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

Generate trust roots SecCertificate for Transport Services #350

Merged
merged 7 commits into from May 13, 2021

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Mar 19, 2021

This PR is a result of another #321.

In that PR I provided an alternative structure to TLSConfiguration for when connecting with Transport Services.

In this one I construct the NWProtocolTLS.Options from TLSConfiguration. It does mean a little more work for whenever we make a connection, but having spoken to @weissi he doesn't seem to think that is an issue.

Also there is no method to create a SecIdentity at the moment. We need to generate a pkcs#12 from the certificate chain and private key, which can then be used to create the SecIdentity.

This should resolve #292

@swift-server-bot
Copy link

Can one of the admins verify this patch?

1 similar comment
@swift-server-bot
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

The actual change seems to be lost in reformatting (which also reformats it in the wrong way (eg. moves qualifiers before extension instead of the individual members)). Could we undo everything that's not the actual change you'd like to make?

Sources/AsyncHTTPClient/HTTPClient+HTTPCookie.swift Outdated Show resolved Hide resolved
@adam-fowler
Copy link
Member Author

The actual change seems to be lost in reformatting (which also reformats it in the wrong way (eg. moves qualifiers before extension instead of the individual members)). Could we undo everything that's not the actual change you'd like to make?

Sorry I'm running a newer version of swift format and submitted all the other files by mistake.

The public infront of extension is caused by a new rule extensionAccessControl which is defaulted to on by default. I have it disabled in soto because its a pain. You could use it to force the positioning of the public qualifier through. Do you guys intend to upgrade from v0.44.6 at some point?

@Lukasa
Copy link
Collaborator

Lukasa commented Mar 22, 2021

@swift-server-bot add to allowlist

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Aside from the error handling situation this looks basically good to me.

try SecCertificateCreateWithData(nil, Data(certificate.toDERBytes()) as CFData)
}
} catch {
// failed to load
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need some error handling here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I stopped catching the error here and set getNWProtocolTLSOptions() to throws. Is that enough?

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

happy when @Lukasa is

}
case .some(.file):
preconditionFailure("TLSConfiguration.trustRoots.file is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

same q here. @Lukasa wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a slightly different case. I could probably support this case if I knew what format the file was in.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The file format for trust roots is just bundle-o-pem: a collection of PEM-encoded X509 certs in the same file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now loading PEM info NIOSSLCertificate and generating DER for loading into SecCertificateCreateWithData. Possibly not the quickest route.

@adam-fowler adam-fowler force-pushed the ts-tls-config2 branch 2 times, most recently from 7b7857b to 7a6826b Compare April 22, 2021 14:42
@adam-fowler adam-fowler requested a review from Lukasa April 22, 2021 14:51
@adam-fowler
Copy link
Member Author

@Lukasa do we need some more tests for converting between TLSConfiguration and NWProtocolTLS.Options?

@adam-fowler adam-fowler requested a review from weissi April 22, 2021 14:52
@adam-fowler
Copy link
Member Author

@Lukasa @weissi Anything left to do here?

guard case .default = trustRoots else {
preconditionFailure("TLSConfiguration.trustRoots != .default is not supported")
var secTrustRoots: [SecCertificate]?
switch trustRoots {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A note for the future, we've also added additionalTrustRoots which allows you to do default + others. No need to block this PR on that, but worth noting that it's there.

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Thank you, this looks good to me too! I left one comment (https://github.com/swift-server/async-http-client/pull/350/files#r631742891) which'd be nice to address. Just to be 100% sure we're on the right queue.

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

After chatting to @adam-fowler: we're not calling SecEvaluateTrust on the right queue at the moment.

@adam-fowler
Copy link
Member Author

After chatting to @adam-fowler: we're not calling SecEvaluateTrust on the right queue at the moment.

And then after reviewing code I realised we were.

Although we did come across another issue where a file load could happen on the EventLoop. To avoid this I have moved the whole NWProtocolTLS.Options generation to the DispatchQueue.

@@ -109,6 +126,11 @@
preconditionFailure("TLSConfiguration.keyLogCallback is not supported. \(useMTELGExplainer)")
}

// the certificate chain
if self.certificateChain.count > 0 {
preconditionFailure("TLSConfiguration.certificateChain is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
preconditionFailure("TLSConfiguration.certificateChain is not supported")
preconditionFailure("TLSConfiguration.certificateChain is not supported. \(useMTELGExplainer)")

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@weissi weissi merged commit 9cdf8a0 into swift-server:main May 13, 2021
@weissi weissi added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label May 13, 2021
@adam-fowler adam-fowler deleted the ts-tls-config2 branch May 13, 2021 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Non-Default TrustRoots on Darwin
4 participants