-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
URLSession: Added support for client certificate authentication for non MacOS platforms #4937
base: main
Are you sure you want to change the base?
URLSession: Added support for client certificate authentication for non MacOS platforms #4937
Conversation
@swift-ci test |
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 work to add this! I believe adding new public API like this would need to go through an API review process, but we might also be able to accomplish this by implementing existing Darwin URLCredential
API and adding smalls stubs for SecIdentity
/SecCertificate
. I'll need to give that a bit more thought, but in the meantime, I've left a few comments that should hopefully help address the build issues/other minor feedback :)
I think it'd be better to set this on the task instead of the session configuration. Generally the client would use the same session + configuration for every request they make, but might not necessarily want to enable client certificate authentication on all of them. |
e4ff2fa
to
bf338c8
Compare
Thanks @jrflat and @travarin for the feedback! I have just updated the PR with your suggestions. Reading Just on few points you mentioned in your comments:
I guess the next step is for me to create a proposal in swift-evolution? |
bf338c8
to
7141710
Compare
Swift Foundation Networking does not currently support client certificate authentication which is quite a limitation when integrating with a more complex system.
For MacOS/iOS based platform, the client certificate authentication is done through URLSessionDelegate that handles authentication challenges.
Swift Foundation Networking relies on
libcurl
forURLSession
. This support does not go throughURLSessionDelegate
for authentication challenge. The approach used by this pull-request is:URLCredential
to also pass client private key and certificateURLCredential
throughURLSessionConfiguration
. Note: on MacOS/iOS this approach could also be used as theURLSessionDelegate
is often a copy/paste to passURLCredential
back toURLSession
.There is no unittest for this new code as it would require Swift to support server with TLS client certificate authentication support. The code can be locally tested with
openssl s_server
.Here is an example code to use this API:
Limitations of this support:
URLSessionDelegate
. But for using the same approach, we would either need to forklibcurl
inswift-corelibs-foundation
to handle the authentication challenge in Swift or we would need to a different library "backend" to handleURLSession