-
Notifications
You must be signed in to change notification settings - Fork 347
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
Accept crypto.Signer
that contains a ed25519.PublicKey
in ed25519
#95
Conversation
…her ed25519 providers than crypto/ed25519
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.
Thank you for you contribution! I am a bit sceptical about this though. I understand your specific use case, however accepting a generic crypto.Signer
could lead to situations where people insert the wrong kind of key into this function and we will never be able to catch it.
I fear that the "safer" way for you would probably be to register a custom signing method that does this specifically for the key struct/interface that you have or we could think about having a "generic" signing method that does accept any crypto.Signer
interface.
Golang does not provide a "good way" to check if a given signer is a RSA, ECDSA or Ed25519 key. One option would be to use Another option would be to add a "getTypeByObject" function that checks if the key is one of known types, and only accept either ed25519 or unknown keys (for advanced users), but reject common errors of for example someone putting a RSA key into a ed25519 signature. |
I think the issue, to start, is that the method name was not matching its exact semantics, because in fact it should be named |
I've looked at Go's own libraries since these work just fine and it turns out typically Go will detect the algorithm based on the public key, so that's probably an acceptable way of handling things. Ideally the key type shouldn't be passed and indeed be automatically detected based on the key itself as other go apis do, but in the meantime this is an update that makes jwt more generic without modifying existing APIs.
The only difference is that passing an invalid ed25519 key will now return a different kind of error, but that is probably a good thing as it helps differentiate between invalid ed25519 key and wrong key algorithm. I do think this should be modified in the future to remove the need of specifying the key algorithm. |
I think I could live with that solution. Could you maybe add a comment to the |
crypto.Signer
that contains a ed25519.PublicKey
in ed25519
Added a comment about |
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 from my side.
in order to allow usage of other ed25519 providers than crypto/ed25519
For example in my case I use a HSM (YubiHSM2), which means the private key is not visible to the go code (can't check its len, etc), however it is indeed a ed25519 key and the object provides the Sign() method
The HSM lib: https://github.com/KarpelesLab/hsm