Skip to content

Commit

Permalink
Change to use the new method added to BCL (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Jan 11, 2025
1 parent 797d72f commit 812fbfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
12 changes: 5 additions & 7 deletions KeyVault.Acmebot/Internal/AcmeProtocolClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ byte[] HmacSignature(byte[] x)
{
var hmacKeyBytes = CryptoHelper.Base64.UrlDecode(_options.ExternalAccountBinding.HmacKey);

var hmac = (HMAC)(_options.ExternalAccountBinding.Algorithm switch
return _options.ExternalAccountBinding.Algorithm switch
{
"HS256" => new HMACSHA256(hmacKeyBytes),
"HS384" => new HMACSHA384(hmacKeyBytes),
"HS512" => new HMACSHA512(hmacKeyBytes),
"HS256" => HMACSHA256.HashData(hmacKeyBytes, x),
"HS384" => HMACSHA384.HashData(hmacKeyBytes, x),
"HS512" => HMACSHA512.HashData(hmacKeyBytes, x),
_ => throw new NotSupportedException($"The signature algorithm {_options.ExternalAccountBinding.Algorithm} is not supported. (supported values are HS256 / HS384 / HS512)")
});

return hmac.ComputeHash(x);
};
}

var payload = JsonConvert.SerializeObject(acmeProtocolClient.Signer.ExportJwk());
Expand Down
17 changes: 1 addition & 16 deletions KeyVault.Acmebot/Internal/CertificateExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Azure.Security.KeyVault.Certificates;

Expand Down Expand Up @@ -33,7 +32,7 @@ public static CertificateItem ToCertificateItem(this KeyVaultCertificateWithPoli
DnsProviderName = certificate.Properties.Tags.TryGetDnsProvider(out var dnsProviderName) ? dnsProviderName : "",
CreatedOn = certificate.Properties.CreatedOn.Value,
ExpiresOn = certificate.Properties.ExpiresOn.Value,
X509Thumbprint = ToHexString(certificate.Properties.X509Thumbprint),
X509Thumbprint = Convert.ToHexString(certificate.Properties.X509Thumbprint),
KeyType = certificate.Policy.KeyType?.ToString(),
KeySize = certificate.Policy.KeySize,
KeyCurveName = certificate.Policy.KeyCurveName?.ToString(),
Expand Down Expand Up @@ -93,19 +92,5 @@ public static IDictionary<string, string> ToCertificateMetadata(this Certificate

private static bool TryGetDnsAlias(this IDictionary<string, string> tags, out string dnsAlias) => tags.TryGetValue(DnsAliasKey, out dnsAlias);

private static string ToHexString(byte[] bytes)
{
ArgumentNullException.ThrowIfNull(bytes);

var result = new StringBuilder();

foreach (var b in bytes)
{
result.Append(b.ToString("x2"));
}

return result.ToString();
}

private static string NormalizeEndpoint(string endpoint) => Uri.TryCreate(endpoint, UriKind.Absolute, out var legacyEndpoint) ? legacyEndpoint.Host : endpoint;
}

0 comments on commit 812fbfc

Please sign in to comment.