OpenVPN export, add export_pkcs12() to BaseExporter for easy pkcs12 generation. for https://github.com/opnsense/core/issues/2787

Example usage (from inherited object):

$p12 = $this->export_pkcs12($this->config['client_crt'], $this->config['client_prv'], $this->config['p12_password']);
This commit is contained in:
Ad Schellevis 2018-11-19 21:45:59 +01:00
parent 04df3de895
commit d001f34479

View File

@ -44,4 +44,19 @@ abstract class BaseExporter
{
$this->config = $conf;
}
/**
* @param string $crt X.509 certificate
* @param string $prv PEM formatted private key
* @param string $pass password
* @return string pkcs12
*/
protected function export_pkcs12($crt, $prv, $pass="")
{
$p12 = null;
$crt = openssl_x509_read($crt);
$prv = openssl_get_privatekey($prv);
openssl_pkcs12_export($crt, $p12, $prv, $pass);
return $p12;
}
}