{"action":"created","issue":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1122","repository_url":"https://api.github.com/repos/Alamofire/Alamofire","labels_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1122/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1122/comments","events_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1122/events","html_url":"https://github.com/Alamofire/Alamofire/issues/1122","id":141303115,"number":1122,"title":"SSL Connection does not work when using a Background Session Configuration","user":{"login":"matthiaslau","id":574305,"avatar_url":"https://avatars.githubusercontent.com/u/574305?v=3","gravatar_id":"","url":"https://api.github.com/users/matthiaslau","html_url":"https://github.com/matthiaslau","followers_url":"https://api.github.com/users/matthiaslau/followers","following_url":"https://api.github.com/users/matthiaslau/following{/other_user}","gists_url":"https://api.github.com/users/matthiaslau/gists{/gist_id}","starred_url":"https://api.github.com/users/matthiaslau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthiaslau/subscriptions","organizations_url":"https://api.github.com/users/matthiaslau/orgs","repos_url":"https://api.github.com/users/matthiaslau/repos","events_url":"https://api.github.com/users/matthiaslau/events{/privacy}","received_events_url":"https://api.github.com/users/matthiaslau/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/bug","name":"bug","color":"ff3333"},{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/help%20wanted","name":"help wanted","color":"9559F0"},{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/needs%20feedback","name":"needs feedback","color":"9559F0"},{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/session%20delegate","name":"session delegate","color":"69B805"}],"state":"open","locked":false,"assignee":{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2016-03-16T15:07:54Z","updated_at":"2016-03-22T16:02:30Z","closed_at":null,"body":"When using a Background Session Configuration instead of the default to call a HTTPS URL the serverTrustPolicyManager is never used and the download fails with \"An SSL error has occured and a secure connection to the server cannot be made.\".\r\n\r\nI create my Manager like this\r\n```\r\nlet serverTrustPolicies: [String: ServerTrustPolicy] = [\r\n    Consts.host: .PinCertificates(\r\n        certificates: ServerTrustPolicy.certificatesInBundle(),\r\n         validateCertificateChain: true,\r\n         validateHost: false\r\n     )\r\n]\r\nlet configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(\"projectid.background\")\r\nlet downloadManager = Alamofire.Manager(\r\n    configuration: configuration,\r\n    serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)\r\n)\r\n```\r\n\r\nThe `didReceiveChallenge` of the SessionDelegate is never called. Using `NSURLSessionConfiguration.defaultSessionConfiguration()` everything works as expected and the SSL certificate is successfully validated. Does anyone have an idea why the didReceiveChallenge is not called when using a background configuration? I couldn´t figure it out yet.\r\n\r\nI am using XCode 7.2.1 testing on iOS 9.2.1."},"comment":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/comments/199881299","html_url":"https://github.com/Alamofire/Alamofire/issues/1122#issuecomment-199881299","issue_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1122","id":199881299,"user":{"login":"matthiaslau","id":574305,"avatar_url":"https://avatars.githubusercontent.com/u/574305?v=3","gravatar_id":"","url":"https://api.github.com/users/matthiaslau","html_url":"https://github.com/matthiaslau","followers_url":"https://api.github.com/users/matthiaslau/followers","following_url":"https://api.github.com/users/matthiaslau/following{/other_user}","gists_url":"https://api.github.com/users/matthiaslau/gists{/gist_id}","starred_url":"https://api.github.com/users/matthiaslau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthiaslau/subscriptions","organizations_url":"https://api.github.com/users/matthiaslau/orgs","repos_url":"https://api.github.com/users/matthiaslau/repos","events_url":"https://api.github.com/users/matthiaslau/events{/privacy}","received_events_url":"https://api.github.com/users/matthiaslau/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T16:02:30Z","updated_at":"2016-03-22T16:02:30Z","body":"This problem directly occurs regardless of whether in foreground or background. In my usecase we are communicating with a server running on a hardware we are producing using certificate pinning for security reasons. When we are downloading files from this server I want the app to continue in the background so the download is finished even when the user leaves the app.\r\n\r\nThe interesting part is that without putting the app into background `didReceiveChallenge`is not called just because the session configuration is different.\r\n\r\n@cnoon: do you have a rough idea where I can look at for further investigation? Thanks for your help! :-D"}}