From: js6pak Date: Wed, 31 Mar 2021 11:37:54 +0000 (+0200) Subject: Fix tests on linux X-Git-Tag: 1.0.0~7 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=dd0f98643b2b969cae0d29f44531a541308c36e7;p=rhonda%2Fimpostor.hazel.git Fix tests on linux --- diff --git a/Hazel.UnitTests/Dtls/ConnectionTests.cs b/Hazel.UnitTests/Dtls/ConnectionTests.cs index 0b9073e..bc8207f 100644 --- a/Hazel.UnitTests/Dtls/ConnectionTests.cs +++ b/Hazel.UnitTests/Dtls/ConnectionTests.cs @@ -72,16 +72,13 @@ IsdbLCwHYD3GVgk/D7NVxyU= private static X509Certificate2 GetCertificateForServer() { RSA privateKey = Utils.DecodeRSAKeyFromPEM(TestPrivateKey); - X509Certificate2 privateCertificate = new X509Certificate2(); - privateCertificate.Import(Utils.DecodePEM(TestCertificate)); - privateCertificate.PrivateKey = privateKey; + X509Certificate2 privateCertificate = new X509Certificate2(Utils.DecodePEM(TestCertificate)).CopyWithPrivateKey(privateKey); return privateCertificate; } private static X509Certificate2Collection GetCertificateForClient() { - X509Certificate2 publicCertificate = new X509Certificate2(); - publicCertificate.Import(Utils.DecodePEM(TestCertificate)); + X509Certificate2 publicCertificate = new X509Certificate2(Utils.DecodePEM(TestCertificate)); X509Certificate2Collection clientCertificates = new X509Certificate2Collection(); clientCertificates.Add(publicCertificate); diff --git a/Hazel.UnitTests/Utils.cs b/Hazel.UnitTests/Utils.cs index 988cb58..ad60abc 100644 --- a/Hazel.UnitTests/Utils.cs +++ b/Hazel.UnitTests/Utils.cs @@ -87,11 +87,18 @@ namespace Hazel.UnitTests return result.ToArray(); } + private static RSA CreateRSAProvider(RSAParameters rp) + { + RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider(); + rsaCsp.ImportParameters(rp); + return rsaCsp; + } + public static RSA DecodeRSAKeyFromPEM(string pemData) { PemReader pemReader = new PemReader(new StringReader(pemData)); RsaPrivateCrtKeyParameters keyParameters = (RsaPrivateCrtKeyParameters)pemReader.ReadObject(); - return DotNetUtilities.ToRSA(keyParameters); + return CreateRSAProvider(DotNetUtilities.ToRSAParameters(keyParameters)); } } }