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

DBDebugToolkit not compatible with ATS and self-signed certificate #2

Closed
aliasdoc opened this issue Mar 28, 2017 · 4 comments
Closed
Assignees

Comments

@aliasdoc
Copy link

Hi,

For first, very good job, I'm trying to use your library and it appears that it's not compatible with URLSessionDelegate, in my app i'm using https with a self-signed certificate and I use URLSessionDelegate for debug and when i'm setup your library, delegate are not fired and make me errors.

Steps for reproducing:
AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        #if DEBUG
            DBDebugToolkit.setup() // <-- if I comment network works good
        #endif

        ...

SSLDebugSessionDelegate.swift

class SSLDebugSessionDelegate: NSObject, URLSessionDelegate {
    
    /// The host to allow a self-signed SSL certificate for.
    let host: String
    
    
    /** Designated initializer.
     
     - parameter host: The host to which the exception should apply
     */
    public init(host: String) {
        self.host = host
    }
    
    open func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge,
                         completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        Log.debug("----DEBUG SESSION DELEGATE----")
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
            if challenge.protectionSpace.host == host, let trust = challenge.protectionSpace.serverTrust {
                let credential = URLCredential(trust: trust)
                completionHandler(.useCredential, credential)
                return
            }
        }
        completionHandler(.performDefaultHandling, nil)
    }

}
let sessionDelegate = SSLDebugSessionDelegate(host:"xxxxxxx")
URLSession(configuration: config, delegate: sessionDelegate, delegateQueue: nil)

And use a self-signed certificate.

@aliasdoc aliasdoc changed the title issue with SSL DBDebugToolkit not compatible with ATS and self-signed certificate Mar 28, 2017
@dbukowski
Copy link
Owner

Hi, thank you! Sorry for responding so late, I will take a look at this issue.

@dbukowski dbukowski self-assigned this Apr 4, 2017
@dbukowski
Copy link
Owner

Hi @aliasdoc, I just pushed a branch with code that I believe will fix your issues. Could you please take a look at it? That would be really helpful.

To do that, you can specify a branch in your Podfile like this:
pod 'DBDebugToolkit', :git => 'https://github.com/dbukowski/DBDebugToolkit.git', :branch => 'bug-fix/self-signed-certificate'

If it does fix your issues I will merge it to the master branch and release a new version of DBDebugToolkit. If not, then I would like to ask you for more details about your issues.

@aliasdoc
Copy link
Author

Hi @dbukowski, good work, it works now ;), thank you.

@dbukowski
Copy link
Owner

@aliasdoc thanks for checking that! I just released a new version 0.1.4 with this fix, so you can remove the specified branch from your Podfile :)

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