-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Updated CryptographyClientImpl to return a versioned keyId where applicable
#47822
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes Key Vault cryptography operation results to return the service-returned (versioned) key identifier (kid) instead of the client’s (potentially unversioned) keyId, enabling correct roundtrip scenarios when key rotation is used (e.g., sign→verify, wrap→unwrap).
Changes:
- Updated
EncryptResultto useKeyOperationResult.getKid()forkeyId. - Updated
DecryptResultto useKeyOperationResult.getKid()forkeyId. - Updated
SignResult,WrapResult, andUnwrapResultto useKeyOperationResult.getKid()forkeyId.
...ava/com/azure/security/keyvault/keys/cryptography/implementation/CryptographyClientImpl.java
Show resolved
Hide resolved
...ava/com/azure/security/keyvault/keys/cryptography/implementation/CryptographyClientImpl.java
Show resolved
Hide resolved
heaths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given your changelog entry, this would seem right but without seeing any tests or knowing your code from memory, does getKid() return the full URI including version? Might be good to add a test or even an assertion to existing tests to make sure you do indeed have a version.
|
@heaths Added a few more check to our unit tests, including one for kid version |
| // Ensure the keyId includes the key version | ||
| String[] keyIdParts = keyId.split("/"); | ||
|
|
||
| assertTrue(keyIdParts.length >= 5 && !keyIdParts[4].isEmpty(), "keyId does not contain key version."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this works, but don't you have an ID parser like we added to all other languages? Might be nice to use that for maintainability so it's obvious that the version is being checked: parse it into its components, and check a version local. Just a suggestion. Non-blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right! I forgot we had that. Thanks for reminding me :)
Description
Fixes: #43451
Fixed an issue where cryptographic operation results (
SignResult,EncryptResult,DecryptResult,WrapResult,UnwrapResult) returned a versionless key ID instead of the full versioned key ID returned by the service. This caused issues when attempting roundtrip scenarios, as callers couldn't determine which key version was used for the original operation (e.g. Sign -> Verify).All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines