From 0afd4478716469eb5bd9138de6089f28ef775f63 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 6 Oct 2009 22:17:40 -0600 Subject: [PATCH] Better error handling for S/MIME certs --- framework/Crypt/lib/Horde/Crypt/Smime.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/framework/Crypt/lib/Horde/Crypt/Smime.php b/framework/Crypt/lib/Horde/Crypt/Smime.php index 911351dcb..6f1097a22 100644 --- a/framework/Crypt/lib/Horde/Crypt/Smime.php +++ b/framework/Crypt/lib/Horde/Crypt/Smime.php @@ -646,20 +646,18 @@ class Horde_Crypt_Smime extends Horde_Crypt * * @param string $cert PEM format certificate * - * @return array Array containing all extractable information about - * the certificate. + * @return mixed Array containing all extractable information about + * the certificate. Returns false on error. */ public function parseCert($cert) { $cert_split = preg_split('/(-----((BEGIN)|(END)) CERTIFICATE-----)/', $cert); - if (!isset($cert_split[1])) { - $raw_cert = base64_decode($cert); - } else { - $raw_cert = base64_decode($cert_split[1]); - } + $raw_cert = base64_decode(isset($cert_split[1]) ? $cert_split[1] : $cert); $cert_data = $this->_parseASN($raw_cert); - if (!is_array($cert_data) || ($cert_data[0] == 'UNKNOWN')) { + if (!is_array($cert_data) || + ($cert_data[0] == 'UNKNOWN') || + ($cert_data[1][0] == 'UNKNOWN')) { return false; } -- 2.11.0