From 9029e1c78aa62a918ce1db1aea54a2cfe3c15293 Mon Sep 17 00:00:00 2001 From: Peter <34331512+pmaytak@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:33:51 -0700 Subject: [PATCH] Fixes for CodeQL + spelling fixes. (#4361) --- .../Core/Helpers/ECDCertificatePopCryptoProvider.cs | 11 ++++------- .../Core/Helpers/RSACertificatePopCryptoProvider.cs | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs b/tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs index 65492fe616..1d5b34e8a9 100644 --- a/tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs +++ b/tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs @@ -28,19 +28,18 @@ public ECDCertificatePopCryptoProvider() private void InitializeSigningKey() { - ECCurve eCCurve = ECCurve.CreateFromFriendlyName(ECCurve.NamedCurves.nistP256.Oid.FriendlyName); - _signingKey = ECDsa.Create(eCCurve); + _signingKey = ECDsa.Create(ECCurve.NamedCurves.nistP256); ECParameters publicKeyInfo = _signingKey.ExportParameters(false); - CannonicalPublicKeyJwk = ComputeCannonicalJwk(publicKeyInfo); + CannonicalPublicKeyJwk = ComputeCanonicalJwk(publicKeyInfo); } /// - /// Creates the cannonical representation of the JWK. See https://tools.ietf.org/html/rfc7638#section-3 + /// Creates the canonical representation of the JWK. See https://tools.ietf.org/html/rfc7638#section-3 /// The number of parameters as well as the lexicographic order is important, as this string will be hashed to get a thumbprint /// - private static string ComputeCannonicalJwk(ECParameters ecdPublicKey) + private static string ComputeCanonicalJwk(ECParameters ecdPublicKey) { string x = ecdPublicKey.Q.X != null ? Base64UrlHelpers.Encode(ecdPublicKey.Q.X) : null; string y = ecdPublicKey.Q.Y != null ? Base64UrlHelpers.Encode(ecdPublicKey.Q.Y) : null; @@ -70,12 +69,10 @@ private static string GetCrvParameterValue(ECCurve curve) /// private static class JsonWebKeyECTypes { -#pragma warning disable 1591 public const string P256 = "P-256"; public const string P384 = "P-384"; public const string P512 = "P-512"; public const string P521 = "P-521"; -#pragma warning restore 1591 } } } diff --git a/tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs b/tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs index 4a3654b2c2..92f8703a76 100644 --- a/tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs +++ b/tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs @@ -2,10 +2,8 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; -using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography; -using System.Text; +using System.Security.Cryptography.X509Certificates; using Microsoft.Identity.Client.AuthScheme.PoP; using Microsoft.Identity.Client.Utils; @@ -21,7 +19,7 @@ public RSACertificatePopCryptoProvider(X509Certificate2 cert) RSA provider = _cert.GetRSAPublicKey(); RSAParameters publicKeyParams = provider.ExportParameters(false); - CannonicalPublicKeyJwk = ComputeCannonicalJwk(publicKeyParams); + CannonicalPublicKeyJwk = ComputeCanonicalJwk(publicKeyParams); } public byte[] Sign(byte[] payload) @@ -31,7 +29,7 @@ public byte[] Sign(byte[] payload) return key.SignData( payload, HashAlgorithmName.SHA256, - RSASignaturePadding.Pkcs1); + RSASignaturePadding.Pss); } } @@ -43,7 +41,7 @@ public byte[] Sign(byte[] payload) /// Creates the canonical representation of the JWK. See https://tools.ietf.org/html/rfc7638#section-3 /// The number of parameters as well as the lexicographic order is important, as this string will be hashed to get a thumbprint /// - private static string ComputeCannonicalJwk(RSAParameters rsaPublicKey) + private static string ComputeCanonicalJwk(RSAParameters rsaPublicKey) { return $@"{{""e"":""{Base64UrlHelpers.Encode(rsaPublicKey.Exponent)}"",""kty"":""RSA"",""n"":""{Base64UrlHelpers.Encode(rsaPublicKey.Modulus)}""}}"; }