mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-24 04:38:08 +00:00
Motivation:
NIOCertificateReloading provides updated versions of a certificate and
private key pair, in the form of a NIOSSLContextConfigurationOverride,
to be used when performing a TLS handshake in NIO. Prior to this change,
the Swift customPrivateKey callback did not see the override. It always
read the private key from the immutable TLSConfiguration if one was
provided at initialization. This configuration might have been nil and
resulted in a precondition failure if the user was expecting to set the
key on the first reloader run. Otherwise, it would have contained a
stale key.
Modifications:
- Store the NIOSSLContextConfigurationOverride in SSLConnection when
applyOverride() is called.
- Update the customKey computed property to check the stored override
first and fall back to the parent context.
- Add tests:
- Server configuration sets a native key, reloader switches to a custom
key for signing.
- Server configuration sets a custom key, reloader switches to a native
key for signing.
- Server configuration sets a native key, reloader switches to a custom
key for decryption.
- Client key and cert are set by reloader.
Result:
NIOCertificateReloading will work as expected with custom private keys.