Better error handling for S/MIME certs
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Oct 2009 04:17:40 +0000 (22:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Oct 2009 04:17:40 +0000 (22:17 -0600)
framework/Crypt/lib/Horde/Crypt/Smime.php

index 911351d..6f1097a 100644 (file)
@@ -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;
         }