forked from opnsense/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/freeradius: New EAP features (opnsense#327)
- Loading branch information
Showing
12 changed files
with
447 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PLUGIN_NAME= freeradius | ||
PLUGIN_VERSION= 1.1.0 | ||
PLUGIN_VERSION= 1.2.0 | ||
PLUGIN_COMMENT= RADIUS Authentication, Authorization and Accounting Server | ||
PLUGIN_DEPENDS= freeradius3 | ||
PLUGIN_MAINTAINER= [email protected] | ||
|
76 changes: 76 additions & 0 deletions
76
net/freeradius/src/opnsense/mvc/app/controllers/OPNsense/Freeradius/Api/EapController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2015 - 2017 Deciso B.V. | ||
* Copyright (C) 2017 Michael Muenz | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
namespace OPNsense\Freeradius\Api; | ||
|
||
use \OPNsense\Base\ApiControllerBase; | ||
use \OPNsense\Freeradius\Eap; | ||
use \OPNsense\Core\Config; | ||
|
||
class EapController extends ApiControllerBase | ||
{ | ||
public function getAction() | ||
{ | ||
// define list of configurable settings | ||
$result = array(); | ||
if ($this->request->isGet()) { | ||
$mdlEAP = new EAP(); | ||
$result['eap'] = $mdlEAP->getNodes(); | ||
} | ||
return $result; | ||
} | ||
|
||
public function setAction() | ||
{ | ||
$result = array("result"=>"failed"); | ||
if ($this->request->isPost()) { | ||
// load model and update with provided data | ||
$mdlEAP = new EAP(); | ||
$mdlEAP->setNodes($this->request->getPost("eap")); | ||
|
||
// perform validation | ||
$valMsgs = $mdlEAP->performValidation(); | ||
foreach ($valMsgs as $field => $msg) { | ||
if (!array_key_exists("validations", $result)) { | ||
$result["validations"] = array(); | ||
} | ||
$result["validations"]["eap.".$msg->getField()] = $msg->getMessage(); | ||
} | ||
|
||
// serialize model to config and save | ||
if ($valMsgs->count() == 0) { | ||
$mdlEAP->serializeToConfig(); | ||
Config::getInstance()->save(); | ||
$result["result"] = "saved"; | ||
} | ||
} | ||
return $result; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
net/freeradius/src/opnsense/mvc/app/controllers/OPNsense/Freeradius/EapController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/* | ||
Copyright (C) 2017 Michael Muenz | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
namespace OPNsense\Freeradius; | ||
|
||
class EapController extends \OPNsense\Base\IndexController | ||
{ | ||
public function indexAction() | ||
{ | ||
$this->view->title = gettext("EAP Settings"); | ||
$this->view->eapForm = $this->getForm("eap"); | ||
$this->view->pick('OPNsense/Freeradius/eap'); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
net/freeradius/src/opnsense/mvc/app/controllers/OPNsense/Freeradius/forms/eap.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<form> | ||
<field> | ||
<id>eap.default_eap_type</id> | ||
<label>Default EAP Type</label> | ||
<type>dropdown</type> | ||
<help>Set the default EAP type.</help> | ||
</field> | ||
<field> | ||
<id>eap.enable_client_cert</id> | ||
<label>Enable Client Certficate Authentication</label> | ||
<type>checkbox</type> | ||
<help>This will activate certificate based authentication. Please choose CA and Certificate below and do not forget to roll out certificates to the clients.</help> | ||
</field> | ||
<field> | ||
<id>eap.ca</id> | ||
<label>Root Certificate</label> | ||
<type>dropdown</type> | ||
<help>Choose the Root CA.</help> | ||
</field> | ||
<field> | ||
<id>eap.certificate</id> | ||
<label>Server Certificate</label> | ||
<type>dropdown</type> | ||
<help>Choose the certificate the Radius service should use.</help> | ||
</field> | ||
<field> | ||
<id>eap.crl</id> | ||
<label>CRL</label> | ||
<type>dropdown</type> | ||
<help>This enables CRL checking, please restart this service with every change to the CRL.</help> | ||
</field> | ||
</form> |
34 changes: 34 additions & 0 deletions
34
net/freeradius/src/opnsense/mvc/app/models/OPNsense/Freeradius/Eap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace OPNsense\Freeradius; | ||
|
||
use OPNsense\Base\BaseModel; | ||
|
||
/* | ||
Copyright (C) 2017 Michael Muenz | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
class Eap extends BaseModel | ||
{ | ||
} |
37 changes: 37 additions & 0 deletions
37
net/freeradius/src/opnsense/mvc/app/models/OPNsense/Freeradius/Eap.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<model> | ||
<mount>//OPNsense/freeradius/eap</mount> | ||
<description>EAP configuration</description> | ||
<version>1.0.0</version> | ||
<items> | ||
<default_eap_type type="OptionField"> | ||
<default>MD5</default> | ||
<Required>Y</Required> | ||
<multiple>N</multiple> | ||
<OptionValues> | ||
<md5>MD5</md5> | ||
<mschapv2>MSCHAPv2</mschapv2> | ||
<peap>PEAP</peap> | ||
<ttls>TTLS</ttls> | ||
</OptionValues> | ||
</default_eap_type> | ||
<enable_client_cert type="BooleanField"> | ||
<default>0</default> | ||
<Required>Y</Required> | ||
</enable_client_cert> | ||
<ca type="CertificateField"> | ||
<default></default> | ||
<Type>ca</Type> | ||
<Required>N</Required> | ||
</ca> | ||
<certificate type="CertificateField"> | ||
<default></default> | ||
<Type>cert</Type> | ||
<Required>N</Required> | ||
</certificate> | ||
<crl type="CertificateField"> | ||
<default></default> | ||
<Type>crl</Type> | ||
<Required>N</Required> | ||
</crl> | ||
</items> | ||
</model> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
net/freeradius/src/opnsense/mvc/app/views/OPNsense/Freeradius/eap.volt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{# | ||
|
||
OPNsense® is Copyright © 2014 – 2017 by Deciso B.V. | ||
This file is Copyright © 2017 by Michael Muenz | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. | ||
|
||
#} | ||
|
||
<div class="content-box" style="padding-bottom: 1.5em;"> | ||
{{ partial("layout_partials/base_form",['fields':eapForm,'id':'frm_eap_settings'])}} | ||
<hr /> | ||
<div class="col-md-12"> | ||
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress" class=""></i></button> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
$( document ).ready(function () { | ||
var data_get_map = {'frm_eap_settings':"/api/freeradius/eap/get"}; | ||
mapDataToFormUI(data_get_map).done(function (data) { | ||
formatTokenizersUI(); | ||
$('.selectpicker').selectpicker('refresh'); | ||
}); | ||
ajaxCall(url="/api/freeradius/service/status", sendData={}, callback=function (data, status) { | ||
updateServiceStatusUI(data['status']); | ||
}); | ||
|
||
// link save button to API set action | ||
$("#saveAct").click(function () { | ||
saveFormToEndpoint(url="/api/freeradius/eap/set", formid='frm_eap_settings',callback_ok=function () { | ||
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse"); | ||
ajaxCall(url="/api/freeradius/service/reconfigure", sendData={}, callback=function (data,status) { | ||
ajaxCall(url="/api/freeradius/service/status", sendData={}, callback=function (data,status) { | ||
updateServiceStatusUI(data['status']); | ||
}); | ||
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
</script> |
78 changes: 78 additions & 0 deletions
78
net/freeradius/src/opnsense/scripts/Freeradius/generate_certs.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/local/bin/php | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2015 Deciso B.V. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
// use legacy code to generate certs and ca's | ||
// eventually we need to replace this. | ||
require_once("config.inc"); | ||
require_once("certs.inc"); | ||
require_once("legacy_bindings.inc"); | ||
|
||
use OPNsense\Core\Config; | ||
|
||
// traverse Freeradius plugin for certficiates | ||
$configObj = Config::getInstance()->object(); | ||
if (isset($configObj->OPNsense->freeradius)) { | ||
foreach ($configObj->OPNsense->freeradius->children() as $find_cert) { | ||
$cert_refid = (string)$find_cert->certificate; | ||
// if eap has a certificate attached, search for its contents | ||
if ($cert_refid != "") { | ||
foreach ($configObj->cert as $cert) { | ||
if ($cert_refid == (string)$cert->refid) { | ||
// generate cert pem file | ||
$pem_content = trim(str_replace("\n\n", "\n", str_replace( | ||
"\r", | ||
"", | ||
base64_decode((string)$cert->crt) | ||
))); | ||
|
||
$pem_content .= "\n"; | ||
$pem_content .= trim(str_replace( | ||
"\n\n", | ||
"\n", | ||
str_replace("\r", "", base64_decode((string)$cert->prv)) | ||
)); | ||
$pem_content .= "\n"; | ||
$output_pem_filename = "/usr/local/etc/raddb/certs/cert_" . $cert_refid . ".pem"; | ||
file_put_contents($output_pem_filename, $pem_content); | ||
chmod($output_pem_filename, 0600); | ||
echo "certificate generated " .$output_pem_filename . "\n"; | ||
// generate ca pem file | ||
if (!empty($cert->caref)) { | ||
$output_pem_filename = "/usr/local/etc/raddb/certs/ca_" . $cert_refid . ".pem"; | ||
$cert = (array)$cert; | ||
$ca = ca_chain($cert); | ||
file_put_contents($output_pem_filename, $ca); | ||
chmod($output_pem_filename, 0600); | ||
echo "certificate generated " .$output_pem_filename ."\n"; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.