Skip to content
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

Add callback-based custom private keys. #322

Merged
merged 1 commit into from
Sep 21, 2021

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Sep 20, 2021

Motivation:

NIOSSL traditionally handles private keys be requiring that they can be
decoded into a BoringSSL EVP_PKEY structure. This requires the key to
have an in-memory representation that BoringSSL understands, and
ultimately forces the bytes of the private key into memory.

In many cases, however, this is either undesirable or not possible.
For security reasons it is common to want to offload a private key into
secure storage, such as the iPhone's Secure Enclave or a portable smart
card. In other circumstances it may be useful to put the private key on
an entirely different machine and have the signing operations occur over
an RPC mechanism.

In all of these cases it is necessary to have a programmatic interface
to the private key that can be implemented in an essentially arbitrary
manner.

Modifications:

  • Defined a new protocol, NIOSSLCustomPrivateKey, that allows users to
    implement the private key operations needed for TLS.
  • Plumbed support for this interface through NIOSSLPrivateKey.
  • Added support for the BoringSSL interface to SSLConnection.

Result:

Custom TLS private keys backed by function calls can now be provided to
NIOSSL.

@Lukasa Lukasa added the semver/minor Adds new public API. label Sep 20, 2021
@Lukasa Lukasa linked an issue Sep 20, 2021 that may be closed by this pull request
@Lukasa Lukasa force-pushed the cb-custom-callback-based-keys branch from dc8796f to a849681 Compare September 20, 2021 11:43
/// - customPrivateKey: The custom private key to use with the TLS certificate.
@inlinable
public init<CustomKey: NIOSSLCustomPrivateKey & Hashable>(customPrivateKey: CustomKey) {
self.representation = .custom(AnyNIOSSLCustomPrivateKey(customPrivateKey))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question; would this be the entry point for any key that is created outside the context of BoringSSL's EVP_PKEY type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Motivation:

NIOSSL traditionally handles private keys be requiring that they can be
decoded into a BoringSSL EVP_PKEY structure. This requires the key to
have an in-memory representation that BoringSSL understands, and
ultimately forces the bytes of the private key into memory.

In many cases, however, this is either undesirable or not possible.
For security reasons it is common to want to offload a private key into
secure storage, such as the iPhone's Secure Enclave or a portable smart
card. In other circumstances it may be useful to put the private key on
an entirely different machine and have the signing operations occur over
an RPC mechanism.

In all of these cases it is necessary to have a programmatic interface
to the private key that can be implemented in an essentially arbitrary
manner.

Modifications:

- Defined a new protocol, `NIOSSLCustomPrivateKey`, that allows users to
  implement the private key operations needed for TLS.
- Plumbed support for this interface through `NIOSSLPrivateKey`.
- Added support for the BoringSSL interface to `SSLConnection`.

Result:

Custom TLS private keys backed by function calls can now be provided to
NIOSSL.
Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to my very untrained eye.

@Lukasa Lukasa merged commit 70da47e into apple:main Sep 21, 2021
@Lukasa Lukasa deleted the cb-custom-callback-based-keys branch September 21, 2021 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How I can user secure enclave SecKey with nio-ssl?
3 participants