/* * Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved. * * This file is part of System Informer. * * Authors: * * dmex * */ namespace CustomBuildTool { // https://learn.microsoft.com/en-us/rest/api/keyvault/certificates/get-certificate/get-certificate?tabs=HTTP //public class AccessTokenCredential : TokenCredential //{ // private readonly AccessToken accessToken; // // public AccessTokenCredential(string token, DateTimeOffset expiresOn) // { // ArgumentException.ThrowIfNullOrWhiteSpace(token); // "Access Token cannot be null or empty" // // accessToken = new AccessToken(token, expiresOn); // } // // public AccessTokenCredential(string token) // { // ArgumentException.ThrowIfNullOrWhiteSpace(token); // "Access Token cannot be null or empty" // // accessToken = new AccessToken(token, DateTimeOffset.UtcNow.AddHours(1)); // } // // public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) // { // return accessToken; // } // // public override ValueTask GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) // { // return new ValueTask(accessToken); // } //} public enum KeyVaultSignatureAlgorithm { RSAPkcs15, ECDsa } // JWS / JWT signature algorithm identifiers used by the codebase. public enum SignatureAlgorithm { RSNULL, RS256, RS384, RS512, ES256, ES384, ES512 } /// /// Provides methods for translating signature algorithm and hash algorithm combinations to their corresponding JSON /// Web Signature (JWS) algorithm identifiers. /// /// This class is intended for use when interoperating with systems that require JWS algorithm /// identifiers, such as JWT libraries or web authentication protocols. All methods are static and /// thread-safe. public static class SignatureAlgorithmTranslator { /// /// Maps a Key Vault signature algorithm and hash algorithm to the corresponding JWS algorithm identifier. /// /// Use this method to obtain the JWS algorithm identifier required for JWT signing when /// using Azure Key Vault signature algorithms. Only specific combinations of signature and hash algorithms are /// supported. /// The signature algorithm to convert. Supported values are RSAPkcs15 and ECDsa. /// The hash algorithm used with the signature algorithm. Supported values are SHA256, SHA384, and SHA512. /// A string containing the JWS algorithm identifier that matches the specified signature and hash algorithm. /// Thrown if the combination of signature algorithm and hash algorithm is not supported. public static string SignatureAlgorithmToJwsAlgId(KeyVaultSignatureAlgorithm SignatureAlgorithm, HashAlgorithmName HashAlgorithmName) { switch (SignatureAlgorithm) { case KeyVaultSignatureAlgorithm.RSAPkcs15: if (HashAlgorithmName == HashAlgorithmName.SHA256) { return "RS256"; } if (HashAlgorithmName == HashAlgorithmName.SHA384) { return "RS384"; } if (HashAlgorithmName == HashAlgorithmName.SHA512) { return "RS512"; } break; case KeyVaultSignatureAlgorithm.ECDsa: if (HashAlgorithmName == HashAlgorithmName.SHA256) { return "ES256"; } if (HashAlgorithmName == HashAlgorithmName.SHA384) { return "ES384"; } if (HashAlgorithmName == HashAlgorithmName.SHA512) { return "ES512"; } break; } throw new NotSupportedException("The algorithm specified is not supported."); } } }