From 81240c6b92c1d9a865b74b51e38cd613bfdcac29 Mon Sep 17 00:00:00 2001 From: Roman Ettlinger Date: Mon, 3 Feb 2025 06:21:26 +0100 Subject: [PATCH] fix tests on net 462 --- Tests/Opc.Ua.Gds.Tests/PushTest.cs | 43 +++++++++++-------- .../CRLTests.cs | 17 +++++--- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Tests/Opc.Ua.Gds.Tests/PushTest.cs b/Tests/Opc.Ua.Gds.Tests/PushTest.cs index 779955ae1..83d598dcf 100644 --- a/Tests/Opc.Ua.Gds.Tests/PushTest.cs +++ b/Tests/Opc.Ua.Gds.Tests/PushTest.cs @@ -511,27 +511,31 @@ public void UpdateCertificateSelfSigned(string keyFormat) X509Certificate2 newCert; +#if ECC_SUPPORT ECCurve? curve = EccUtils.GetCurveFromCertificateTypeId(m_certificateType); - // RSA Certificate - if (curve == null) + if (curve != null) { newCert = CertificateFactory.CreateCertificate( - m_applicationRecord.ApplicationUri, - m_applicationRecord.ApplicationNames[0].Text, - m_selfSignedServerCert.Subject + "1", - null).CreateForRSA(); + m_applicationRecord.ApplicationUri, + m_applicationRecord.ApplicationNames[0].Text, + m_selfSignedServerCert.Subject + "1", + null) + .SetECCurve(curve.Value) + .CreateForECDsa(); } + // RSA Certificate else { +#endif newCert = CertificateFactory.CreateCertificate( m_applicationRecord.ApplicationUri, m_applicationRecord.ApplicationNames[0].Text, m_selfSignedServerCert.Subject + "1", - null) - .SetECCurve(curve.Value) - .CreateForECDsa(); + null).CreateForRSA(); +#if ECC_SUPPORT } +#endif byte[] privateKey = null; @@ -935,27 +939,30 @@ private async Task CreateCATestCerts(string tempStorePath) var certificateStoreIdentifier = new CertificateStoreIdentifier(tempStorePath, false); Assert.IsTrue(EraseStore(certificateStoreIdentifier)); string subjectName = "CN=CA Test Cert, O=OPC Foundation"; - +#if ECC_SUPPORT ECCurve? curve = EccUtils.GetCurveFromCertificateTypeId(m_certificateType); - // RSA Certificate - if (curve == null) + if (curve != null) { m_caCert = await CertificateFactory.CreateCertificate( - null, null, subjectName, null) - .SetCAConstraint() - .CreateForRSA() - .AddToStoreAsync(certificateStoreIdentifier).ConfigureAwait(false); + null, null, subjectName, null) + .SetCAConstraint() + .SetECCurve(curve.Value) + .CreateForECDsa() + .AddToStoreAsync(certificateStoreIdentifier).ConfigureAwait(false); } + // RSA Certificate else { +#endif m_caCert = await CertificateFactory.CreateCertificate( null, null, subjectName, null) .SetCAConstraint() - .SetECCurve(curve.Value) - .CreateForECDsa() + .CreateForRSA() .AddToStoreAsync(certificateStoreIdentifier).ConfigureAwait(false); +#if ECC_SUPPORT } +#endif // initialize cert revocation list (CRL) X509CRL newCACrl = await CertificateGroup.RevokeCertificateAsync(certificateStoreIdentifier, m_caCert).ConfigureAwait(false); diff --git a/Tests/Opc.Ua.Security.Certificates.Tests/CRLTests.cs b/Tests/Opc.Ua.Security.Certificates.Tests/CRLTests.cs index 97128aaca..11502f213 100644 --- a/Tests/Opc.Ua.Security.Certificates.Tests/CRLTests.cs +++ b/Tests/Opc.Ua.Security.Certificates.Tests/CRLTests.cs @@ -87,22 +87,27 @@ public CRLTests(string certificateTypeString, NodeId certificateType) [OneTimeSetUp] protected void OneTimeSetUp() { +#if ECC_SUPPORT ECCurve? curve = EccUtils.GetCurveFromCertificateTypeId(m_certificateType); - // RSA Certificate - if (curve == null) + if (curve != null) { m_issuerCert = CertificateBuilder.Create("CN=Root CA, O=OPC Foundation") .SetCAConstraint() - .CreateForRSA(); + .SetECCurve(curve.Value) + .CreateForECDsa(); + } + // RSA Certificate else { +#endif m_issuerCert = CertificateBuilder.Create("CN=Root CA, O=OPC Foundation") - .SetCAConstraint() - .SetECCurve(curve.Value) - .CreateForECDsa(); + .SetCAConstraint() + .CreateForRSA(); +#if ECC_SUPPORT } +#endif } ///