-
Notifications
You must be signed in to change notification settings - Fork 21
Enable access to the peer's certificate chain #126
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
Enable access to the peer's certificate chain #126
Conversation
Motivation: The peer certificate chain can contain relevant information in some mTLS scenarios. NIO SSL only exposes the validated certificate chain when using custom verification callbacks. Now that this configuration option is available here, we can expose this property as well. Modifications: Make the property available and expose it as a validated certificate chain type from swift-certificates. Add tests to confirm the implementation. Result: The validated certificate chain is available when using mTLS with a custom certificate validation callback.
if let peerValidatedCertificateChain = | ||
try await channel.nioSSL_peerValidatedCertificateChain().get() | ||
{ | ||
context.peerValidatedCertificateChain = |
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.
Can we grab the peer cert from the chain to make the do-catch block above a little cheaper?
|
||
/// The validated peer certificate chain from the mTLS handshake. This is only available when using a custom verification callback. | ||
@available(gRPCSwiftNIOTransport 2.2, *) | ||
public var peerValidatedCertificateChain: X509.ValidatedCertificateChain? |
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.
This name makes it sound like the peer validated the cert chain. Do we need validated in the name at all here? It's documented and in the type name so I think peerCertificateChain
would be sufficient.
@available(gRPCSwiftNIOTransport 2.2, *) | ||
extension NIOSSL.ValidatedCertificateChain { | ||
// The precondition holds because the `NIOSSL.ValidatedCertificateChain` always contains one `NIOSSLCertificate`. | ||
func usingX509Certificates() throws -> X509.ValidatedCertificateChain { | ||
return .init( | ||
uncheckedCertificateChain: try self.map { | ||
let derBytes = try $0.toDERBytes() | ||
return try Certificate(derEncoded: derBytes) | ||
} | ||
) | ||
} | ||
} |
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.
The more natural spelling here is probably an extension
on X509.ValidatedCertificateChain
which adds an init(_ chain: NIOSSL.ValidatedCertificateChain) throws
let expectedCertificateChain: [Certificate] | ||
init(_ expectedCertificateChain: [Certificate]) { | ||
self.expectedCertificateChain = expectedCertificateChain | ||
} | ||
func intercept<Input, Output>( |
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.
let expectedCertificateChain: [Certificate] | |
init(_ expectedCertificateChain: [Certificate]) { | |
self.expectedCertificateChain = expectedCertificateChain | |
} | |
func intercept<Input, Output>( | |
let expectedCertificateChain: [Certificate] | |
init(_ expectedCertificateChain: [Certificate]) { | |
self.expectedCertificateChain = expectedCertificateChain | |
} | |
func intercept<Input, Output>( |
Thank you for the review! I pushed a commit to address your feedback. |
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, thanks @josephnoir!
Motivation:
The peer certificate chain can contain relevant information in some mTLS scenarios. NIO SSL only exposes the validated certificate chain when using custom verification callbacks. Now that this configuration option is available here, we can expose this property as well.
Modifications:
Make the property available and expose it as a validated certificate chain type from swift-certificates. Add tests to confirm the implementation.
Result:
The validated certificate chain is available when using mTLS with a custom certificate validation callback.