Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for CYOK end-points #744

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Auth0.ManagementApi/Clients/IKeysClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ public interface IKeysClient
/// <param name="request"><see cref="WrappingKeyCreateRequest"/></param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
Task<WrappingKey> CreatePublicWrappingKeyAsync(WrappingKeyCreateRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Perform rekeying operation on the key hierarchy.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
Task RekeyAsync(CancellationToken cancellationToken = default);
}
}
13 changes: 12 additions & 1 deletion src/Auth0.ManagementApi/Clients/KeysClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,24 @@ public Task<WrappingKey> CreatePublicWrappingKeyAsync(

if (string.IsNullOrEmpty(request.Kid))
throw new ArgumentNullException(nameof(request.Kid));

return Connection.SendAsync<WrappingKey>(
HttpMethod.Post,
BuildUri($"keys/encryption/{EncodePath(request.Kid)}/wrapping-key"),
body: null,
headers: DefaultHeaders,
cancellationToken: cancellationToken);
}

/// <inheritdoc cref="IKeysClient.RekeyAsync"/>
public Task RekeyAsync(CancellationToken cancellationToken = default)
{
return Connection.SendAsync<object>(
HttpMethod.Post,
BuildUri("keys/encryption/rekey"),
body: null,
headers: DefaultHeaders,
cancellationToken: cancellationToken);
}
}
}
36 changes: 36 additions & 0 deletions tests/Auth0.ManagementApi.IntegrationTests/KeysTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,41 @@ public async void Test_import_encrypted_keys()
importedKeys.Type.Should().Be(EncryptionKeyType.CustomerProvidedRootKey);
importedKeys.ParentKid.Should().Be("a20128c5-9bf5-4209-8c43-b6dfcee60e9b");
}

[Fact]
public async void Test_rekey_encrypted_keys()
{
// Get the existing Tenant Master Key
var existingTenantMasterKey = await GetExistingTenantMasterKey();

await fixture.ApiClient.Keys.RekeyAsync();

var newTenantMasterKey = await GetExistingTenantMasterKey();

// After rekey operation, a new Tenant Master Key should be generated
existingTenantMasterKey.Should().NotBeEquivalentTo(newTenantMasterKey);

var existingTenantMasterKeyAfterRekey =
await fixture.ApiClient.Keys.GetEncryptionKeyAsync(
new EncryptionKeyGetRequest()
{
Kid = existingTenantMasterKey.Kid
}
);

// Confirming that the old master key is destroyed
existingTenantMasterKeyAfterRekey.State.Should().Be(EncryptionKeyState.Destroyed);
}

private async Task<EncryptionKey> GetExistingTenantMasterKey()
{
var existingEncryptionKeys = await fixture.ApiClient.Keys.GetAllEncryptionKeysAsync(new PaginationInfo());

// Get the existing Tenant Master Key
var existingTenantMasterKey =
existingEncryptionKeys.FirstOrDefault(x => x.State == EncryptionKeyState.Active &&
x.Type == EncryptionKeyType.TenantMasterKey);
return existingTenantMasterKey;
}
}
}
Loading