-
Notifications
You must be signed in to change notification settings - Fork 170
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
extras: Provide initializers for RSA keys from RSA parameters #247
extras: Provide initializers for RSA keys from RSA parameters #247
Conversation
945d5dc
to
cc4f80f
Compare
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 the feedback @Lukasa. I think this is ready for another pass 🙏
cc4f80f
to
09a8cc3
Compare
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.
Very nice, just a little note.
cc @ptoffy since we've implemented that ourselves in JWTKit - we should either wait for this or ensure our APIs are internal so we can switch over without an API break |
@0xTim we have our own key wrapping SwiftCrypto's so we should be fine. We can switch to this without breaking anything |
09a8cc3
to
7690a99
Compare
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, looks good to me, minus the inlinable thing.
/// | ||
/// On Darwin platforms, this will serialize it to PEM format, and then construct a platform-specific key from | ||
/// the PEM representation. | ||
public init(n: some ContiguousBytes, e: some ContiguousBytes) throws { |
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.
Generalised nit: @inlinable
on generic methods, as far as possible. This feedback applies to any new generic function or type.
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.
FWICT there is a very deliberate use of private
for the backing key types and fileprivate
for the type aliases which is why existing generic initialisers are not currently inlinable either (e.g. the PEM and DER initialisers).
I think we'd probably need to take a wider view to achieve this so should we defer this to a future PR?
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.
Sounds good.
@swift-server-bot test this please |
Motivation
We currently offer APIs to construct RSA keys from PEM and DER representations but we have no way of constructing they key from its constituent RSA parameters: n and e for public keys, and n, e, d, p, and q for private keys. Sometimes these are what you have to hand, e.g. in a JSON Web Key.
Modifications
Provide initializers for RSA keys from RSA parameters for all the RSA key types.
To implement this, we leverage the fact that we are making use of BoringSSL in
_CryptoExtras
on all platforms. We need this because there are no APIs to construct the underlying key type on Darwin platforms from these parameters. So we do this by first creating a BoringSSL key, serializing it to PEM format, and then constructing a platform-specific key from the PEM representation.Result
New APIs to construct RSA keys from RSA parameters.