mirror of
https://github.com/MAKS-IT-COM/maksit-certs-ui.git
synced 2025-12-31 04:00:03 +01:00
(refactor): use anonymous obj for thumbpring json
This commit is contained in:
parent
e5f400749e
commit
0bbb412e97
@ -1,5 +1,7 @@
|
|||||||
using MaksIT.LetsEncrypt.Models.Responses;
|
using MaksIT.Core.Security.JWK;
|
||||||
|
using MaksIT.LetsEncrypt.Models.Responses;
|
||||||
using MaksIT.LetsEncrypt.Services;
|
using MaksIT.LetsEncrypt.Services;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
|
||||||
namespace MaksIT.LetsEncrypt.Entities.LetsEncrypt;
|
namespace MaksIT.LetsEncrypt.Entities.LetsEncrypt;
|
||||||
@ -12,4 +14,9 @@ public class State {
|
|||||||
public List<AuthorizationChallengeChallenge> Challenges { get; } = new List<AuthorizationChallengeChallenge>();
|
public List<AuthorizationChallengeChallenge> Challenges { get; } = new List<AuthorizationChallengeChallenge>();
|
||||||
public string? Nonce { get; set; }
|
public string? Nonce { get; set; }
|
||||||
public RegistrationCache? Cache { get; set; }
|
public RegistrationCache? Cache { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Jwk? Jwk;
|
||||||
|
private RSA? RSA;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,12 +26,12 @@ public class JwsService : IJwsService {
|
|||||||
private RSA _rsa;
|
private RSA _rsa;
|
||||||
|
|
||||||
public JwsService(RSA rsa) {
|
public JwsService(RSA rsa) {
|
||||||
_rsa = rsa ?? throw new ArgumentNullException(nameof(rsa));
|
_rsa = rsa;
|
||||||
|
|
||||||
var publicParameters = rsa.ExportParameters(false);
|
var publicParameters = rsa.ExportParameters(false);
|
||||||
|
|
||||||
var exp = publicParameters.Exponent ?? throw new ArgumentNullException(nameof(publicParameters.Exponent));
|
var exp = publicParameters.Exponent;
|
||||||
var mod = publicParameters.Modulus ?? throw new ArgumentNullException(nameof(publicParameters.Modulus));
|
var mod = publicParameters.Modulus;
|
||||||
|
|
||||||
_jwk = new Jwk() {
|
_jwk = new Jwk() {
|
||||||
KeyType = JwkKeyType.Rsa.Name,
|
KeyType = JwkKeyType.Rsa.Name,
|
||||||
@ -80,6 +80,11 @@ public class JwsService : IJwsService {
|
|||||||
public string GetKeyAuthorization(string token) =>
|
public string GetKeyAuthorization(string token) =>
|
||||||
$"{token}.{GetSha256Thumbprint()}";
|
$"{token}.{GetSha256Thumbprint()}";
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For thumbprint calculation, always build the JSON string manually or use an anonymous object with the correct property order
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
private string GetSha256Thumbprint() {
|
private string GetSha256Thumbprint() {
|
||||||
|
|
||||||
var thumbprint = new {
|
var thumbprint = new {
|
||||||
@ -88,7 +93,7 @@ public class JwsService : IJwsService {
|
|||||||
n = _jwk.RsaModulus
|
n = _jwk.RsaModulus
|
||||||
};
|
};
|
||||||
|
|
||||||
var json = "{\"e\":\"" + _jwk.RsaExponent + "\",\"kty\":\"RSA\",\"n\":\"" + _jwk.RsaModulus + "\"}";
|
var json = thumbprint.ToJson();
|
||||||
return Base64UrlUtility.Encode(SHA256.HashData(Encoding.UTF8.GetBytes(json)));
|
return Base64UrlUtility.Encode(SHA256.HashData(Encoding.UTF8.GetBytes(json)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user