{"action":"created","issue":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/819","labels_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/819/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/819/comments","events_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/819/events","html_url":"https://github.com/Alamofire/Alamofire/issues/819","id":108630391,"number":819,"title":"self-signed certificate issue","user":{"login":"gensmusic","id":5219641,"avatar_url":"https://avatars.githubusercontent.com/u/5219641?v=3","gravatar_id":"","url":"https://api.github.com/users/gensmusic","html_url":"https://github.com/gensmusic","followers_url":"https://api.github.com/users/gensmusic/followers","following_url":"https://api.github.com/users/gensmusic/following{/other_user}","gists_url":"https://api.github.com/users/gensmusic/gists{/gist_id}","starred_url":"https://api.github.com/users/gensmusic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gensmusic/subscriptions","organizations_url":"https://api.github.com/users/gensmusic/orgs","repos_url":"https://api.github.com/users/gensmusic/repos","events_url":"https://api.github.com/users/gensmusic/events{/privacy}","received_events_url":"https://api.github.com/users/gensmusic/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/security","name":"security","color":"69B805"},{"url":"https://api.github.com/repos/Alamofire/Alamofire/labels/support","name":"support","color":"FC6808"}],"state":"closed","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":4,"created_at":"2015-09-28T10:34:52Z","updated_at":"2015-09-29T05:22:03Z","closed_at":"2015-09-29T03:20:56Z","body":"Hi,\r\n   Currently I'm using Alamofire to do a https connection. The server's certificate is self-signed.\r\nI got this error:\r\n```\r\n2015-09-28 18:20:58.950 alamofire-test[80162:2146829] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)\r\n2015-09-28 18:20:58.953 alamofire-test[80162:2143698] json: (Optional(<NSMutableURLRequest: 0x79085cb0> { URL: https://www.anexamplehost.cn/api/register }), nil, FAILURE: Error Domain=NSURLErrorDomain Code=-1202 \"The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.anexamplehost.cn” which could put your confidential information at risk.\" UserInfo={NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.anexamplelhost.cn” which could put your confidential information at risk., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSUnderlyingError=0x79082ae0 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 \"(null)\" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9813, _kCFStreamErrorCodeKey=-9813, _kCFStreamErrorDomainKey=3, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x78f75360>, kCFStreamPropertySSLPeerCertificates=<CFArray 0x794889f0 [0x98f098]>{type = immutable, count = 1, values = (\r\n\t0 : <cert(0x78f75220) s: Admin i: Admin>\r\n)}}}, _kCFStreamErrorCodeKey=-9813, NSErrorFailingURLStringKey=https://www.anexamplehost.cn/api/register, NSErrorPeerCertificateChainKey=<CFArray 0x794889f0 [0x98f098]>{type = immutable, count = 1, values = (\r\n\t0 : <cert(0x78f75220) s: Admin i: Admin>\r\n)}, NSErrorClientCertificateStateKey=0, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x78f75360>, NSErrorFailingURLKey=https://www.anexamplehost.cn/api/register} )\r\n```\r\nAnd this is the source code\r\n```\r\nclass MyManager {\r\n    static let sharedInstance = MyManager()\r\n    \r\n    let defaultManager: Alamofire.Manager = {\r\n        let serverTrustPolicies: [String: ServerTrustPolicy] = [\r\n            \"anexamplehost.cn\": .DisableEvaluation\r\n        ]\r\n\r\n        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()\r\n        configuration.HTTPAdditionalHeaders = Alamofire.Manager.defaultHTTPHeaders\r\n        \r\n        return Alamofire.Manager(\r\n            configuration: configuration,\r\n            serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)\r\n        )\r\n        }()\r\n}\r\n\r\nclass NotificationProvider {\r\n    static let registerURL = \"https://anexamplehost.cn/api/register\"\r\n    static let authUserName = \"admin\"\r\n    static let authPassword = \"admin\"\r\n    \r\n\r\n    func register(identity: String, _ device: String, _ token: String) {\r\n        \r\n        let params = [\"identity\": identity, \"device\": device, \"device_type\": UIDevice.currentDevice().systemName, \"token\":token ]\r\n        let credential = NSURLCredential(user: NotificationProvider.authUserName, password: NotificationProvider.authPassword, persistence: .Permanent)\r\n        MyManager.sharedInstance.defaultManager.request(.POST, NotificationProvider.registerURL, parameters: params, encoding: .JSON)\r\n            .authenticate(usingCredential: credential)\r\n            .responseJSON { response in\r\n                NSLog(\"json: \\(response)\")\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThe server is using http authentication digest and it's working good when I use curl or in browser.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/comments/143947873","html_url":"https://github.com/Alamofire/Alamofire/issues/819#issuecomment-143947873","issue_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/819","id":143947873,"user":{"login":"gensmusic","id":5219641,"avatar_url":"https://avatars.githubusercontent.com/u/5219641?v=3","gravatar_id":"","url":"https://api.github.com/users/gensmusic","html_url":"https://github.com/gensmusic","followers_url":"https://api.github.com/users/gensmusic/followers","following_url":"https://api.github.com/users/gensmusic/following{/other_user}","gists_url":"https://api.github.com/users/gensmusic/gists{/gist_id}","starred_url":"https://api.github.com/users/gensmusic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gensmusic/subscriptions","organizations_url":"https://api.github.com/users/gensmusic/orgs","repos_url":"https://api.github.com/users/gensmusic/repos","events_url":"https://api.github.com/users/gensmusic/events{/privacy}","received_events_url":"https://api.github.com/users/gensmusic/received_events","type":"User","site_admin":false},"created_at":"2015-09-29T05:22:03Z","updated_at":"2015-09-29T05:22:03Z","body":"Thanks, it works now."}}