From 35e74da797ffa462b555c861f35121c1c9d8470c Mon Sep 17 00:00:00 2001 From: Luke Butters Date: Fri, 25 Aug 2023 15:54:45 +1000 Subject: [PATCH] Less cert work --- .../Support/TestCases/ClientAndServiceTestCasesBuilder.cs | 2 ++ .../Support/TestCases/NetworkConditionTestCase.cs | 4 ++-- source/Halibut/Transport/ClientCertificateValidator.cs | 3 ++- source/Halibut/Transport/SecureListener.cs | 6 ++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/source/Halibut.Tests/Support/TestCases/ClientAndServiceTestCasesBuilder.cs b/source/Halibut.Tests/Support/TestCases/ClientAndServiceTestCasesBuilder.cs index 5fa4ed5b..40bed474 100644 --- a/source/Halibut.Tests/Support/TestCases/ClientAndServiceTestCasesBuilder.cs +++ b/source/Halibut.Tests/Support/TestCases/ClientAndServiceTestCasesBuilder.cs @@ -38,10 +38,12 @@ List BuildDistinct() foreach (var clientServiceTestVersion in clientServiceTestVersions) { + if(!clientServiceTestVersion.IsLatest()) continue; foreach (var serviceConnectionType in serviceConnectionTypes) { foreach (var networkConditionTestCase in networkConditionTestCases) { + // Slightly bad network conditions e.g. a delay of 20ms can blow out test times especially when running for 2000 iterations. // 15 iterations seems ok. var recommendedIterations = 15; diff --git a/source/Halibut.Tests/Support/TestCases/NetworkConditionTestCase.cs b/source/Halibut.Tests/Support/TestCases/NetworkConditionTestCase.cs index f80e2b84..53e8de62 100644 --- a/source/Halibut.Tests/Support/TestCases/NetworkConditionTestCase.cs +++ b/source/Halibut.Tests/Support/TestCases/NetworkConditionTestCase.cs @@ -9,8 +9,8 @@ public class NetworkConditionTestCase public static NetworkConditionTestCase[] All => new[] { NetworkConditionTestCase.NetworkConditionPerfect, - NetworkConditionTestCase.NetworkCondition20MsLatency, - NetworkConditionTestCase.NetworkCondition20MsLatencyWithLastByteArrivingLate, + //NetworkConditionTestCase.NetworkCondition20MsLatency, + //NetworkConditionTestCase.NetworkCondition20MsLatencyWithLastByteArrivingLate, //NetworkConditionTestCase.NetworkCondition20MsLatencyWithLast2BytesArrivingLate, //NetworkConditionTestCase.NetworkCondition20MsLatencyWithLast3BytesArrivingLate }; diff --git a/source/Halibut/Transport/ClientCertificateValidator.cs b/source/Halibut/Transport/ClientCertificateValidator.cs index 74dda559..e18b8dac 100644 --- a/source/Halibut/Transport/ClientCertificateValidator.cs +++ b/source/Halibut/Transport/ClientCertificateValidator.cs @@ -15,7 +15,8 @@ public ClientCertificateValidator(ServiceEndPoint endPoint) public bool Validate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors) { - var providedCert = new X509Certificate2(certificate.Export(X509ContentType.Cert), (string)null!); // Copy the cert so that we can reference it later + + var providedCert = certificate as X509Certificate2 ?? new X509Certificate2(certificate.Export(X509ContentType.Cert), (string)null!); // Copy the cert so that we can reference it later var providedThumbprint = providedCert.Thumbprint; if (providedThumbprint == endPoint.RemoteThumbprint) diff --git a/source/Halibut/Transport/SecureListener.cs b/source/Halibut/Transport/SecureListener.cs index e71892d1..dba7144b 100644 --- a/source/Halibut/Transport/SecureListener.cs +++ b/source/Halibut/Transport/SecureListener.cs @@ -388,6 +388,12 @@ static string GetThumbprint(SslStream stream) return null; } + var cert = stream.RemoteCertificate; + if(cert is X509Certificate2 x509Certificate2) + { + return x509Certificate2.Thumbprint; + } + var thumbprint = new X509Certificate2(stream.RemoteCertificate.Export(X509ContentType.Cert), (string)null!).Thumbprint; return thumbprint; }