Skip to content

Commit b58af51

Browse files
committed
Optimise thumbprint creation under .NET 7.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent b4d8baf commit b58af51

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private bool ValidateFingerprint(byte[]? validationHash, ReadOnlySpan<byte> chal
639639
Span<byte> combined = stackalloc byte[32 + challenge.Length + passwordHashResult.Length];
640640
passwordHashResult.CopyTo(combined);
641641
challenge.CopyTo(combined[passwordHashResult.Length..]);
642-
m_sha2Thumbprint!.CopyTo(combined[(passwordHashResult.Length + challenge.Length)..]);
642+
m_remoteCertificateSha2Thumbprint!.CopyTo(combined[(passwordHashResult.Length + challenge.Length)..]);
643643

644644
Span<byte> hashBytes = stackalloc byte[32];
645645
#if NET5_0_OR_GREATER
@@ -1593,13 +1593,13 @@ caCertificateChain is not null &&
15931593
if (rcbCertificate is X509Certificate2 cert2)
15941594
{
15951595
// saving sha256 thumbprint and SSL errors until thumbprint validation
1596-
#if !NET5_0_OR_GREATER
1597-
using (var sha256 = SHA256.Create())
1598-
{
1599-
m_sha2Thumbprint = sha256.ComputeHash(cert2.RawData);
1600-
}
1596+
#if NET7_0_OR_GREATER
1597+
m_remoteCertificateSha2Thumbprint = SHA256.HashData(cert2.RawDataMemory.Span);
1598+
#elif NET5_0_OR_GREATER
1599+
m_remoteCertificateSha2Thumbprint = SHA256.HashData(cert2.RawData);
16011600
#else
1602-
m_sha2Thumbprint = SHA256.HashData(cert2.RawData);
1601+
using var sha256 = SHA256.Create();
1602+
m_remoteCertificateSha2Thumbprint = sha256.ComputeHash(cert2.RawData);
16031603
#endif
16041604
m_rcbPolicyErrors = rcbPolicyErrors;
16051605
return true;
@@ -2127,6 +2127,6 @@ protected override void OnStatementBegin(int index)
21272127
private byte[]? m_pipelinedResetConnectionBytes;
21282128
private Dictionary<string, PreparedStatements>? m_preparedStatements;
21292129
private string m_pluginName = "mysql_native_password";
2130-
private byte[]? m_sha2Thumbprint;
2130+
private byte[]? m_remoteCertificateSha2Thumbprint;
21312131
private SslPolicyErrors m_rcbPolicyErrors;
21322132
}

0 commit comments

Comments
 (0)