From c0df27881a7cbf967b49260a6ea249c0e279f9a4 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Thu, 16 Jun 2022 13:06:58 -0400 Subject: [PATCH] Miscellaneous cleanup --- .../X509Certificates/ManagedX509ExtensionProcessor.cs | 2 +- .../Cryptography/X509Certificates/OpenSslPkcs12Reader.cs | 1 + .../X509Certificates/RSAPkcs1X509SignatureGenerator.cs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ManagedX509ExtensionProcessor.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ManagedX509ExtensionProcessor.cs index 1749598a6f547..888638dc24fc4 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ManagedX509ExtensionProcessor.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ManagedX509ExtensionProcessor.cs @@ -31,7 +31,7 @@ public virtual void DecodeX509KeyUsageExtension(byte[] encoded, out X509KeyUsage try { - AsnReader reader = new AsnReader(encoded, AsnEncodingRules.BER); + AsnValueReader reader = new AsnValueReader(encoded, AsnEncodingRules.BER); keyUsagesAsn = reader.ReadNamedBitListValue(); reader.ThrowIfNotEmpty(); } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslPkcs12Reader.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslPkcs12Reader.cs index 79b7aed738772..7ce3eb5f31973 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslPkcs12Reader.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslPkcs12Reader.cs @@ -57,6 +57,7 @@ protected override AsymmetricAlgorithm LoadKey(ReadOnlyMemory pkcs8) if (bytesRead != pkcs8.Length) { + key.Dispose(); throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding); } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/RSAPkcs1X509SignatureGenerator.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/RSAPkcs1X509SignatureGenerator.cs index f49eb588eabec..bcde068cb8cfd 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/RSAPkcs1X509SignatureGenerator.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/RSAPkcs1X509SignatureGenerator.cs @@ -30,6 +30,7 @@ protected override PublicKey BuildPublicKey() internal static PublicKey BuildPublicKey(RSA rsa) { Oid oid = Oids.RsaOid; + ReadOnlySpan asnNull = new byte[] { 0x05, 0x00 }; // The OID is being passed to everything here because that's what // X509Certificate2.PublicKey does. @@ -39,7 +40,7 @@ internal static PublicKey BuildPublicKey(RSA rsa) // // This is due to one version of the ASN.1 not including OPTIONAL, and that was // the version that got predominately implemented for RSA. Now it's convention. - new AsnEncodedData(oid, stackalloc byte[] { 0x05, 0x00 }), + new AsnEncodedData(oid, asnNull), new AsnEncodedData(oid, rsa.ExportRSAPublicKey())); }