Do not throw, optionally, when facing an unknown OID. Fix mozroot facing an sha384ECD...
authorSebastien Pouliot <sebastien@xamarin.com>
Wed, 26 Jun 2013 23:56:14 +0000 (19:56 -0400)
committerSebastien Pouliot <sebastien@xamarin.com>
Wed, 26 Jun 2013 23:56:14 +0000 (19:56 -0400)
mcs/class/Mono.Security/Mono.Security.Cryptography/PKCS1.cs
mcs/class/Mono.Security/Mono.Security.X509/X509Certificate.cs

index aad30c1323bdccc52c96efbe1f54537c9b9175ca..4e579eee94ae2bab77cd3bd121a7fe3928487bc5 100644 (file)
@@ -426,7 +426,7 @@ namespace Mono.Security.Cryptography {
                        return mask;
                }
 
-               static internal string HashNameFromOid (string oid)
+               static internal string HashNameFromOid (string oid, bool throwOnError = true)
                {
                        switch (oid) {
                        case "1.2.840.113549.1.1.2":    // MD2 with RSA encryption 
@@ -448,7 +448,9 @@ namespace Mono.Security.Cryptography {
                        case "1.3.36.3.3.1.2":
                                return "RIPEMD160";
                        default:
-                               throw new CryptographicException ("Unsupported hash algorithm: " + oid);
+                               if (throwOnError)
+                                       throw new CryptographicException ("Unsupported hash algorithm: " + oid);
+                               return null;
                        }
                }
                
index 1bea107fd55548973256a8b8a60168440609e90e..11be419681b1abe55aa502fe916dd7aab511351a 100644 (file)
@@ -289,8 +289,11 @@ namespace Mono.Security.X509 {
                                if (certhash == null) {
                                        if ((decoder == null) || (decoder.Count < 1))
                                                return null;
+                                       string algo = PKCS1.HashNameFromOid (m_signaturealgo, false);
+                                       if (algo == null)
+                                               return null;
                                        byte[] toBeSigned = decoder [0].GetBytes ();
-                                       using (var hash = PKCS1.CreateFromOid (m_signaturealgo))
+                                       using (var hash = PKCS1.CreateFromName (algo))
                                                certhash = hash.ComputeHash (toBeSigned, 0, toBeSigned.Length);
                                }
                                return (byte[]) certhash.Clone ();