(self)
| 2907 | USE_SAME_TEST_CONTEXT = False |
| 2908 | |
| 2909 | def test_getpeercert(self): |
| 2910 | if support.verbose: |
| 2911 | sys.stdout.write("\n") |
| 2912 | |
| 2913 | client_context, server_context, hostname = testing_context() |
| 2914 | server = ThreadedEchoServer(context=server_context, chatty=False) |
| 2915 | with server: |
| 2916 | with client_context.wrap_socket(socket.socket(), |
| 2917 | do_handshake_on_connect=False, |
| 2918 | server_hostname=hostname) as s: |
| 2919 | s.connect((HOST, server.port)) |
| 2920 | # getpeercert() raise ValueError while the handshake isn't |
| 2921 | # done. |
| 2922 | with self.assertRaises(ValueError): |
| 2923 | s.getpeercert() |
| 2924 | s.do_handshake() |
| 2925 | cert = s.getpeercert() |
| 2926 | self.assertTrue(cert, "Can't get peer certificate.") |
| 2927 | cipher = s.cipher() |
| 2928 | if support.verbose: |
| 2929 | sys.stdout.write(pprint.pformat(cert) + '\n') |
| 2930 | sys.stdout.write("Connection cipher is " + str(cipher) + '.\n') |
| 2931 | if 'subject' not in cert: |
| 2932 | self.fail("No subject field in certificate: %s." % |
| 2933 | pprint.pformat(cert)) |
| 2934 | if ((('organizationName', 'Python Software Foundation'),) |
| 2935 | not in cert['subject']): |
| 2936 | self.fail( |
| 2937 | "Missing or invalid 'organizationName' field in certificate subject; " |
| 2938 | "should be 'Python Software Foundation'.") |
| 2939 | self.assertIn('notBefore', cert) |
| 2940 | self.assertIn('notAfter', cert) |
| 2941 | before = ssl.cert_time_to_seconds(cert['notBefore']) |
| 2942 | after = ssl.cert_time_to_seconds(cert['notAfter']) |
| 2943 | self.assertLess(before, after) |
| 2944 | |
| 2945 | def test_crl_check(self): |
| 2946 | if support.verbose: |
nothing calls this directly
no test coverage detected