Merge pull request #1514 from directhex/master
authorJoão Matos <joao@tritao.eu>
Sun, 1 Mar 2015 20:36:42 +0000 (20:36 +0000)
committerJoão Matos <joao@tritao.eu>
Sun, 1 Mar 2015 20:36:42 +0000 (20:36 +0000)
Workaround for X509Certificate.RSA throwing an unhandled exception

mcs/class/Mono.Security/Mono.Security.X509/X509Certificate.cs

index 11be419681b1abe55aa502fe916dd7aab511351a..2851c1716cc8521babeecc1daec6f9ff7aad5b5b 100644 (file)
@@ -68,6 +68,10 @@ namespace Mono.Security.X509 {
                private byte[] certhash;
                private RSA _rsa;
                private DSA _dsa;
+
+               // from http://msdn.microsoft.com/en-gb/library/ff635835.aspx
+               private const string OID_DSA = "1.2.840.10040.4.1";
+               private const string OID_RSA = "1.2.840.113549.1.1.1";
                
                // from http://www.ietf.org/rfc/rfc2459.txt
                //
@@ -247,7 +251,7 @@ namespace Mono.Security.X509 {
                                if (m_keyalgoparams == null)
                                        throw new CryptographicException ("Missing key algorithm parameters.");
 
-                               if (_dsa == null) {
+                               if (_dsa == null && m_keyalgo == OID_DSA) {
                                        DSAParameters dsaParams = new DSAParameters ();
                                        // for DSA m_publickey contains 1 ASN.1 integer - Y
                                        ASN1 pubkey = new ASN1 (m_publickey);
@@ -327,7 +331,7 @@ namespace Mono.Security.X509 {
 
                public virtual RSA RSA {
                        get {
-                               if (_rsa == null) {
+                               if (_rsa == null && m_keyalgo == OID_RSA) {
                                        RSAParameters rsaParams = new RSAParameters ();
                                        // for RSA m_publickey contains 2 ASN.1 integers
                                        // the modulus and the public exponent
@@ -560,4 +564,4 @@ namespace Mono.Security.X509 {
                        return Convert.FromBase64String (base64);
                }
        }
-}
\ No newline at end of file
+}