-
Notifications
You must be signed in to change notification settings - Fork 52
Add key revocation checks, for credentials creation #546
Conversation
Codecov Report
@@ Coverage Diff @@
## main #546 +/- ##
==========================================
+ Coverage 23.98% 24.19% +0.21%
==========================================
Files 46 46
Lines 5119 5120 +1
==========================================
+ Hits 1228 1239 +11
+ Misses 3663 3650 -13
- Partials 228 231 +3
|
At this point I wonder if the proposed approach (using credential creation as example) is good enough. If yes, I will implement the check in other similar places, e.g. schema creation. A potential alternative is to move the revocation check inside |
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.
This is an improvement, but I'm torn on whether we should support a generic "state" vs a specific revoked
field, which is a boolean.
After seeing the APIs for a couple of KMS providers, I noticed that's the approach they took.
pkg/service/keystore/service_test.go
Outdated
assert.NotEmpty(t, keyResponse) | ||
assert.Equal(t, privKey, keyResponse.Key) | ||
assert.Equal(t, true, keyResponse.Revoked) | ||
assert.NotEmpty(t, keyResponse.RevokedAt) |
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.
I think it makes sense to test the value here as well. You can do so by injecting a clock instance to the service.
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.
I have tried to do it, but stopped after discovering that the keystore service does not use Clock
, it uses time.Now()
instead. I noticed that all other services also use time.Now()
with the only exception being the manifest service that uses Clock
. However, the Clock module is unmaintained. Are you sure?
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.
Thanks for pointing out that Clock is now archived. I wasn't aware of that! That said, I think it's still a good approach so that times are tested.
I'm make a ticket to clean up other places that use time.Now()
.
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.
Could you elaborate on how the times should be tested within this PR specifically?
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.
Following the same pattern as manifest service.
- Create a field of type
Clock
in theService
struct. - Set that instance in the constructor by calling clock.New()
- In this test, override the field by setting up a mock clock
keyStore.Clock = mockClock
. - Assert that the time in the mock clock is the same as the
RevokedAt
time.
This will need a little bit of refactoring of the Storage.RevokeKey
method, but that's ok. The code will look much better.
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.
Thanks, updated.
…ation endpoint, tests
Thank you! |
I believe that all necessary changes have been addressed. Please let me know if there's anything else I need to do before this can be merged. Next, I will implement the revocation check in other places. |
@decentralgabe PTAL |
Overview
Add key revocation check when creating a credential, expose key revocation endpoint.
Description
How Has This Been Tested?
Manual test:
controller
be ID of the DID."error": "could not create credential: execute: failed to execute after retrying: signing credential: cannot use revoked key<MyKeyID>"
The above steps has been automated within
pkg/server/router/credential_test.go
file.Also, a unit test added to
pkg/service/keystore/service_test.go
.Checklist
Before submitting this PR, please make sure:
References
Related to #451 .