(self)
| 2943 | self.assertLess(before, after) |
| 2944 | |
| 2945 | def test_crl_check(self): |
| 2946 | if support.verbose: |
| 2947 | sys.stdout.write("\n") |
| 2948 | |
| 2949 | client_context, server_context, hostname = testing_context() |
| 2950 | |
| 2951 | tf = getattr(ssl, "VERIFY_X509_TRUSTED_FIRST", 0) |
| 2952 | self.assertEqual(client_context.verify_flags, ssl.VERIFY_DEFAULT | tf) |
| 2953 | |
| 2954 | # VERIFY_DEFAULT should pass |
| 2955 | server = ThreadedEchoServer(context=server_context, chatty=True) |
| 2956 | with server: |
| 2957 | with client_context.wrap_socket(socket.socket(), |
| 2958 | server_hostname=hostname) as s: |
| 2959 | s.connect((HOST, server.port)) |
| 2960 | cert = s.getpeercert() |
| 2961 | self.assertTrue(cert, "Can't get peer certificate.") |
| 2962 | |
| 2963 | # VERIFY_CRL_CHECK_LEAF without a loaded CRL file fails |
| 2964 | client_context.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF |
| 2965 | |
| 2966 | server = ThreadedEchoServer(context=server_context, chatty=True) |
| 2967 | # Allow for flexible libssl error messages. |
| 2968 | regex = re.compile(r"""( |
| 2969 | certificate verify failed # OpenSSL |
| 2970 | | |
| 2971 | CERTIFICATE_VERIFY_FAILED # AWS-LC |
| 2972 | )""", re.X) |
| 2973 | with server: |
| 2974 | with client_context.wrap_socket(socket.socket(), |
| 2975 | server_hostname=hostname) as s: |
| 2976 | with self.assertRaisesRegex(ssl.SSLError, regex): |
| 2977 | s.connect((HOST, server.port)) |
| 2978 | |
| 2979 | # now load a CRL file. The CRL file is signed by the CA. |
| 2980 | client_context.load_verify_locations(CRLFILE) |
| 2981 | |
| 2982 | server = ThreadedEchoServer(context=server_context, chatty=True) |
| 2983 | with server: |
| 2984 | with client_context.wrap_socket(socket.socket(), |
| 2985 | server_hostname=hostname) as s: |
| 2986 | s.connect((HOST, server.port)) |
| 2987 | cert = s.getpeercert() |
| 2988 | self.assertTrue(cert, "Can't get peer certificate.") |
| 2989 | |
| 2990 | def test_check_hostname(self): |
| 2991 | if support.verbose: |
nothing calls this directly
no test coverage detected