Skip to content

Commit

Permalink
net/freeradius: New EAP features (opnsense#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimugmail authored and fichtner committed Oct 19, 2017
1 parent a073300 commit c9eff68
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 7 deletions.
2 changes: 1 addition & 1 deletion net/freeradius/Makefile
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]
Expand Down
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;
}
}
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');
}
}
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>
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
{
}
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>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<General url="/ui/freeradius/general/index" order="10"/>
<User url="/ui/freeradius/user/index" order="20"/>
<Client url="/ui/freeradius/client/index" order="30"/>
<EAP url="/ui/freeradius/eap/index" order="40"/>
</FreeRADIUS>
</Services>
</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{#

OPNsense® is Copyright © 20142017 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 PROVIDEDAS ISAND 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 net/freeradius/src/opnsense/scripts/Freeradius/generate_certs.php
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";
}
}
}
}
}
}
Loading

0 comments on commit c9eff68

Please sign in to comment.