Skip to content

Commit

Permalink
Fixes for CodeQL + spelling fixes. (#4361)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak authored Sep 29, 2023
1 parent 80c3be5 commit 9029e1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
/// 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
/// </summary>
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;
Expand Down Expand Up @@ -70,12 +69,10 @@ private static string GetCrvParameterValue(ECCurve curve)
/// </summary>
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -31,7 +29,7 @@ public byte[] Sign(byte[] payload)
return key.SignData(
payload,
HashAlgorithmName.SHA256,
RSASignaturePadding.Pkcs1);
RSASignaturePadding.Pss);
}
}

Expand All @@ -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
/// </summary>
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)}""}}";
}
Expand Down

0 comments on commit 9029e1c

Please sign in to comment.