Commit 542c9587 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3815 Conversion of PEM certificate in DER (binary)

parent 95193599
......@@ -20,10 +20,17 @@
class CertificateFileAttribute extends FileAttribute
{
static $pemBegin = "-----BEGIN CERTIFICATE-----";
static $pemEnd = "-----END CERTIFICATE-----";
/* Return the value as an array of values to be displayed in a table columns */
function getArrayValue ()
{
$value = $this->getValue();
if (!strpos($value, self::$pemBegin)) {
/* Convert DER to PEM */
$value = self::$pemBegin."\n".chunk_split(base64_encode($value), 64, "\n").self::$pemEnd."\n";
}
$infos = openssl_x509_parse($value, TRUE);
if (empty($infos)) {
return array(_('Unknown format'), $this->displayValue($this->getValue()), '');
......@@ -47,6 +54,17 @@ class CertificateFileAttribute extends FileAttribute
}
return $values;
}
/*! \brief Convert PEM to DER if needed
*/
function setValue ($value)
{
$pattern = '/'.preg_quote(self::$pemBegin, '/').'(.*)'.preg_quote($pemEnd, '/').'/s';
if (preg_match($pattern, $value, $m)) {
$value = base64_decode($m[1]);
}
parent::setValue($value);
}
}
class userCertificates extends simplePlugin
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment