Use OID constructor for certificate SignatureAlgorithm.
authorKevin Jones <kevin@vcsjones.com>
Tue, 17 Aug 2021 15:58:13 +0000 (11:58 -0400)
committerGitHub <noreply@github.com>
Tue, 17 Aug 2021 15:58:13 +0000 (08:58 -0700)
This fixes an issue where it was not possible to get the SignatureAlgorithm
on Windows if the signature algorithm does not have a FriendlyName, like
a GOST certificate. This changes the SignatureAlgorithm property to use the
OID constructor so that the value can always be accessed, and the FriendlyName
is lazily resolve when the property is accessed.

src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/CertTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/TestData.cs

index 967d291..11ba08e 100644 (file)
@@ -345,7 +345,7 @@ namespace System.Security.Cryptography.X509Certificates
                 if (signatureAlgorithm == null)
                 {
                     string oidValue = Pal.SignatureAlgorithm;
-                    signatureAlgorithm = _lazySignatureAlgorithm = Oid.FromOidValue(oidValue, OidGroup.SignatureAlgorithm);
+                    signatureAlgorithm = _lazySignatureAlgorithm = new Oid(oidValue, null);
                 }
                 return signatureAlgorithm;
             }
index 98cd5c4..41b8084 100644 (file)
@@ -121,6 +121,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
 
                 Assert.Equal("00D01E4090000046520000000100000004", cert2.SerialNumber);
                 Assert.Equal("1.2.840.113549.1.1.5", cert2.SignatureAlgorithm.Value);
+                Assert.NotEmpty(cert2.SignatureAlgorithm.FriendlyName);
                 Assert.Equal("7A74410FB0CD5C972A364B71BF031D88A6510E9E", cert2.Thumbprint);
                 Assert.Equal(3, cert2.Version);
             }
@@ -495,6 +496,15 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             }
         }
 
+        [Fact]
+        public static void SignatureAlgorithmOidReadableForGostCertificate()
+        {
+            using (X509Certificate2 cert = new X509Certificate2(TestData.GostCertificate))
+            {
+                Assert.Equal("1.2.643.2.2.3", cert.SignatureAlgorithm.Value);
+            }
+        }
+
         public static IEnumerable<object[]> StorageFlags => CollectionImportTests.StorageFlags;
     }
 }
index a36a401..a738e45 100644 (file)
@@ -2418,6 +2418,51 @@ suIwDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQDAgMwADAtAhUAxMT7z8lLv7hgWmGh
             "E74F327E578FEBCC16B9958803D09A7C85AE0FE48DEAA6BB7E56C7CBB0DF0F66" +
             "BCCAEA1A60").HexToByteArray();
 
+        internal static byte[] GostCertificate = (
+            "308204f5308204a4a00302010202103b0f900958220fa74f1fd37f3ddcd2" +
+            "65300806062a85030202033081f73118301606052a85036401120d313034" +
+            "37373037303330353133311a301806082a85030381030101120c30303737" +
+            "3037333239313532312f302d06035504091e260443043b002e0020041d04" +
+            "350433043b0438043d043d0430044f00200434002e002000320033311b30" +
+            "1906035504081e120433002e0020041c043e0441043a043204303120301e" +
+            "06092a864886f70d01090116116d6e733132373035406e616c6f672e7275" +
+            "310b3009060355040613025255310f300d060355040713064d6f73636f77" +
+            "311c301a060355040a13134665646572616c205461782053657276696365" +
+            "311330110603550403130a464e5320527573736961301e170d3132313030" +
+            "323130323032315a170d3432313030333130323032315a3081f731183016" +
+            "06052a85036401120d31303437373037303330353133311a301806082a85" +
+            "030381030101120c303037373037333239313532312f302d06035504091e" +
+            "260443043b002e0020041d04350433043b0438043d043d0430044f002004" +
+            "34002e002000320033311b301906035504081e120433002e0020041c043e" +
+            "0441043a043204303120301e06092a864886f70d01090116116d6e733132" +
+            "373035406e616c6f672e7275310b3009060355040613025255310f300d06" +
+            "0355040713064d6f73636f77311c301a060355040a13134665646572616c" +
+            "205461782053657276696365311330110603550403130a464e5320527573" +
+            "7369613063301c06062a8503020213301206072a85030202230106072a85" +
+            "0302021e010343000440286aa49187f798c61d83382a0deae4dc3c644e88" +
+            "e8bf04098644d2710c263ef310c3de5492fc5fa54264b0a76b0f9060b65a" +
+            "df9125e101b0154ea0f4bed550dea382020630820202303606052a850364" +
+            "6f042d0c2b22d09ad180d0b8d0bfd182d0bed09fd180d0be204353502220" +
+            "28d0b2d0b5d180d181d0b8d18f20332e36293082013106052a8503647004" +
+            "820126308201220c2b22d09ad180d0b8d0bfd182d0bed09fd180d0be2043" +
+            "5350222028d0b2d0b5d180d181d0b8d18f20332e36290c5322d0a3d0b4d0" +
+            "bed181d182d0bed0b2d0b5d180d18fd18ed189d0b8d0b920d186d0b5d0bd" +
+            "d182d1802022d09ad180d0b8d0bfd182d0bed09fd180d0be20d0a3d0a622" +
+            "20d0b2d0b5d180d181d0b8d0b820312e350c4e43d0b5d180d182d0b8d184" +
+            "d0b8d0bad0b0d18220d181d0bed0bed182d0b2d0b5d182d181d182d0b2d0" +
+            "b8d18f20e2849620d0a1d0a42f3132312d3138353920d0bed1822031372e" +
+            "30362e323031320c4e43d0b5d180d182d0b8d184d0b8d0bad0b0d18220d1" +
+            "81d0bed0bed182d0b2d0b5d182d181d182d0b2d0b8d18f20e2849620d0a1" +
+            "d0a42f3132382d3138323220d0bed1822030312e30362e32303132300b06" +
+            "03551d0f040403020186300f0603551d130101ff040530030101ff301d06" +
+            "03551d0e04160414e0aca23183615a27ac05b888102fd46009b6fae43012" +
+            "06092b060104018237150104050203020002302306092b06010401823715" +
+            "020416041488a9bed7a922afee5c420aff55b347b034370d8d301d060355" +
+            "1d2004163014300806062a8503647101300806062a850364710230080606" +
+            "2a85030202030341003c272993f0a9a4108d721f0280e7d48bfca7ebd16e" +
+            "028bedeefab9a2be80466fe278fdc50db1b9530e1796b23271b4df2cddd9" +
+            "4769c8a21a8f66c6d4bc181713").HexToByteArray();
+
         internal static byte[] ConcatenatedPemFile = ByteUtils.AsciiBytes(
             @"-----BEGIN CERTIFICATE-----
 MIIFcDCCBFigAwIBAgIQB6krbZc11OZ5l2/FnU3CpTANBgkqhkiG9w0BAQsFADBG