mirror of
https://github.com/DuendeSoftware/products
synced 2026-05-24 09:28:24 +00:00
Make CT required in IValidationKeysStore, ISigningCredentialStore, IAutomaticKeyManagerKeyStore, eliminating default stopgaps in DefaultKeyMaterialService and AutomaticKeyManagerKeyStore
This commit is contained in:
parent
65f3adcd57
commit
907e07f618
6 changed files with 23 additions and 20 deletions
|
|
@ -46,14 +46,14 @@ public class DefaultKeyMaterialService : IKeyMaterialService
|
|||
var list = _signingCredentialStores.ToList();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var key = await list[i].GetSigningCredentialsAsync();
|
||||
var key = await list[i].GetSigningCredentialsAsync(ct);
|
||||
if (key != null)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
var automaticKey = await _keyManagerKeyStore.GetSigningCredentialsAsync();
|
||||
var automaticKey = await _keyManagerKeyStore.GetSigningCredentialsAsync(ct);
|
||||
if (automaticKey != null)
|
||||
{
|
||||
return automaticKey;
|
||||
|
|
@ -82,14 +82,14 @@ public class DefaultKeyMaterialService : IKeyMaterialService
|
|||
|
||||
foreach (var store in _signingCredentialStores)
|
||||
{
|
||||
var signingKey = await store.GetSigningCredentialsAsync();
|
||||
var signingKey = await store.GetSigningCredentialsAsync(ct);
|
||||
if (signingKey != null)
|
||||
{
|
||||
credentials.Add(signingKey);
|
||||
}
|
||||
}
|
||||
|
||||
var automaticSigningKeys = await _keyManagerKeyStore.GetAllSigningCredentialsAsync();
|
||||
var automaticSigningKeys = await _keyManagerKeyStore.GetAllSigningCredentialsAsync(ct);
|
||||
if (automaticSigningKeys != null)
|
||||
{
|
||||
credentials.AddRange(automaticSigningKeys);
|
||||
|
|
@ -105,7 +105,7 @@ public class DefaultKeyMaterialService : IKeyMaterialService
|
|||
|
||||
var keys = new List<SecurityKeyInfo>();
|
||||
|
||||
var automaticSigningKeys = await _keyManagerKeyStore.GetValidationKeysAsync();
|
||||
var automaticSigningKeys = await _keyManagerKeyStore.GetValidationKeysAsync(ct);
|
||||
if (automaticSigningKeys?.Any() == true)
|
||||
{
|
||||
keys.AddRange(automaticSigningKeys);
|
||||
|
|
@ -113,7 +113,7 @@ public class DefaultKeyMaterialService : IKeyMaterialService
|
|||
|
||||
foreach (var store in _validationKeysStores)
|
||||
{
|
||||
var validationKeys = await store.GetValidationKeysAsync();
|
||||
var validationKeys = await store.GetValidationKeysAsync(ct);
|
||||
keys.AddRange(validationKeys);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ public interface IAutomaticKeyManagerKeyStore : IValidationKeysStore, ISigningCr
|
|||
/// <summary>
|
||||
/// Gets all the signing credentials.
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync();
|
||||
Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync(CT ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -27,13 +28,13 @@ public interface IAutomaticKeyManagerKeyStore : IValidationKeysStore, ISigningCr
|
|||
internal class NopAutomaticKeyManagerKeyStore : IAutomaticKeyManagerKeyStore
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public Task<SigningCredentials> GetSigningCredentialsAsync() => Task.FromResult<SigningCredentials>(null);
|
||||
public Task<SigningCredentials> GetSigningCredentialsAsync(CT ct) => Task.FromResult<SigningCredentials>(null);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync() => Task.FromResult(Enumerable.Empty<SigningCredentials>());
|
||||
public Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync(CT ct) => Task.FromResult(Enumerable.Empty<SigningCredentials>());
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync() => Task.FromResult(Enumerable.Empty<SecurityKeyInfo>());
|
||||
public Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync(CT ct) => Task.FromResult(Enumerable.Empty<SecurityKeyInfo>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -56,41 +57,41 @@ public class AutomaticKeyManagerKeyStore : IAutomaticKeyManagerKeyStore
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<SigningCredentials> GetSigningCredentialsAsync()
|
||||
public async Task<SigningCredentials> GetSigningCredentialsAsync(CT ct)
|
||||
{
|
||||
if (!_options.Enabled)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var credentials = await GetAllSigningCredentialsAsync();
|
||||
var credentials = await GetAllSigningCredentialsAsync(ct);
|
||||
var alg = _options.DefaultSigningAlgorithm;
|
||||
var credential = credentials.FirstOrDefault(x => alg == x.Algorithm);
|
||||
return credential;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync()
|
||||
public async Task<IEnumerable<SigningCredentials>> GetAllSigningCredentialsAsync(CT ct)
|
||||
{
|
||||
if (!_options.Enabled)
|
||||
{
|
||||
return Enumerable.Empty<SigningCredentials>();
|
||||
}
|
||||
|
||||
var keyContainers = await _keyManager.GetCurrentKeysAsync(default);
|
||||
var keyContainers = await _keyManager.GetCurrentKeysAsync(ct);
|
||||
var credentials = keyContainers.Select(x => new SigningCredentials(x.ToSecurityKey(), x.Algorithm));
|
||||
return credentials;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync()
|
||||
public async Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync(CT ct)
|
||||
{
|
||||
if (!_options.Enabled)
|
||||
{
|
||||
return Enumerable.Empty<SecurityKeyInfo>();
|
||||
}
|
||||
|
||||
var containers = await _keyManager.GetAllKeysAsync(default);
|
||||
var containers = await _keyManager.GetAllKeysAsync(ct);
|
||||
var keys = containers.Select(x => new SecurityKeyInfo
|
||||
{
|
||||
Key = x.ToSecurityKey(),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public interface ISigningCredentialStore
|
|||
/// <summary>
|
||||
/// Gets the signing credentials.
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
Task<SigningCredentials> GetSigningCredentialsAsync();
|
||||
Task<SigningCredentials> GetSigningCredentialsAsync(CT ct);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public interface IValidationKeysStore
|
|||
/// <summary>
|
||||
/// Gets all validation keys.
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync();
|
||||
Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync(CT ct);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class InMemorySigningCredentialsStore : ISigningCredentialStore
|
|||
/// Gets the signing credentials.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<SigningCredentials> GetSigningCredentialsAsync()
|
||||
public Task<SigningCredentials> GetSigningCredentialsAsync(CT ct)
|
||||
{
|
||||
using var activity = Tracing.StoreActivitySource.StartActivity("InMemorySigningCredentialsStore.GetSigningCredentials");
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class InMemoryValidationKeysStore : IValidationKeysStore
|
|||
/// Gets all validation keys.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync()
|
||||
public Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync(CT ct)
|
||||
{
|
||||
using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryValidationKeysStore.GetValidationKeys");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue