diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5e5d5b4bdb..2f29ac340c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,9 +1,19 @@ name: "CodeQL" on: - push: + push: + paths-ignore: + - 'test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/**' + - 'test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/**' + - '/src/Microsoft.IdentityModel.KeyVaultExtensions/**' + - '/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/**' branches: [ "dev", "dev6x", "dev7x"] pull_request: + paths-ignore: + - 'test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/**' + - 'test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/**' + - '/src/Microsoft.IdentityModel.KeyVaultExtensions/**' + - '/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/**' types: - opened - synchronize diff --git a/Wilson.sln b/Wilson.sln index 8dd5dcbce2..18274278e0 100644 --- a/Wilson.sln +++ b/Wilson.sln @@ -66,18 +66,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.Jso EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{EB14B99B-2255-45BC-BF14-E488DCD4A4BA}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{B961CF69-0DE6-4B9F-9473-9F669365BD62}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.KeyVaultExtensions.Tests", "test\Microsoft.IdentityModel.KeyVaultExtensions.Tests\Microsoft.IdentityModel.KeyVaultExtensions.Tests.csproj", "{987772FA-BA24-4EF4-9B58-3DA78FFD61DD}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests", "test\Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests\Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests.csproj", "{97315A25-B694-4BD0-8DF5-C339884A6D26}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.KeyVaultExtensions", "src\Microsoft.IdentityModel.KeyVaultExtensions\Microsoft.IdentityModel.KeyVaultExtensions.csproj", "{F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.TestExtensions", "src\Microsoft.IdentityModel.TestExtensions\Microsoft.IdentityModel.TestExtensions.csproj", "{AF787AA8-DE6E-4B74-816E-E8F3203A2FA0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.ManagedKeyVaultSecurityKey", "src\Microsoft.IdentityModel.ManagedKeyVaultSecurityKey\Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.csproj", "{8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.Protocols.SignedHttpRequest", "src\Microsoft.IdentityModel.Protocols.SignedHttpRequest\Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj", "{C768FBB5-DE0D-4970-918C-96B37485E34C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.IdentityModel.Protocols.SignedHttpRequest.Tests", "test\Microsoft.IdentityModel.Protocols.SignedHttpRequest.Tests\Microsoft.IdentityModel.Protocols.SignedHttpRequest.Tests.csproj", "{15944563-F7DA-4150-B5F1-6144EBF2CE23}" @@ -200,26 +190,10 @@ Global {DBF58792-25DF-4B6E-866C-77A0BC5AB81B}.Debug|Any CPU.Build.0 = Debug|Any CPU {DBF58792-25DF-4B6E-866C-77A0BC5AB81B}.Release|Any CPU.ActiveCfg = Release|Any CPU {DBF58792-25DF-4B6E-866C-77A0BC5AB81B}.Release|Any CPU.Build.0 = Release|Any CPU - {987772FA-BA24-4EF4-9B58-3DA78FFD61DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {987772FA-BA24-4EF4-9B58-3DA78FFD61DD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {987772FA-BA24-4EF4-9B58-3DA78FFD61DD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {987772FA-BA24-4EF4-9B58-3DA78FFD61DD}.Release|Any CPU.Build.0 = Release|Any CPU - {97315A25-B694-4BD0-8DF5-C339884A6D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97315A25-B694-4BD0-8DF5-C339884A6D26}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97315A25-B694-4BD0-8DF5-C339884A6D26}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97315A25-B694-4BD0-8DF5-C339884A6D26}.Release|Any CPU.Build.0 = Release|Any CPU - {F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6}.Release|Any CPU.Build.0 = Release|Any CPU {AF787AA8-DE6E-4B74-816E-E8F3203A2FA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AF787AA8-DE6E-4B74-816E-E8F3203A2FA0}.Debug|Any CPU.Build.0 = Debug|Any CPU {AF787AA8-DE6E-4B74-816E-E8F3203A2FA0}.Release|Any CPU.ActiveCfg = Release|Any CPU {AF787AA8-DE6E-4B74-816E-E8F3203A2FA0}.Release|Any CPU.Build.0 = Release|Any CPU - {8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F}.Release|Any CPU.Build.0 = Release|Any CPU {C768FBB5-DE0D-4970-918C-96B37485E34C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C768FBB5-DE0D-4970-918C-96B37485E34C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C768FBB5-DE0D-4970-918C-96B37485E34C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -289,12 +263,7 @@ Global {E4E6D0ED-12CB-4C01-A4C1-4F60D10E2304} = {BD2706C5-6C57-484D-89C8-A0CF5F8E3D19} {DBF58792-25DF-4B6E-866C-77A0BC5AB81B} = {BD2706C5-6C57-484D-89C8-A0CF5F8E3D19} {EB14B99B-2255-45BC-BF14-E488DCD4A4BA} = {BD2706C5-6C57-484D-89C8-A0CF5F8E3D19} - {B961CF69-0DE6-4B9F-9473-9F669365BD62} = {8905D2E3-4499-4A86-BF3E-F098F228DD59} - {987772FA-BA24-4EF4-9B58-3DA78FFD61DD} = {B961CF69-0DE6-4B9F-9473-9F669365BD62} - {97315A25-B694-4BD0-8DF5-C339884A6D26} = {B961CF69-0DE6-4B9F-9473-9F669365BD62} - {F5636C24-D6D5-4F6A-8A21-7C78FC1FC6C6} = {EB14B99B-2255-45BC-BF14-E488DCD4A4BA} {AF787AA8-DE6E-4B74-816E-E8F3203A2FA0} = {EB14B99B-2255-45BC-BF14-E488DCD4A4BA} - {8DFF1DEA-F01F-4CE4-9471-5D2CEFB7E59F} = {EB14B99B-2255-45BC-BF14-E488DCD4A4BA} {C768FBB5-DE0D-4970-918C-96B37485E34C} = {BD2706C5-6C57-484D-89C8-A0CF5F8E3D19} {15944563-F7DA-4150-B5F1-6144EBF2CE23} = {8905D2E3-4499-4A86-BF3E-F098F228DD59} {DA585910-0E6C-45A5-AABD-30917130FD63} = {BD2706C5-6C57-484D-89C8-A0CF5F8E3D19} diff --git a/build/dependencies.props b/build/dependencies.props index 23e1b91065..8203da572c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -2,8 +2,6 @@ 2.1.1 - 3.0.5 - 1.0.3 4.5.0 1.0.0 2.0.3 diff --git a/buildConfiguration.xml b/buildConfiguration.xml index 06e064dafa..0abda703bf 100644 --- a/buildConfiguration.xml +++ b/buildConfiguration.xml @@ -14,8 +14,6 @@ - - @@ -33,8 +31,6 @@ - - diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/InternalsVisibleTo.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/InternalsVisibleTo.cs deleted file mode 100644 index 5e625e7a84..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/InternalsVisibleTo.cs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.KeyVaultExtensions.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultCryptoProvider.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultCryptoProvider.cs deleted file mode 100644 index 7eecfe8d82..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultCryptoProvider.cs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Linq; -using Microsoft.Azure.KeyVault.WebKey; -using Microsoft.IdentityModel.Logging; -using Microsoft.IdentityModel.Tokens; - -namespace Microsoft.IdentityModel.KeyVaultExtensions -{ - /// - /// Provides cryptographic operators based on Azure Key Vault. - /// - public class KeyVaultCryptoProvider : ICryptoProvider - { - private readonly CryptoProviderCache _cache; - - /// - /// Initializes a new instance of the class. - /// - public KeyVaultCryptoProvider() - { - _cache = new InMemoryCryptoProviderCache(); - } - - /// - /// Gets the - /// - internal CryptoProviderCache CryptoProviderCache => _cache; - - /// - /// Returns a cryptographic operator that supports the algorithm. - /// - /// the algorithm that defines the cryptographic operator. - /// the arguments required by the cryptographic operator. May be null. - /// if is null or empty. - /// if is null. - /// if does not contain a . - /// call when finished with the object. - public object Create(string algorithm, params object[] args) - { - if (string.IsNullOrEmpty(algorithm)) - throw LogHelper.LogArgumentNullException(nameof(algorithm)); - - if (args == null) - throw LogHelper.LogArgumentNullException(nameof(args)); - - if (args.FirstOrDefault() is KeyVaultSecurityKey key) - { - if (JsonWebKeyEncryptionAlgorithm.AllAlgorithms.Contains(algorithm, StringComparer.Ordinal)) - return new KeyVaultKeyWrapProvider(key, algorithm); - else if (JsonWebKeySignatureAlgorithm.AllAlgorithms.Contains(algorithm, StringComparer.Ordinal)) - { - var willCreateSignatures = (bool)(args.Skip(1).FirstOrDefault() ?? false); - - if (_cache.TryGetSignatureProvider(key, algorithm, typeofProvider: key.GetType().ToString(), willCreateSignatures, out var cachedProvider)) - return cachedProvider; - - var signatureProvider = new KeyVaultSignatureProvider(key, algorithm, willCreateSignatures); - if (CryptoProviderFactory.ShouldCacheSignatureProvider(signatureProvider)) - _cache.TryAdd(signatureProvider); - - return signatureProvider; - } - } - - throw LogHelper.LogExceptionMessage(new NotSupportedException(LogHelper.FormatInvariant(LogMessages.IDX10652, LogHelper.MarkAsNonPII(algorithm)))); - } - - /// - /// Called to determine if a cryptographic operation is supported. - /// - /// the algorithm that defines the cryptographic operator. - /// the arguments required by the cryptographic operator. May be null. - /// true if supported - public bool IsSupportedAlgorithm(string algorithm, params object[] args) - { - if (string.IsNullOrEmpty(algorithm)) - throw LogHelper.LogArgumentNullException(nameof(algorithm)); - - if (args == null) - throw LogHelper.LogArgumentNullException(nameof(args)); - - return args.FirstOrDefault() is KeyVaultSecurityKey - && (JsonWebKeyEncryptionAlgorithm.AllAlgorithms.Contains(algorithm, StringComparer.Ordinal) || JsonWebKeySignatureAlgorithm.AllAlgorithms.Contains(algorithm, StringComparer.Ordinal)); - } - - /// - /// Called to release the object returned from - /// - /// the object returned from . - public void Release(object cryptoInstance) - { - if (cryptoInstance is SignatureProvider signatureProvider) - _cache.TryRemove(signatureProvider); - - if (cryptoInstance is IDisposable obj) - obj.Dispose(); - } - } -} diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultKeyWrapProvider.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultKeyWrapProvider.cs deleted file mode 100644 index 63c625fe03..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultKeyWrapProvider.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.Logging; -using Microsoft.IdentityModel.Tokens; - -namespace Microsoft.IdentityModel.KeyVaultExtensions -{ - /// - /// Provides wrap and unwrap operations using Azure Key Vault. - /// - public class KeyVaultKeyWrapProvider : KeyWrapProvider - { - private readonly IKeyVaultClient _client; - private readonly KeyVaultSecurityKey _key; - private readonly string _algorithm; - private bool _disposed = false; - - /// - /// Initializes a new instance of the class. - /// - /// The that will be used for key wrap operations. - /// The key wrap algorithm to apply. - /// if is null. - /// if is not a . - /// if is null or empty. - public KeyVaultKeyWrapProvider(SecurityKey key, string algorithm) - : this(key, algorithm, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The that will be used for key wrap operations. - /// The key wrap algorithm to apply. - /// A mock used for testing purposes. - internal KeyVaultKeyWrapProvider(SecurityKey key, string algorithm, IKeyVaultClient? client) - { - _algorithm = string.IsNullOrEmpty(algorithm) ? throw LogHelper.LogArgumentNullException(nameof(algorithm)) : algorithm; - if (key == null) - throw LogHelper.LogArgumentNullException(nameof(key)); - - _key = key as KeyVaultSecurityKey ?? throw LogHelper.LogExceptionMessage(new NotSupportedException(key.GetType().ToString())); - _client = client ?? new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(_key.Callback!)); - } - - /// - /// Gets the KeyWrap algorithm that is being used. - /// - public override string Algorithm => _algorithm; - - /// - /// Gets or sets a user context for a . - /// - /// This is null by default. This can be used by runtimes or for extensibility scenarios. - public override string? Context { get; set; } - - /// - /// Gets the that is being used. - /// - public override SecurityKey Key => _key; - - /// - /// Unwrap a key. - /// - /// key to unwrap. - /// if is null. - /// if .Length == 0. - /// Unwrapped key. - public override byte[] UnwrapKey(byte[] keyBytes) - { - return UnwrapKeyAsync(keyBytes, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); - } - - /// - /// Wrap a key. - /// - /// the key to be wrapped - /// if is null. - /// if .Length == 0. - /// wrapped key. - public override byte[] WrapKey(byte[] keyBytes) - { - return WrapKeyAsync(keyBytes, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - /// true, if called from Dispose(), false, if invoked inside a finalizer - protected override void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - _disposed = true; - _client.Dispose(); - } - } - } - - /// - /// Unwraps a symmetric key using Azure Key Vault. - /// - /// key to unwrap. - /// Propagates notification that operations should be canceled. - /// if is null. - /// if .Length == 0. - /// Unwrapped key. - private async Task UnwrapKeyAsync(byte[] keyBytes, CancellationToken cancellation) - { - if (keyBytes == null || keyBytes.Length == 0) - throw LogHelper.LogArgumentNullException(nameof(keyBytes)); - - return (await _client.UnwrapKeyAsync(_key.KeyId, Algorithm, keyBytes, cancellation).ConfigureAwait(false)).Result; - } - - /// - /// Wraps a symmetric key using Azure Key Vault. - /// - /// the key to be wrapped - /// Propagates notification that operations should be canceled. - /// if is null. - /// if .Length == 0. - /// wrapped key. - private async Task WrapKeyAsync(byte[] keyBytes, CancellationToken cancellation) - { - if (keyBytes == null || keyBytes.Length == 0) - throw LogHelper.LogArgumentNullException(nameof(keyBytes)); - - return (await _client.WrapKeyAsync(_key.KeyId, Algorithm, keyBytes, cancellation).ConfigureAwait(false)).Result; - } - } -} diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSecurityKey.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSecurityKey.cs deleted file mode 100644 index 9a56ce27e8..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSecurityKey.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.Logging; -using Microsoft.IdentityModel.Tokens; - -namespace Microsoft.IdentityModel.KeyVaultExtensions -{ - /// - /// Provides signing and verifying operations using Azure Key Vault. - /// - public class KeyVaultSecurityKey : SecurityKey - { - private int? _keySize; - private string? _keyId; - - /// - /// The authentication callback delegate which is to be implemented by the client code. - /// - /// Identifier of the authority, a URL. - /// Identifier of the target resource that is the recipient of the requested token, a URL. - /// The scope of the authentication request. - /// An access token for Azure Key Vault. - public delegate Task AuthenticationCallback(string authority, string resource, string scope); - - /// - /// Initializes a new instance of the class. - /// - protected KeyVaultSecurityKey() - { - - } - - /// - /// Initializes a new instance of the class. - /// - /// The key identifier that is recognized by KeyVault. - /// The authentication callback that will obtain the access_token for KeyVault. - /// if is null or empty. - /// if is null. - public KeyVaultSecurityKey(string keyIdentifier, AuthenticationCallback callback) - { - Callback = callback ?? throw LogHelper.LogArgumentNullException(nameof(callback)); - KeyId = keyIdentifier; - } - - internal KeyVaultSecurityKey(string keyIdentifier, int keySize) - { - _keyId = keyIdentifier; - _keySize = keySize; - } - - /// - /// The authentication callback delegate that retrieves an access token for the KeyVault. - /// - public AuthenticationCallback? Callback { get; protected set; } - - /// - /// The uniform resource identifier of the security key. - /// - public override string KeyId - { - get => _keyId!; - set - { - if (string.IsNullOrEmpty(value)) - throw LogHelper.LogArgumentNullException(nameof(value)); - else if (StringComparer.Ordinal.Equals(_keyId, value)) - return; - - _keyId = value; - - // Reset the properties so they can be retrieved from Azure KeyVault the next time they are accessed. - _keySize = null; - } - } - - /// - /// The size of the security key. - /// - public override int KeySize - { - get - { - if (!_keySize.HasValue) - Initialize(); - - return _keySize!.Value; - } - } - - /// - /// Retrieve the properties from Azure Key Vault. - /// - private void Initialize() - { - using (var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(Callback!))) - { - var bundle = client.GetKeyAsync(_keyId, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); - _keySize = new BitArray(bundle.Key.N).Length; - } - } - } -} diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSignatureProvider.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSignatureProvider.cs deleted file mode 100644 index 38478482fd..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/KeyVaultSignatureProvider.cs +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Security.Cryptography; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.Logging; -using Microsoft.IdentityModel.Tokens; - -namespace Microsoft.IdentityModel.KeyVaultExtensions -{ - /// - /// Provides signing and verifying operations using Azure Key Vault. - /// - public class KeyVaultSignatureProvider : SignatureProvider - { - private readonly HashAlgorithm _hash; - private readonly IKeyVaultClient _client; - private readonly KeyVaultSecurityKey _key; - private bool _disposed = false; - - /// - /// Initializes a new instance of the class. - /// - /// The that will be used for signature operations. - /// The signature algorithm to apply. - /// Whether this is required to create signatures then set this to true. - /// is null. - /// is null or empty. - public KeyVaultSignatureProvider(SecurityKey key, string algorithm, bool willCreateSignatures) - : this(key, algorithm, willCreateSignatures, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The that will be used for signature operations. - /// The signature algorithm to apply. - /// Whether this is required to create signatures then set this to true. - /// A mock used for testing purposes. - internal KeyVaultSignatureProvider(SecurityKey key, string algorithm, bool willCreateSignatures, IKeyVaultClient? client) - : base(key, algorithm) - { - _key = key as KeyVaultSecurityKey ?? throw LogHelper.LogArgumentNullException(nameof(key)); - _client = client ?? new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(_key.Callback!)); - WillCreateSignatures = willCreateSignatures; - - switch (algorithm) - { - case SecurityAlgorithms.RsaSha256: - _hash = SHA256.Create(); - break; - case SecurityAlgorithms.RsaSha384: - _hash = SHA384.Create(); - break; - case SecurityAlgorithms.RsaSha512: - _hash = SHA512.Create(); - break; - default: - throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX10652, LogHelper.MarkAsNonPII(algorithm)), nameof(algorithm))); - } - } - - /// - /// Produces a signature over the 'input' using Azure Key Vault. - /// - /// The bytes to sign. - /// A signature over the input. - /// if is null. - /// if .Length == 0. - /// If Dispose has been called. - public override byte[] Sign(byte[] input) - { - return SignAsync(input, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); - } - - /// - /// Verifies that the is over using Azure Key Vault. - /// - /// bytes to verify. - /// signature to compare against. - /// true if the computed signature matches the signature parameter, false otherwise. - /// is null or has length == 0. - /// is null or has length == 0. - /// If Dispose has been called. - public override bool Verify(byte[] input, byte[] signature) - { - return VerifyAsync(input, signature, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); - } - - /// - public override bool Verify(byte[] input, int inputOffset, int lengthOffset, byte[] signature, int signatureOffset, int signatureLength) => throw new NotImplementedException(); - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - /// true, if called from Dispose(), false, if invoked inside a finalizer - protected override void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - _disposed = true; - _hash.Dispose(); - _client.Dispose(); - } - } - } - - /// - /// Creates a digital signature using Azure Key Vault. - /// - /// bytes to sign. - /// Propagates notification that operations should be canceled. - /// A signature over the input. - /// is null or has length == 0. - /// If Dispose has been called. - private async Task SignAsync(byte[] input, CancellationToken cancellation) - { - if (input == null || input.Length == 0) - throw LogHelper.LogArgumentNullException(nameof(input)); - - if (_disposed) - throw LogHelper.LogExceptionMessage(new ObjectDisposedException(GetType().ToString())); - - return (await _client.SignAsync(_key.KeyId, Algorithm, _hash.ComputeHash(input), cancellation).ConfigureAwait(false)).Result; - } - - /// - /// Verifies a digital signature using Azure Key Vault. - /// - /// bytes to verify. - /// signature to compare against. - /// Propagates notification that operations should be canceled. - /// true if the computed signature matches the signature parameter, false otherwise. - /// is null or has length == 0. - /// is null or has length == 0. - /// If Dispose has been called. - private async Task VerifyAsync(byte[] input, byte[] signature, CancellationToken cancellation) - { - if (input == null || input.Length == 0) - throw LogHelper.LogArgumentNullException(nameof(input)); - - if (signature == null || signature.Length == 0) - throw LogHelper.LogArgumentNullException(nameof(signature)); - - if (_disposed) - throw LogHelper.LogExceptionMessage(new ObjectDisposedException(GetType().ToString())); - - return await _client.VerifyAsync(_key.KeyId, Algorithm, _hash.ComputeHash(input), signature, cancellation).ConfigureAwait(false); - } - } -} diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj b/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj deleted file mode 100644 index 2825f85730..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - Microsoft.IdentityModel.KeyVaultExtensions - Includes types that provide support for signing and encrypting tokens with Azure Key Vault. - true - Microsoft.IdentityModel.KeyVaultExtensions - netstandard2.0;net6.0;net8.0 - $(TargetFrameworks);net9.0 - .NET;Windows;Authentication;Identity;Azure;Key;Vault;Extensions - enable - - - - full - true - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/Properties/AssemblyInfo.cs b/src/Microsoft.IdentityModel.KeyVaultExtensions/Properties/AssemblyInfo.cs deleted file mode 100644 index 1f06ec3782..0000000000 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: CLSCompliant(true)] -[assembly: ComVisible(false)] diff --git a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/GlobalSuppression.cs b/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/GlobalSuppression.cs deleted file mode 100644 index 04498d0dc3..0000000000 --- a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/GlobalSuppression.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Previously released with this name", Scope ="Type", Target = "Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.ManagedKeyVaultSecurityKey")] diff --git a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/InternalsVisibleTo.cs b/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/InternalsVisibleTo.cs deleted file mode 100644 index cae70d8a10..0000000000 --- a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/InternalsVisibleTo.cs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.Tokens.Extensions.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/ManagedKeyVaultSecurityKey.cs b/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/ManagedKeyVaultSecurityKey.cs deleted file mode 100644 index 78ce01f9ee..0000000000 --- a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/ManagedKeyVaultSecurityKey.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Azure.Services.AppAuthentication; -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using Microsoft.IdentityModel.KeyVaultExtensions; -using Microsoft.IdentityModel.Logging; -using System; - -namespace Microsoft.IdentityModel.ManagedKeyVaultSecurityKey -{ - /// - /// Provides signing and verifying operations using Azure Key Vault - /// for resources that are using Managed identities for Azure resources. - /// - public class ManagedKeyVaultSecurityKey : KeyVaultSecurityKey - { - /// - /// Initializes a new instance of the class. - /// - /// The key identifier that is recognized by KeyVault. - /// if is null or empty. - public ManagedKeyVaultSecurityKey(string keyIdentifier) - : base(keyIdentifier, new AuthenticationCallback((new AzureServiceTokenProvider()).KeyVaultTokenCallback)) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The key identifier that is recognized by KeyVault. - /// The authentication callback. - /// if is null or empty. - /// if is null. - public ManagedKeyVaultSecurityKey(string keyIdentifier, AuthenticationCallback callback) - : base(keyIdentifier, callback) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The key identifier. - /// Identifier of the client. - /// Secret of the client identity. - /// if is null or empty. - /// if is null or empty. - /// if is null or clientSecret. - public ManagedKeyVaultSecurityKey(string keyIdentifier, string clientId, string clientSecret) - { - if (string.IsNullOrEmpty(keyIdentifier)) - throw LogHelper.LogArgumentNullException(nameof(keyIdentifier)); - - if (string.IsNullOrEmpty(clientId)) - throw LogHelper.LogArgumentNullException(nameof(clientId)); - - if (string.IsNullOrEmpty(clientSecret)) - throw LogHelper.LogArgumentNullException(nameof(clientSecret)); - - KeyId = keyIdentifier; - Callback = new AuthenticationCallback(async (string authority, string resource, string scope) => - (await (new AuthenticationContext(authority, TokenCache.DefaultShared)).AcquireTokenAsync(resource, new ClientCredential(clientId, clientSecret)).ConfigureAwait(false)).AccessToken); - } - } -} diff --git a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.csproj b/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.csproj deleted file mode 100644 index aa342135ca..0000000000 --- a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - Microsoft.IdentityModel.ManagedKeyVaultSecurityKey - Includes types that provide support for signing and encrypting tokens with Azure Key Vault for - Applications that are using Managed identities for Azure resources. - true - Microsoft.IdentityModel.ManagedKeyVaultSecurityKey - netstandard2.0 - .NET;Windows;Authentication;Identity;Azure;Key;Vault;Extensions - enable - - - - full - true - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Properties/AssemblyInfo.cs b/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Properties/AssemblyInfo.cs deleted file mode 100644 index 1f06ec3782..0000000000 --- a/src/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: CLSCompliant(true)] -[assembly: ComVisible(false)] diff --git a/src/Microsoft.IdentityModel.Tokens/InternalsVisibleTo.cs b/src/Microsoft.IdentityModel.Tokens/InternalsVisibleTo.cs index ba34f3462b..dd03b90595 100644 --- a/src/Microsoft.IdentityModel.Tokens/InternalsVisibleTo.cs +++ b/src/Microsoft.IdentityModel.Tokens/InternalsVisibleTo.cs @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.KeyVaultExtensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.TestUtils, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("CrossVersionTokenValidation.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.Tokens.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.JsonWebTokens, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.JsonWebTokens.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.Protocols.OpenIdConnect, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.TestUtils, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.IdentityModel.Tokens.Jwt, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.IdentityModel.Tokens.Jwt.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.IdentityModel.S2S, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/src/Microsoft.IdentityModel.Tokens/Properties/AssemblyInfo.cs b/src/Microsoft.IdentityModel.Tokens/Properties/AssemblyInfo.cs index f22a0f4b5e..12d7bcb55f 100644 --- a/src/Microsoft.IdentityModel.Tokens/Properties/AssemblyInfo.cs +++ b/src/Microsoft.IdentityModel.Tokens/Properties/AssemblyInfo.cs @@ -17,7 +17,6 @@ [assembly: InternalsVisibleTo("Microsoft.IdentityModel.Tokens.Saml, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("Microsoft.IdentityModel.Xml, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("Microsoft.AzureAD.SmartSessionEvaluator, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] -[assembly: InternalsVisibleTo("Microsoft.IdentityModel.KeyVaultExtensions.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("Microsoft.IdentityModel.Protocols, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("Microsoft.IdentityModel.Protocols.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("Microsoft.IdentityModel.Validators, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/Microsoft.IdentityModel.JsonWebTokens.Tests.csproj b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/Microsoft.IdentityModel.JsonWebTokens.Tests.csproj index e333ac1f95..523c78d729 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/Microsoft.IdentityModel.JsonWebTokens.Tests.csproj +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/Microsoft.IdentityModel.JsonWebTokens.Tests.csproj @@ -20,6 +20,10 @@ + + + + diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultCryptoProviderTests.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultCryptoProviderTests.cs deleted file mode 100644 index 39e83e852c..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultCryptoProviderTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading.Tasks; -using Microsoft.Azure.KeyVault.WebKey; -using Microsoft.IdentityModel.TestUtils; -using Microsoft.IdentityModel.Tokens; -using Xunit; -using static Microsoft.IdentityModel.KeyVaultExtensions.KeyVaultSecurityKey; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultCryptoProviderTests - { - [Fact] - public void ShouldCacheSignatureProvider() - { - TestUtilities.WriteHeader($"{this}.ShouldCacheSignatureProvider"); - var context = new CompareContext($"{this}.ShouldCacheSignatureProvider"); - var keyVaultKeyWithEmptyKid = new CustomKeyVaultSecurityKey("test", new AuthenticationCallback((string authority, string resource, string scope) => Task.FromResult(string.Empty))); - var keyVaultCryptoProvider = new KeyVaultCryptoProvider(); - var signatureProvider = keyVaultCryptoProvider.Create(JsonWebKeySignatureAlgorithm.RS256, keyVaultKeyWithEmptyKid, true); - if (keyVaultCryptoProvider.CryptoProviderCache.TryGetSignatureProvider(keyVaultKeyWithEmptyKid, SecurityAlgorithms.RsaSha256Signature, typeof(KeyVaultSignatureProvider).ToString(), true, out var _)) - context.Diffs.Add("A SignatureProvider was added to keyVaultCryptoProvider.CryptoProviderCache.CryptoProviderCache, but ShouldCacheSignatureProvider() should return false as the key has an empty key id."); - - CryptoProviderFactory.Default.ReleaseSignatureProvider(signatureProvider as KeyVaultSignatureProvider); - - TestUtilities.AssertFailIfErrors(context); - } - - public class CustomKeyVaultSecurityKey : KeyVaultSecurityKey - { - /// - /// Initializes a new instance of the class. - /// - public CustomKeyVaultSecurityKey(string keyIdentifier, AuthenticationCallback callback) : base(keyIdentifier, callback) - { - } - - internal override string InternalId => ""; - } - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultKeyWrapProviderTests.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultKeyWrapProviderTests.cs deleted file mode 100644 index c16f6cdefa..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultKeyWrapProviderTests.cs +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.TestUtils; -using Microsoft.IdentityModel.Tokens; -using Xunit; - -#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultKeyWrapProviderTests - { - private readonly MockKeyVaultClient _client; - private readonly SecurityKey _key; - - public KeyVaultKeyWrapProviderTests() - { - _client = new MockKeyVaultClient(); - _key = new KeyVaultSecurityKey(KeyVaultUtilities.CreateKeyIdentifier(), keySize: default); - } - - [Theory, MemberData(nameof(DisposeProviderTheoryData))] - public void DisposeProviderTest(KeyWrapProviderTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.DisposeProviderTest", theoryData); - - try - { - var provider = new KeyVaultKeyWrapProvider(_key, theoryData.Algorithm, _client); - _key.CryptoProviderFactory.ReleaseKeyWrapProvider(provider); - - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception exception) - { - theoryData.ExpectedException.ProcessException(exception, context); - } - - TestUtilities.AssertFailIfErrors(context); - } - - public static TheoryData DisposeProviderTheoryData - { - get => new TheoryData - { - new KeyWrapProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaPKCS1, - ExpectedException = ExpectedException.NoExceptionExpected, - First = true, - TestId = nameof(SecurityAlgorithms.RsaPKCS1), - }, - new KeyWrapProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaOAEP, - ExpectedException = ExpectedException.NoExceptionExpected, - TestId = nameof(SecurityAlgorithms.RsaOAEP), - }, - }; - } - - [Theory, MemberData(nameof(KeyWrapProviderTheoryData))] - public void WrapUnwrapKeyTest(KeyWrapProviderTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.WrapUnwrapKeyTest", theoryData); - - try - { - var provider = new KeyVaultKeyWrapProvider(_key, theoryData.Algorithm, _client); - if (provider == null) - context.AddDiff("(provider == null)"); - - var keyBytes = Guid.NewGuid().ToByteArray(); - var wrappedKey = provider.WrapKey(keyBytes); - if (wrappedKey == null) - context.AddDiff("(wrappedKey == null)"); - - if (_client.ExpectedKeyWrapLength != wrappedKey.Length) - context.AddDiff($"_client.ExpectedKeyWrapLength != wrappedKey.Length. {_client.ExpectedKeyWrapLength} != {wrappedKey.Length}"); - - if (Utility.AreEqual(keyBytes, wrappedKey)) - context.AddDiff("Utility.AreEqual(keyBytes, wrappedKey)"); - - var unwrappedKey = provider.UnwrapKey(wrappedKey); - if (unwrappedKey == null) - context.AddDiff("(unwrappedKey == null)"); - - IdentityComparer.AreBytesEqual(keyBytes, unwrappedKey, context); - - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception exception) - { - theoryData.ExpectedException.ProcessException(exception, context); - } - - TestUtilities.AssertFailIfErrors(context); - } - - public static TheoryData KeyWrapProviderTheoryData - { - get => new TheoryData - { - new KeyWrapProviderTheoryData - { - Algorithm = null, - ExpectedException = ExpectedException.ArgumentNullException(), - First = true, - TestId = "NullAlgorithm", - }, - new KeyWrapProviderTheoryData - { - Algorithm = string.Empty, - ExpectedException = ExpectedException.ArgumentNullException(), - TestId = "EmptyAlgorithm", - }, - new KeyWrapProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaPKCS1, - TestId = nameof(SecurityAlgorithms.RsaPKCS1), - }, - new KeyWrapProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaOAEP, - TestId = nameof(SecurityAlgorithms.RsaOAEP), - }, - }; - } - } -} - -#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyAuthenticationCallbackTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyAuthenticationCallbackTheoryData.cs deleted file mode 100644 index 39747206c6..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyAuthenticationCallbackTheoryData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading.Tasks; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultSecurityKeyAuthenticationCallbackTheoryData : KeyVaultSecurityKeyTheoryData - { - public KeyVaultSecurityKey.AuthenticationCallback Callback { get; set; } = new KeyVaultSecurityKey.AuthenticationCallback((string authority, string resource, string scope) => Task.FromResult(string.Empty)); - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyConfidentialClientTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyConfidentialClientTheoryData.cs deleted file mode 100644 index 75e3f1bca9..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyConfidentialClientTheoryData.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultSecurityKeyConfidentialClientTheoryData : KeyVaultSecurityKeyTheoryData - { - public string ClientId { get; set; } = $"{Guid.NewGuid():D}"; - public string ClientSecret { get; set; } = Guid.NewGuid().ToString(); - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyManagedServiceIdentityTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyManagedServiceIdentityTheoryData.cs deleted file mode 100644 index f5c096fa16..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyManagedServiceIdentityTheoryData.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultSecurityKeyManagedServiceIdentityTheoryData : KeyVaultSecurityKeyTheoryData - { - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTests.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTests.cs deleted file mode 100644 index 9badfe1f52..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTests.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Reflection; -using Microsoft.Azure.KeyVault.Models; -using Microsoft.IdentityModel.TestUtils; -using Xunit; - -#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultSecurityKeyTests - { - private static ExpectedException ArgumentNullExceptionExpected = new ExpectedException(typeExpected: typeof(TargetInvocationException), substringExpected: "Exception has been thrown by the target of an invocation.", innerTypeExpected: typeof(ArgumentNullException)); - private static ExpectedException KeyVaultErrorExceptionExpected = new ExpectedException(typeExpected: typeof(TargetInvocationException), substringExpected: "Exception has been thrown by the target of an invocation.", innerTypeExpected: typeof(KeyVaultErrorException)); - - [Theory, MemberData(nameof(KeyVaultSecurityKeyAuthenticationCallbackTheoryData))] - public void AuthenticationCallbackConstructorParams(KeyVaultSecurityKeyAuthenticationCallbackTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.AuthenticationCallbackConstructorParams", theoryData); - - try - { - _ = Activator.CreateInstance(theoryData.Type, new object[] { theoryData.KeyIdentifier, theoryData.Callback }); - } - catch (Exception ex) - { - theoryData.ExpectedException.ProcessException(ex, context); - } - } - - public static TheoryData KeyVaultSecurityKeyAuthenticationCallbackTheoryData - { - get => new TheoryData - { - new KeyVaultSecurityKeyAuthenticationCallbackTheoryData - { - // Callback = default, - ExpectedException = ExpectedException.ArgumentNullException(), - First = true, - KeyIdentifier = null, - TestId = typeof(KeyVaultSecurityKey).FullName, - Type = typeof(KeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyAuthenticationCallbackTheoryData - { - // Callback = default, - ExpectedException = ExpectedException.ArgumentNullException(), - KeyIdentifier = string.Empty, - TestId = typeof(KeyVaultSecurityKey).FullName, - Type = typeof(KeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyAuthenticationCallbackTheoryData - { - Callback = null, - ExpectedException = ExpectedException.ArgumentNullException(), - // KeyIdentifier = default, - TestId = typeof(KeyVaultSecurityKey).FullName, - Type = typeof(KeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyAuthenticationCallbackTheoryData - { - // Callback = default, - ExpectedException = KeyVaultErrorExceptionExpected, - // KeyIdentifier = default, - TestId = typeof(KeyVaultSecurityKey).FullName, - Type = typeof(KeyVaultSecurityKey), - }, - }; - } - } -} - -#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTheoryData.cs deleted file mode 100644 index 73dd0a20c8..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSecurityKeyTheoryData.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.IdentityModel.TestUtils; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public abstract class KeyVaultSecurityKeyTheoryData : TheoryDataBase - { - public string KeyIdentifier { get; set; } = KeyVaultUtilities.CreateKeyIdentifier(); - public Type Type { get; set; } - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSignatureProviderTests.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSignatureProviderTests.cs deleted file mode 100644 index 7ab512625c..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultSignatureProviderTests.cs +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Linq; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.TestUtils; -using Microsoft.IdentityModel.Tokens; -using Microsoft.IdentityModel.KeyVaultExtensions; -using Xunit; - -#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyVaultSignatureProviderTests - { - private readonly MockKeyVaultClient _client; - private readonly SecurityKey _key; - - public KeyVaultSignatureProviderTests() - { - _client = new MockKeyVaultClient(); - _key = new KeyVaultSecurityKey(KeyVaultUtilities.CreateKeyIdentifier(), keySize: default); - } - - [Theory, MemberData(nameof(DisposeProviderTheoryData))] - public void DisposeProviderTest(SignatureProviderTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.DisposeProviderTest", theoryData); - - try - { - var provider = new KeyVaultSignatureProvider(_key, theoryData.Algorithm, willCreateSignatures: true, _client); - _key.CryptoProviderFactory.ReleaseSignatureProvider(provider); - - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception exception) - { - theoryData.ExpectedException.ProcessException(exception, context); - } - - TestUtilities.AssertFailIfErrors(context); - } - - public static TheoryData DisposeProviderTheoryData - { - get => new TheoryData - { - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha256, - ExpectedException = ExpectedException.NoExceptionExpected, - First = true, - TestId = nameof(SecurityAlgorithms.RsaSha256), - }, - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha384, - ExpectedException = ExpectedException.NoExceptionExpected, - TestId = nameof(SecurityAlgorithms.RsaSha384), - }, - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha512, - ExpectedException = ExpectedException.NoExceptionExpected, - TestId = nameof(SecurityAlgorithms.RsaSha512), - }, - }; - } - - [Theory, MemberData(nameof(SignatureProviderTheoryData))] - public void SignatureTest(SignatureProviderTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.SignatureTest", theoryData); - - try - { - var provider = new KeyVaultSignatureProvider(_key, theoryData.Algorithm, willCreateSignatures: true, _client); - if (provider == null) - context.AddDiff("(provider == null)"); - - var input = Guid.NewGuid().ToByteArray(); - var signature = provider.Sign(input); - - if (signature == null) - context.AddDiff("(signature == null)"); - - if (_client.ExpectedSignatureLength != signature.Length) - context.AddDiff($"_client.ExpectedSignatureLength != signature.Length. == {_client.ExpectedSignatureLength}, {signature.Length}."); - - if (!provider.Verify(input, signature)) - context.AddDiff("!provider.Verify(input, signature)"); - - var tamperedInput = new byte[input.Length]; - input.CopyTo(tamperedInput, 0); - if (tamperedInput[0] == byte.MaxValue) - tamperedInput[0]--; - else - tamperedInput[0]++; - - if (provider.Verify(tamperedInput, signature)) - context.AddDiff("provider.Verify(tamperedInput, signature)"); - - foreach (var data in SignatureProviderTheoryData) - { - var newAlgorithm = (data.Single() as SignatureProviderTheoryData)?.Algorithm; - if (string.IsNullOrEmpty(newAlgorithm)) - continue; // Skip invalid input - - // Check that a given Security Key will only validate a signature using the same hash algorithm. - var isValidSignature = new KeyVaultSignatureProvider(_key, newAlgorithm, willCreateSignatures: false, _client).Verify(input, signature); - if (StringComparer.Ordinal.Equals(theoryData.Algorithm, newAlgorithm)) - { - if (!isValidSignature) - context.AddDiff("Signature should have been valid, isValidSignature == false"); - } - else if (isValidSignature) - context.AddDiff("Signature should NOT have been valid, isValidSignature == true"); - } - - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception exception) - { - theoryData.ExpectedException.ProcessException(exception, context); - } - - TestUtilities.AssertFailIfErrors(context); - } - - public static TheoryData SignatureProviderTheoryData - { - get => new TheoryData - { - new SignatureProviderTheoryData - { - Algorithm = null, - ExpectedException = ExpectedException.ArgumentNullException(), - First = true, - TestId = "NullAlgorithm", - }, - new SignatureProviderTheoryData - { - Algorithm = string.Empty, - ExpectedException = ExpectedException.ArgumentNullException(), - TestId = "EmptyAlgorithm", - }, - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha256, - TestId = nameof(SecurityAlgorithms.RsaSha256), - }, - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha384, - TestId = nameof(SecurityAlgorithms.RsaSha384), - }, - new SignatureProviderTheoryData - { - Algorithm = SecurityAlgorithms.RsaSha512, - TestId = nameof(SecurityAlgorithms.RsaSha512), - }, - }; - } - } -} - -#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultUtilities.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultUtilities.cs deleted file mode 100644 index 072a868068..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyVaultUtilities.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public static class KeyVaultUtilities - { - public static string CreateKeyIdentifier() => CreateKeyIdentifier("contoso.vault.azure.net", nameof(KeyVaultUtilities), $"{Guid.NewGuid():N}"); - - public static string CreateKeyIdentifier(string vaultBaseUrl, string vaultKeyName, string vaultKeyVersion) - { - return new UriBuilder(Uri.UriSchemeHttps, vaultBaseUrl, -1, $"/keys/{vaultKeyName}/{vaultKeyVersion}").Uri.ToString(); - } - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyWrapProviderTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyWrapProviderTheoryData.cs deleted file mode 100644 index 5e8ab0f194..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/KeyWrapProviderTheoryData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.IdentityModel.TestUtils; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class KeyWrapProviderTheoryData : TheoryDataBase - { - public string Algorithm { get; set; } - } -} diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Microsoft.IdentityModel.KeyVaultExtensions.Tests.csproj b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Microsoft.IdentityModel.KeyVaultExtensions.Tests.csproj deleted file mode 100644 index 3c797af7a1..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Microsoft.IdentityModel.KeyVaultExtensions.Tests.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - Microsoft.IdentityModel.KeyVaultExtensions.Tests - $(MSBuildThisFileDirectory)..\..\build\35MSSharedLib1024.snk - true - Tests for Microsoft.IdentityModel.KeyVaultExtensions - true - Microsoft.IdentityModel.KeyVaultExtensions.Tests - true - - - - - - - - - - - - diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/MockKeyVaultClient.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/MockKeyVaultClient.cs deleted file mode 100644 index 8fcbc31691..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/MockKeyVaultClient.cs +++ /dev/null @@ -1,622 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Azure.KeyVault; -using Microsoft.Azure.KeyVault.Models; -using Microsoft.IdentityModel.TestUtils; -using Microsoft.IdentityModel.Tokens; -using Microsoft.Rest; -using Microsoft.Rest.Azure; -using Newtonsoft.Json; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - [CLSCompliant(false)] - public class MockKeyVaultClient : IKeyVaultClient - { - private readonly Microsoft.Azure.KeyVault.WebKey.JsonWebKey _key; - private readonly RSACryptoServiceProvider _rsa; - private bool _disposed = false; - - public MockKeyVaultClient() - { - _rsa = new RSACryptoServiceProvider(); - _rsa.ImportParameters(KeyingMaterial.RsaParameters_2048); - _key = new Microsoft.Azure.KeyVault.WebKey.JsonWebKey(_rsa, includePrivateParameters: false); - } - - public int ExpectedKeyWrapLength => 256; - - public int ExpectedSignatureLength => 256; - - public JsonSerializerSettings SerializationSettings => throw new NotImplementedException(); - - public JsonSerializerSettings DeserializationSettings => throw new NotImplementedException(); - - public ServiceClientCredentials Credentials => throw new NotImplementedException(); - - public string ApiVersion => throw new NotImplementedException(); - - public string AcceptLanguage { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public int? LongRunningOperationRetryTimeout { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public bool? GenerateClientRequestId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public Task> BackupCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> BackupKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> BackupSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> BackupStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> CreateCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, CertificatePolicy certificatePolicy = null, CertificateAttributes certificateAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> CreateKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string kty, int? keySize = null, IList keyOps = null, KeyAttributes keyAttributes = null, IDictionary tags = null, string curve = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DecryptWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] value, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteCertificateContactsWithHttpMessagesAsync(string vaultBaseUrl, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteCertificateIssuerWithHttpMessagesAsync(string vaultBaseUrl, string issuerName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteCertificateOperationWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> DeleteStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - /// - /// Calls and - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - _disposed = true; - if (disposing) - { - _rsa.Dispose(); - } - } - } - - public Task> EncryptWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] value, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetCertificateContactsWithHttpMessagesAsync(string vaultBaseUrl, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificateIssuersNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificateIssuersWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetCertificateIssuerWithHttpMessagesAsync(string vaultBaseUrl, string issuerName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetCertificateOperationWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetCertificatePolicyWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificatesNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificatesWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, bool? includePending = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificateVersionsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetCertificateVersionsWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, string certificateVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedCertificatesNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedCertificatesWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, bool? includePending = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetDeletedCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedKeysNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedKeysWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetDeletedKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedSasDefinitionsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedSasDefinitionsWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetDeletedSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedSecretsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedSecretsWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetDeletedSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedStorageAccountsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetDeletedStorageAccountsWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetDeletedStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetKeysNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetKeysWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetKeyVersionsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetKeyVersionsWithHttpMessagesAsync(string vaultBaseUrl, string keyName, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - _key.Kid = GetKeyIdentifier(vaultBaseUrl, keyName, keyVersion); - KeyAttributes attributes = new KeyAttributes(enabled: true); - var response = new AzureOperationResponse - { - Body = new KeyBundle(_key, attributes), - }; - - return Task.FromResult(response); - } - - public Task> GetPendingCertificateSigningRequestWithHttpMessagesAsync(string vault, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSasDefinitionsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSasDefinitionsWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSecretsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSecretsWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSecretVersionsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetSecretVersionsWithHttpMessagesAsync(string vaultBaseUrl, string secretName, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, string secretVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetStorageAccountsNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task>> GetStorageAccountsWithHttpMessagesAsync(string vaultBaseUrl, int? maxresults = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> GetStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> ImportCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, string base64EncodedCertificate, string password = null, CertificatePolicy certificatePolicy = null, CertificateAttributes certificateAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> ImportKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Microsoft.Azure.KeyVault.WebKey.JsonWebKey key, bool? hsm = null, KeyAttributes keyAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> MergeCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, IList x509Certificates, CertificateAttributes certificateAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task PurgeDeletedCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task PurgeDeletedKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task PurgeDeletedSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task PurgeDeletedStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RecoverDeletedCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RecoverDeletedKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RecoverDeletedSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RecoverDeletedSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RecoverDeletedStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RegenerateStorageAccountKeyWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string keyName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RestoreCertificateWithHttpMessagesAsync(string vaultBaseUrl, byte[] certificateBundleBackup, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RestoreKeyWithHttpMessagesAsync(string vaultBaseUrl, byte[] keyBundleBackup, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RestoreSecretWithHttpMessagesAsync(string vaultBaseUrl, byte[] secretBundleBackup, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> RestoreStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, byte[] storageBundleBackup, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SetCertificateContactsWithHttpMessagesAsync(string vaultBaseUrl, Contacts contacts, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SetCertificateIssuerWithHttpMessagesAsync(string vaultBaseUrl, string issuerName, string provider, IssuerCredentials credentials = null, OrganizationDetails organizationDetails = null, IssuerAttributes attributes = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SetSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, string templateUri, string sasType, string validityPeriod, SasDefinitionAttributes sasDefinitionAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SetSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, string value, IDictionary tags = null, string contentType = null, SecretAttributes secretAttributes = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SetStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string resourceId, string activeKeyName, bool autoRegenerateKey, string regenerationPeriod = null, StorageAccountAttributes storageAccountAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> SignWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] value, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - string digestAlgorithm; - switch (algorithm) - { - case SecurityAlgorithms.RsaSha256: - digestAlgorithm = SecurityAlgorithms.Sha256; - break; - case SecurityAlgorithms.RsaSha384: - digestAlgorithm = SecurityAlgorithms.Sha384; - break; - case SecurityAlgorithms.RsaSha512: - digestAlgorithm = SecurityAlgorithms.Sha512; - break; - default: - throw new NotImplementedException(); - } - - var result = _rsa.SignHash(value, digestAlgorithm); - var response = new AzureOperationResponse - { - Body = new KeyOperationResult(GetKeyIdentifier(vaultBaseUrl, keyName, keyVersion), result), - }; - - return Task.FromResult(response); - } - - public Task> UnwrapKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] value, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - bool fOAEP; - if (StringComparer.OrdinalIgnoreCase.Equals(algorithm, SecurityAlgorithms.RsaOAEP)) - fOAEP = true; - else if (StringComparer.OrdinalIgnoreCase.Equals(algorithm, SecurityAlgorithms.RsaPKCS1)) - fOAEP = false; - else - throw new NotImplementedException($"The mock key vault is not configured to unwrap keys using the {algorithm} security algorithm."); - - var result = _rsa.Decrypt(value, fOAEP); - var response = new AzureOperationResponse - { - Body = new KeyOperationResult(GetKeyIdentifier(vaultBaseUrl, keyName, keyVersion), result), - }; - - return Task.FromResult(response); - } - - public Task> UpdateCertificateIssuerWithHttpMessagesAsync(string vaultBaseUrl, string issuerName, string provider = null, IssuerCredentials credentials = null, OrganizationDetails organizationDetails = null, IssuerAttributes attributes = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateCertificateOperationWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, bool cancellationRequested, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateCertificatePolicyWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, CertificatePolicy certificatePolicy, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateCertificateWithHttpMessagesAsync(string vaultBaseUrl, string certificateName, string certificateVersion, CertificatePolicy certificatePolicy = null, CertificateAttributes certificateAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, IList keyOps = null, KeyAttributes keyAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateSasDefinitionWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string sasDefinitionName, string templateUri = null, string sasType = null, string validityPeriod = null, SasDefinitionAttributes sasDefinitionAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateSecretWithHttpMessagesAsync(string vaultBaseUrl, string secretName, string secretVersion, string contentType = null, SecretAttributes secretAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> UpdateStorageAccountWithHttpMessagesAsync(string vaultBaseUrl, string storageAccountName, string activeKeyName = null, bool? autoRegenerateKey = null, string regenerationPeriod = null, StorageAccountAttributes storageAccountAttributes = null, IDictionary tags = null, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task> VerifyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] digest, byte[] signature, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - string digestAlgorithm; - switch (algorithm) - { - case SecurityAlgorithms.RsaSha256: - digestAlgorithm = SecurityAlgorithms.Sha256; - break; - case SecurityAlgorithms.RsaSha384: - digestAlgorithm = SecurityAlgorithms.Sha384; - break; - case SecurityAlgorithms.RsaSha512: - digestAlgorithm = SecurityAlgorithms.Sha512; - break; - default: - digestAlgorithm = null; - break; - } - - var result = string.IsNullOrEmpty(digestAlgorithm) ? null : (bool?)_rsa.VerifyHash(digest, digestAlgorithm, signature); - var response = new AzureOperationResponse - { - Body = new KeyVerifyResult(result), - }; - - return Task.FromResult(response); - } - - public Task> WrapKeyWithHttpMessagesAsync(string vaultBaseUrl, string keyName, string keyVersion, string algorithm, byte[] value, Dictionary> customHeaders = null, CancellationToken cancellationToken = default) - { - bool fOAEP; - if (StringComparer.OrdinalIgnoreCase.Equals(algorithm, SecurityAlgorithms.RsaOAEP)) - fOAEP = true; - else if (StringComparer.OrdinalIgnoreCase.Equals(algorithm, SecurityAlgorithms.RsaPKCS1)) - fOAEP = false; - else - throw new NotImplementedException($"The mock key vault is not configured to wrap keys using the {algorithm} security algorithm."); - - var response = new AzureOperationResponse - { - Body = new KeyOperationResult(GetKeyIdentifier(vaultBaseUrl, keyName, keyVersion), _rsa.Encrypt(value, fOAEP)), - }; - - return Task.FromResult(response); - } - - private string GetKeyIdentifier(string vaultBaseUrl, string keyName, string keyVersion) - { - return new Uri(new Uri(vaultBaseUrl), $"/keys/{keyName}/{keyVersion}").ToString(); - } - } -} - diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index b6a9bad9cd..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: CLSCompliant(false)] -[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] -[assembly: ComVisible(false)] - diff --git a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/SignatureProviderTheoryData.cs b/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/SignatureProviderTheoryData.cs deleted file mode 100644 index 212a8656ed..0000000000 --- a/test/Microsoft.IdentityModel.KeyVaultExtensions.Tests/SignatureProviderTheoryData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.IdentityModel.TestUtils; - -namespace Microsoft.IdentityModel.KeyVaultExtensions.Tests -{ - public class SignatureProviderTheoryData : TheoryDataBase - { - public string Algorithm { get; set; } - } -} diff --git a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/KeyVaultSecurityKeyTests.cs b/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/KeyVaultSecurityKeyTests.cs deleted file mode 100644 index d7c3d41dc6..0000000000 --- a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/KeyVaultSecurityKeyTests.cs +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Azure.KeyVault.Models; -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using Microsoft.IdentityModel.KeyVaultExtensions; -using Microsoft.IdentityModel.KeyVaultExtensions.Tests; -using Microsoft.IdentityModel.TestUtils; -using System; -using System.Reflection; -using Xunit; - -#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant - -namespace Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests -{ - public class KeyVaultSecurityKeyTests - { - private static ExpectedException AdalServiceExceptionExpected = new ExpectedException(typeExpected: typeof(TargetInvocationException), substringExpected: "Exception has been thrown by the target of an invocation.", innerTypeExpected: typeof(AdalServiceException)); - private static ExpectedException ArgumentNullExceptionExpected = new ExpectedException(typeExpected: typeof(TargetInvocationException), substringExpected: "Exception has been thrown by the target of an invocation.", innerTypeExpected: typeof(ArgumentNullException)); - private static ExpectedException KeyVaultErrorExceptionExpected = new ExpectedException(typeExpected: typeof(TargetInvocationException), substringExpected: "Exception has been thrown by the target of an invocation.", innerTypeExpected: typeof(KeyVaultErrorException)); - - [Theory, MemberData(nameof(KeyVaultSecurityKeyConfidentialClientTheoryData))] - public void ConfidentialClientConstructorParams(KeyVaultSecurityKeyConfidentialClientTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.ConfidentialClientConstructorParams", theoryData); - - try - { - _ = Activator.CreateInstance(theoryData.Type, new object[] { theoryData.KeyIdentifier, theoryData.ClientId, theoryData.ClientSecret }); - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception ex) - { - theoryData.ExpectedException.ProcessException(ex, context); - } - - TestUtilities.AssertFailIfErrors(context); - } - - public static TheoryData KeyVaultSecurityKeyConfidentialClientTheoryData - { - get => new TheoryData - { - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - // ClientId = default, - // ClientSecret = default, - ExpectedException = ArgumentNullExceptionExpected, - First = true, - KeyIdentifier = null, - TestId = "Test1", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - // ClientId = default, - // ClientSecret = default, - ExpectedException = ArgumentNullExceptionExpected, - KeyIdentifier = string.Empty, - TestId = "Test2", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - ClientId = null, - // ClientSecret = default, - ExpectedException = ArgumentNullExceptionExpected, - // KeyIdentifier = default, - TestId = "Test3", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - ClientId = string.Empty, - /* - ClientSecret = default, - */ - ExpectedException = ArgumentNullExceptionExpected, - // KeyIdentifier = default, - TestId = "Test4", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - // ClientId = default, - ClientSecret = null, - ExpectedException = ArgumentNullExceptionExpected, - // KeyIdentifier = default, - TestId = "Test5", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - // ClientId = default, - ClientSecret = string.Empty, - ExpectedException = ArgumentNullExceptionExpected, - // KeyIdentifier = default, - TestId = "Test6", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyConfidentialClientTheoryData - { - // ClientId = default, - // ClientSecret = default, - // KeyIdentifier = default, - TestId = "Test7", - Type = typeof(ManagedKeyVaultSecurityKey), - } - }; - } - - [Theory, MemberData(nameof(KeyVaultSecurityKeyManagedServiceIdentityTheoryData))] - public void ManagedServiceIdentityConstructorParams(KeyVaultSecurityKeyTheoryData theoryData) - { - var context = TestUtilities.WriteHeader($"{this}.ManagedServiceIdentityConstructorParams", theoryData); - - try - { - _ = Activator.CreateInstance(theoryData.Type, new object[] { theoryData.KeyIdentifier }); - theoryData.ExpectedException.ProcessNoException(context); - } - catch (Exception ex) - { - theoryData.ExpectedException.ProcessException(ex, context); - } - } - - public static TheoryData KeyVaultSecurityKeyManagedServiceIdentityTheoryData - { - get => new TheoryData - { - new KeyVaultSecurityKeyManagedServiceIdentityTheoryData - { - ExpectedException = ExpectedException.ArgumentNullException(), - First = true, - KeyIdentifier = null, - TestId = "Test1", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyManagedServiceIdentityTheoryData - { - ExpectedException = ExpectedException.ArgumentNullException(), - KeyIdentifier = string.Empty, - TestId = "Test2", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - new KeyVaultSecurityKeyManagedServiceIdentityTheoryData - { - ExpectedException = KeyVaultErrorExceptionExpected, - // KeyIdentifier = default, - TestId = "Test3", - Type = typeof(ManagedKeyVaultSecurityKey), - }, - }; - } - } -} - -#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant diff --git a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests.csproj b/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests.csproj deleted file mode 100644 index d372f245e9..0000000000 --- a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests - $(MSBuildThisFileDirectory)..\..\build\35MSSharedLib1024.snk - true - Tests for Microsoft.IdentityModel.ManagedKeyVaultSecurityKey - true - Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests - true - - - - - - - - - - - - - diff --git a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index b6a9bad9cd..0000000000 --- a/test/Microsoft.IdentityModel.ManagedKeyVaultSecurityKey.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: CLSCompliant(false)] -[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] -[assembly: ComVisible(false)] - diff --git a/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs b/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs index f4580dba31..1590981f36 100644 --- a/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs +++ b/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs @@ -303,7 +303,7 @@ public DerivedSecurityKey(string keyId, int keySize) _keySize = keySize; } - internal override string InternalId { get =>_keyId; } + internal override string InternalId { get => _keyId; } public Exception ThrowOnGetKeyId { get; set; } diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Microsoft.IdentityModel.Tokens.Tests.csproj b/test/Microsoft.IdentityModel.Tokens.Tests/Microsoft.IdentityModel.Tokens.Tests.csproj index 571c3cdde6..1457cc8bd1 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Microsoft.IdentityModel.Tokens.Tests.csproj +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Microsoft.IdentityModel.Tokens.Tests.csproj @@ -13,7 +13,6 @@ - diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/SecurityKeyTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/SecurityKeyTests.cs index b2c606189f..d11ad7c75b 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/SecurityKeyTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/SecurityKeyTests.cs @@ -14,11 +14,8 @@ public class SecurityKeyTests [Fact] public void ComputeJwkThumbprint() { - var exception = Assert.Throws(() => new ManagedKeyVaultSecurityKey.ManagedKeyVaultSecurityKey("keyid").ComputeJwkThumbprint()); - Assert.Contains("IDX10710", exception.Message); - #if NET461 || NET462 - exception = Assert.Throws(() => new ECDsaSecurityKey(KeyingMaterial.JsonWebKeyP256, false).ComputeJwkThumbprint()); + var exception = Assert.Throws(() => new ECDsaSecurityKey(KeyingMaterial.JsonWebKeyP256, false).ComputeJwkThumbprint()); Assert.Contains("IDX10695", exception.Message); #else var ex = Record.Exception(() => new ECDsaSecurityKey(KeyingMaterial.JsonWebKeyP256, false).ComputeJwkThumbprint()); diff --git a/test/System.IdentityModel.Tokens.Jwt.Tests/JwtSecurityTokenHandlerTests.cs b/test/System.IdentityModel.Tokens.Jwt.Tests/JwtSecurityTokenHandlerTests.cs index ea2c58a738..9400e6770a 100644 --- a/test/System.IdentityModel.Tokens.Jwt.Tests/JwtSecurityTokenHandlerTests.cs +++ b/test/System.IdentityModel.Tokens.Jwt.Tests/JwtSecurityTokenHandlerTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.IdentityModel.JsonWebTokens; diff --git a/test/System.IdentityModel.Tokens.Jwt.Tests/JwtTestDatasets.cs b/test/System.IdentityModel.Tokens.Jwt.Tests/JwtTestDatasets.cs index 64344d495b..4de6f67bce 100644 --- a/test/System.IdentityModel.Tokens.Jwt.Tests/JwtTestDatasets.cs +++ b/test/System.IdentityModel.Tokens.Jwt.Tests/JwtTestDatasets.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using System.IO; using System.Net; +using System.Net.Http; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; diff --git a/test/System.IdentityModel.Tokens.Jwt.Tests/System.IdentityModel.Tokens.Jwt.Tests.csproj b/test/System.IdentityModel.Tokens.Jwt.Tests/System.IdentityModel.Tokens.Jwt.Tests.csproj index 5ff3cf0408..b0ec53c7af 100644 --- a/test/System.IdentityModel.Tokens.Jwt.Tests/System.IdentityModel.Tokens.Jwt.Tests.csproj +++ b/test/System.IdentityModel.Tokens.Jwt.Tests/System.IdentityModel.Tokens.Jwt.Tests.csproj @@ -19,6 +19,10 @@ + + + +