{"action":"created","issue":{"url":"https://api.github.com/repos/shazow/urllib3/issues/820","repository_url":"https://api.github.com/repos/shazow/urllib3","labels_url":"https://api.github.com/repos/shazow/urllib3/issues/820/labels{/name}","comments_url":"https://api.github.com/repos/shazow/urllib3/issues/820/comments","events_url":"https://api.github.com/repos/shazow/urllib3/issues/820/events","html_url":"https://github.com/shazow/urllib3/pull/820","id":141620743,"number":820,"title":"Show certificate when there is a hostname mismatch","user":{"login":"msabramo","id":305268,"avatar_url":"https://avatars.githubusercontent.com/u/305268?v=3","gravatar_id":"","url":"https://api.github.com/users/msabramo","html_url":"https://github.com/msabramo","followers_url":"https://api.github.com/users/msabramo/followers","following_url":"https://api.github.com/users/msabramo/following{/other_user}","gists_url":"https://api.github.com/users/msabramo/gists{/gist_id}","starred_url":"https://api.github.com/users/msabramo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msabramo/subscriptions","organizations_url":"https://api.github.com/users/msabramo/orgs","repos_url":"https://api.github.com/users/msabramo/repos","events_url":"https://api.github.com/users/msabramo/events{/privacy}","received_events_url":"https://api.github.com/users/msabramo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-03-17T15:41:24Z","updated_at":"2016-03-17T20:43:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/shazow/urllib3/pulls/820","html_url":"https://github.com/shazow/urllib3/pull/820","diff_url":"https://github.com/shazow/urllib3/pull/820.diff","patch_url":"https://github.com/shazow/urllib3/pull/820.patch"},"body":"I am getting a hostname mismatch error for one of three servers in a pool so I am suspecting that one server has an invalid certificate.\r\n\r\n    requests.exceptions.SSLError: hostname '10.10.194.37' doesn't match u'vault.service.trouper'\r\n\r\nby itself is not much info to go on. It would be nice to see the server certificate that was presented.\r\n\r\nI found that it was surprisingly difficult to see the server certificate, so I decided to see if urllib3 could show the certificate.\r\n\r\nWith this, urllib3 logs an error with the certificate just before raising the exception:\r\n\r\n```\r\nERROR:requests.packages.urllib3.connection:Certificate did not match expected hostname: 10.10.194.38.\r\nCertificate: {'subjectAltName': (('IP Address', '127.0.0.1'), ('IP Address', '10.10.194.36'), ('IP Address', '10.10.194.37'), ('IP Address', '10.10.194.38')),\r\n'notBefore': u'Mar 17 01:18:27 2016 GMT', 'serialNumber': u'9BFDB58B08E7DCCA', 'notAfter': 'Mar 15 01:18:27 2026 GMT', 'version': 3L,\r\n'subject': ((('countryName', u'US'),), (('stateOrProvinceName', u'California'),), (('localityName', u'Palo Alto'),), (('organizationName', u'DevOps'),), (('commonName', u'vault\r\n```\r\n\r\nwhich allows me to check whether the server is presenting the correct certificate.\r\n\r\nI also add the certificate to the exception that is raised so that client code can inspect it."},"comment":{"url":"https://api.github.com/repos/shazow/urllib3/issues/comments/198074800","html_url":"https://github.com/shazow/urllib3/pull/820#issuecomment-198074800","issue_url":"https://api.github.com/repos/shazow/urllib3/issues/820","id":198074800,"user":{"login":"msabramo","id":305268,"avatar_url":"https://avatars.githubusercontent.com/u/305268?v=3","gravatar_id":"","url":"https://api.github.com/users/msabramo","html_url":"https://github.com/msabramo","followers_url":"https://api.github.com/users/msabramo/followers","following_url":"https://api.github.com/users/msabramo/following{/other_user}","gists_url":"https://api.github.com/users/msabramo/gists{/gist_id}","starred_url":"https://api.github.com/users/msabramo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msabramo/subscriptions","organizations_url":"https://api.github.com/users/msabramo/orgs","repos_url":"https://api.github.com/users/msabramo/repos","events_url":"https://api.github.com/users/msabramo/events{/privacy}","received_events_url":"https://api.github.com/users/msabramo/received_events","type":"User","site_admin":false},"created_at":"2016-03-17T20:43:50Z","updated_at":"2016-03-17T20:43:50Z","body":"OK, I just added a few tests in `test/test_connection.py`. The most notable test for this PR is `test_match_hostname_mismatch`."}}