Skip to content

Commit aeda1de

Browse files
authored
Use SHA512 to generate cert thumbprint (#112193)
1 parent 73efdf3 commit aeda1de

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal static SafeSslContextHandle GetOrCreateSslContextHandle(SslAuthenticati
163163

164164
if (sslAuthenticationOptions.IsClient)
165165
{
166-
var key = new SslContextCacheKey(protocols, sslAuthenticationOptions.CertificateContext?.TargetCertificate.GetCertHash(HashAlgorithmName.SHA256));
166+
var key = new SslContextCacheKey(protocols, sslAuthenticationOptions.CertificateContext?.TargetCertificate.GetCertHash(HashAlgorithmName.SHA512));
167167
return s_clientSslContexts.GetOrCreate(key, static (args) =>
168168
{
169169
var (sslAuthOptions, protocols, allowCached) = args;

src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Collections.Concurrent;
77
using System.Collections.ObjectModel;
8+
using System.Security.Cryptography;
89
using System.Security.Authentication;
910
using System.Net.Security;
1011
using System.Security.Cryptography.X509Certificates;
@@ -53,13 +54,13 @@ private sealed class MsQuicConfigurationCache : SafeHandleCache<CacheKey, MsQuic
5354

5455
public CacheKey(QUIC_SETTINGS settings, QUIC_CREDENTIAL_FLAGS flags, X509Certificate? certificate, ReadOnlyCollection<X509Certificate2>? intermediates, List<SslApplicationProtocol> alpnProtocols, QUIC_ALLOWED_CIPHER_SUITE_FLAGS allowedCipherSuites)
5556
{
56-
CertificateThumbprints = certificate == null ? new List<byte[]>() : new List<byte[]> { certificate.GetCertHash() };
57+
CertificateThumbprints = certificate == null ? new List<byte[]>() : new List<byte[]> { certificate.GetCertHash(HashAlgorithmName.SHA512) };
5758

5859
if (intermediates != null)
5960
{
6061
foreach (X509Certificate2 intermediate in intermediates)
6162
{
62-
CertificateThumbprints.Add(intermediate.GetCertHash());
63+
CertificateThumbprints.Add(intermediate.GetCertHash(HashAlgorithmName.SHA512));
6364
}
6465
}
6566

src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ private bool AcquireClientCredentials(ref byte[]? thumbPrint, bool newCredential
597597
//
598598
// SECURITY: selectedCert ref if not null is a safe object that does not depend on possible **user** inherited X509Certificate type.
599599
//
600-
byte[]? guessedThumbPrint = selectedCert?.GetCertHash();
600+
byte[]? guessedThumbPrint = selectedCert?.GetCertHash(HashAlgorithmName.SHA512);
601601
SafeFreeCredentials? cachedCredentialHandle = SslSessionsCache.TryCachedCredential(
602602
guessedThumbPrint,
603603
_sslAuthenticationOptions.EnabledSslProtocols,
@@ -743,7 +743,7 @@ private bool AcquireServerCredentials(ref byte[]? thumbPrint)
743743
//
744744
// Note selectedCert is a safe ref possibly cloned from the user passed Cert object
745745
//
746-
byte[] guessedThumbPrint = selectedCert.GetCertHash();
746+
byte[] guessedThumbPrint = selectedCert.GetCertHash(HashAlgorithmName.SHA512);
747747
bool sendTrustedList = _sslAuthenticationOptions.CertificateContext!.Trust?._sendTrustInHandshake ?? false;
748748
SafeFreeCredentials? cachedCredentialHandle = SslSessionsCache.TryCachedCredential(guessedThumbPrint,
749749
_sslAuthenticationOptions.EnabledSslProtocols,

0 commit comments

Comments
 (0)