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

Adding a certificate authentication request #251

Open
owenhartnett opened this issue Dec 11, 2023 · 1 comment
Open

Adding a certificate authentication request #251

owenhartnett opened this issue Dec 11, 2023 · 1 comment

Comments

@owenhartnett
Copy link

owenhartnett commented Dec 11, 2023

I'm trying to hit a server which sits in the dmz and asks for a certificate. It sends out a challenge in the initial http request. I supply the certificate for the NSURLSession. The code I use for AFNetworking on my REST calls to send the cert is here:

 [manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession * _Nonnull session, NSURLAuthenticationChallenge * _Nonnull challenge, NSURLCredential *__autoreleasing  _Nullable * _Nullable credential) {
        id sender = [challenge sender];
        const void *certArray[] = { certificate };
        CFArrayRef myCerts = CFArrayCreate(NULL, (void *) certArray, 1, NULL);     
        *credential = [NSURLCredential credentialWithIdentity: ident certificates: (__bridge NSArray *) myCerts persistence: NSURLCredentialPersistencePermanent];
        [sender useCredential:*credential forAuthenticationChallenge:challenge];
        CFRelease(myCerts);
        return NSURLSessionAuthChallengeUseCredential;
    }];

Is it possible to send this through the SwiftPhoenix client and, if so, where is the point where I could insert it? I know websocket makes an initial http call to connect, and I'm looking for that particular point in the code (I'm assuming it's using a NSURLSession to connect!)

I don't think the above is certificate pinning, but I could be wrong.

Thanks for any help.

@dsrees
Copy link
Collaborator

dsrees commented Dec 12, 2023

The URLSession used to create the websocket task is found here. I'm not sure exactly what API you would need to accomplish what you're trying to do but you can extend the URLSessionTransport class, override the connect method, and provide your own implementation that should work for you. You can then provide your custom implementation of Transport when you create the `Socket

let socket = Socket("example.com", { url -> MyCustomTransport(url) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants