-
Notifications
You must be signed in to change notification settings - Fork 109
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
Refactor keys to allow more key types and add RSA key verifier #148
Refactor keys to allow more key types and add RSA key verifier #148
Conversation
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Pull Request Test Coverage Report for Build 1221983175
💛 - Coveralls |
Signed-off-by: Asra Ali <[email protected]>
addressed some comments |
Signed-off-by: Asra Ali <[email protected]>
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.
Overall, I really like the generalized approach to key types and separating the interfaces for signing/verification accordingly.
My biggest question is around the structure of the Signer interface + implementing a signer struct for each key. Right now, it's not very flexible for generating signatures (or verifications) in a kms.
Ideally, I would like to use as much of the same code to create keys with go's crypto package and any type of external key gen system. Right now, I'm thinking that creating keys, signing, verifying, and getting public keys should all be interface methods of kms. I'm not too sure what the best approach is here, but I think making the Signer and Verifier more abstract or even changing how we store things in the Key Map would work.
Here's the general structure of what I was thinking for key management systems. Though I have to admit, I wasn't really writing this with the current way keys are generating in memory in mind :/
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 I am ok with this. I understand @d-niu's concerns about extending this API to abstract away things like where the signing operation is actually being done, but I think this can be fixed later.
Can you finish moving the files for keys under keys/ to pkg?
Hm I think Signer and Verify should be separate (although they can be the same object in the case of a KMS client). Looking at your code, the part that probably won't fit is the crypto.Signer operation, since I don't think KMS easily supports Edit: Wanna chat about the way things are stored in the Key Map? The Key Map is just meant to translate "type name" to an "empty type implementation". |
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
OK simplified the interface even more. |
GetVerifier as a method Edit: If you were looking at that test -- the purpose of |
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.
Happy to unblock this for now, we can refine API if need be later
Oh, one more thing: we need RSA support, no? |
Sounds good, we'll need to work how KMS signers will deal with |
I have a local follow-up PR! |
Who else should we have |
So, generating different types of keys, signing, and verifying in kms should not necessarily be under a separate kms interface. Instead, the connection to a kms client like hashicorp vault should be generated when you use a key from the key map and realize that it has some other attributes during UnmarshalKey, for instance. |
Maybe the constructors held in the map should have an |
For sure. Would context/params just hold something to indicate whether its locally generated or in a kms though? We probably won't store kms access tokens or paths in these params. |
Added RSA key implementation. |
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.
Great job! Started reviewing. Some minor comments so far.
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Signed-off-by: Asra Ali <[email protected]>
Fantastic work! |
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.
LGTM
Thank you both very much, @asraa and @hosseinsia! I would strongly encourage @joshuagl to review and approve to ensure there is no collusion 🙂 |
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.
Approving in order to unblock. Great work, Asra! 🎉
This PR added a dependency on github.com/pkg/errors. I've sent #166 to replace the dependency with standard library functions. |
…dateframework#148) * wip Signed-off-by: Asra Ali <[email protected]> * update for testing Signed-off-by: Asra Ali <[email protected]> * working Signed-off-by: Asra Ali <[email protected]> * address comments Signed-off-by: Asra Ali <[email protected]> * factor to helper Signed-off-by: Asra Ali <[email protected]> * simplify key interface Signed-off-by: Asra Ali <[email protected]> * move into pkg/ Signed-off-by: Asra Ali <[email protected]> * update impls Signed-off-by: Asra Ali <[email protected]> * remove empty block Signed-off-by: Asra Ali <[email protected]> * joshua suggestions Signed-off-by: Asra Ali <[email protected]> * add rsa key Signed-off-by: Asra Ali <[email protected]> * address comments Signed-off-by: Asra Ali <[email protected]> * update method name Signed-off-by: Asra Ali <[email protected]> * address preliminary comments Signed-off-by: Asra Ali <[email protected]> * address comments Signed-off-by: Asra Ali <[email protected]> * address comments Signed-off-by: Asra Ali <[email protected]> * add panic Signed-off-by: Asra Ali <[email protected]>
Local tests passes, still working on interop tests and double-checking for clean-up/small changes
This change makes it more friendly to add new keytypes:
data.Key
anddata.PrivateKey
representing the json data for public and private keysSigner
andVerifier
in the keys package that define conversions between the data formats and methods that are needed by the other modulesKeyMap
that registers a key type with the Signer/Verifier implementation. You don't need both to register in the key map (e.g. go-tuf only verifies ecdsa, does not support signing)Ah, another pain point: maybe there should be a file moving refactor so that the library code is in pkg/. these a keys/ package also conflicts with the keys/ folder that go-tuf creates for storing keys....