allow to upload PEM certificates with junk data before cert data

This commit is contained in:
Roland Gruber 2013-12-26 11:35:49 +00:00
parent cfd8abc3e6
commit a6cc0d8a3e
1 changed files with 6 additions and 1 deletions

View File

@ -1625,10 +1625,15 @@ class LAMCfgMain {
* @return mixed TRUE if format is correct, error message if file is not accepted
*/
public function uploadSSLCaCert($cert) {
if (strpos($cert, '-----BEGIN CERTIFICATE-----') !== 0) {
if (strpos($cert, '-----BEGIN CERTIFICATE-----') === false) {
$pem = @chunk_split(@base64_encode($cert), 64, "\n");
$cert = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n";
}
else {
// remove any junk before first "-----BEGIN CERTIFICATE-----"
$pos = strpos($cert, '-----BEGIN CERTIFICATE-----');
$cert = substr($cert, $pos);
}
$pemData = @openssl_x509_parse($cert);
if ($pemData === false) {
return _('Please provide a file in DER or PEM format.');