|
67 | 67 | ) |
68 | 68 | from OpenSSL.SSL import ( |
69 | 69 | DTLS_METHOD, |
70 | | - MODE_RELEASE_BUFFERS, |
71 | 70 | NO_OVERLAPPING_PROTOCOLS, |
72 | 71 | OP_COOKIE_EXCHANGE, |
73 | 72 | OP_NO_COMPRESSION, |
|
132 | 131 | _NoOverlappingProtocols, |
133 | 132 | ) |
134 | 133 |
|
| 134 | +from . import conftest |
135 | 135 | from .test_crypto import ( |
136 | 136 | client_cert_pem, |
137 | 137 | client_key_pem, |
@@ -643,6 +643,12 @@ def test_set_cipher_list_no_cipher_match(self, context: Context) -> None: |
643 | 643 | "", |
644 | 644 | "no cipher match", |
645 | 645 | ), |
| 646 | + # aws-lc |
| 647 | + ( |
| 648 | + "SSL routines", |
| 649 | + "OPENSSL_internal", |
| 650 | + "NO_CIPHER_MATCH", |
| 651 | + ), |
646 | 652 | ] |
647 | 653 |
|
648 | 654 | def test_load_client_ca(self, context: Context, ca_file: bytes) -> None: |
@@ -700,6 +706,12 @@ def test_set_session_id_fail(self, context: Context) -> None: |
700 | 706 | "", |
701 | 707 | "ssl session id context too long", |
702 | 708 | ), |
| 709 | + # aws-lc |
| 710 | + ( |
| 711 | + "SSL routines", |
| 712 | + "OPENSSL_internal", |
| 713 | + "SSL_SESSION_ID_CONTEXT_TOO_LONG", |
| 714 | + ), |
703 | 715 | ] |
704 | 716 |
|
705 | 717 | def test_set_session_id_unicode(self, context: Context) -> None: |
@@ -922,7 +934,8 @@ def test_set_mode(self) -> None: |
922 | 934 | newly set mode. |
923 | 935 | """ |
924 | 936 | context = Context(SSLv23_METHOD) |
925 | | - assert MODE_RELEASE_BUFFERS & context.set_mode(MODE_RELEASE_BUFFERS) |
| 937 | + mode = _lib.SSL_MODE_ENABLE_PARTIAL_WRITE |
| 938 | + assert mode & context.set_mode(mode) |
926 | 939 |
|
927 | 940 | def test_set_timeout_wrong_args(self) -> None: |
928 | 941 | """ |
@@ -969,7 +982,7 @@ def _write_encrypted_pem(self, passphrase: bytes, tmpfile: bytes) -> bytes: |
969 | 982 | """ |
970 | 983 | key = PKey() |
971 | 984 | key.generate_key(TYPE_RSA, 1024) |
972 | | - pem = dump_privatekey(FILETYPE_PEM, key, "blowfish", passphrase) |
| 985 | + pem = dump_privatekey(FILETYPE_PEM, key, "aes-256-cbc", passphrase) |
973 | 986 | with open(tmpfile, "w") as fObj: |
974 | 987 | fObj.write(pem.decode("ascii")) |
975 | 988 | return tmpfile |
@@ -1163,7 +1176,7 @@ def test_set_proto_version(self) -> None: |
1163 | 1176 | client_context = Context(TLS_METHOD) |
1164 | 1177 | client_context.set_max_proto_version(low_version) |
1165 | 1178 |
|
1166 | | - with pytest.raises(Error, match="unsupported protocol"): |
| 1179 | + with pytest.raises(Error, match=r"(?i)unsupported.protocol"): |
1167 | 1180 | self._handshake_test(server_context, client_context) |
1168 | 1181 |
|
1169 | 1182 | client_context = Context(TLS_METHOD) |
@@ -1632,7 +1645,9 @@ def test_set_verify_default_callback(self, mode: int) -> None: |
1632 | 1645 | if mode == SSL.VERIFY_PEER: |
1633 | 1646 | with pytest.raises(Exception) as exc: |
1634 | 1647 | self._handshake_test(serverContext, clientContext) |
1635 | | - assert "certificate verify failed" in str(exc.value) |
| 1648 | + assert "certificate verify failed" in str( |
| 1649 | + exc.value |
| 1650 | + ) or "CERTIFICATE_VERIFY_FAILED" in str(exc.value) |
1636 | 1651 | else: |
1637 | 1652 | self._handshake_test(serverContext, clientContext) |
1638 | 1653 |
|
@@ -1861,9 +1876,27 @@ def test_set_tmp_ecdh(self) -> None: |
1861 | 1876 | with pytest.deprecated_call(): |
1862 | 1877 | context.set_tmp_ecdh(curve) |
1863 | 1878 |
|
| 1879 | + awslc_unsupported_curves = { |
| 1880 | + "BRAINPOOLP256R1", |
| 1881 | + "BRAINPOOLP384R1", |
| 1882 | + "BRAINPOOLP512R1", |
| 1883 | + "SECP192R1", |
| 1884 | + "SECT163K1", |
| 1885 | + "SECT163R2", |
| 1886 | + "SECT233K1", |
| 1887 | + "SECT233R1", |
| 1888 | + "SECT283K1", |
| 1889 | + "SECT283R1", |
| 1890 | + "SECT409K1", |
| 1891 | + "SECT409R1", |
| 1892 | + "SECT571K1", |
| 1893 | + "SECT571R1", |
| 1894 | + } |
1864 | 1895 | for name in dir(ec.EllipticCurveOID): |
1865 | 1896 | if name.startswith("_"): |
1866 | 1897 | continue |
| 1898 | + if conftest.is_awslc and name in awslc_unsupported_curves: |
| 1899 | + continue |
1867 | 1900 | oid = getattr(ec.EllipticCurveOID, name) |
1868 | 1901 | cryptography_curve = ec.get_curve_for_oid(oid) |
1869 | 1902 | context.set_tmp_ecdh(cryptography_curve()) |
@@ -2749,10 +2782,12 @@ def test_state_string(self) -> None: |
2749 | 2782 | assert tls_server.get_state_string() in [ |
2750 | 2783 | b"before/accept initialization", |
2751 | 2784 | b"before SSL initialization", |
| 2785 | + b"TLS server start_accept", |
2752 | 2786 | ] |
2753 | 2787 | assert tls_client.get_state_string() in [ |
2754 | 2788 | b"before/connect initialization", |
2755 | 2789 | b"before SSL initialization", |
| 2790 | + b"TLS client start_connect", |
2756 | 2791 | ] |
2757 | 2792 |
|
2758 | 2793 | def test_app_data(self) -> None: |
@@ -3229,9 +3264,10 @@ def _perform_moving_buffer_test( |
3229 | 3264 | return False # Retry succeeded |
3230 | 3265 | except SSL.Error as e: |
3231 | 3266 | reason = get_ssl_error_reason(e) |
3232 | | - assert reason == "bad write retry", ( |
3233 | | - f"Retry failed with unexpected SSL error: {e!r}({reason})." |
3234 | | - ) |
| 3267 | + assert reason in ( |
| 3268 | + "bad write retry", |
| 3269 | + "BAD_WRITE_RETRY", |
| 3270 | + ), f"Retry failed with unexpected SSL error: {e!r}({reason})." |
3235 | 3271 | return True # Bad write retry |
3236 | 3272 |
|
3237 | 3273 | def _shutdown_connections( |
@@ -3945,6 +3981,10 @@ def test_total_renegotiations(self) -> None: |
3945 | 3981 | connection = Connection(Context(SSLv23_METHOD), None) |
3946 | 3982 | assert connection.total_renegotiations() == 0 |
3947 | 3983 |
|
| 3984 | + @pytest.mark.skipif( |
| 3985 | + conftest.is_awslc, |
| 3986 | + reason="aws-lc doesn't support renegotiation", |
| 3987 | + ) |
3948 | 3988 | def test_renegotiate(self) -> None: |
3949 | 3989 | """ |
3950 | 3990 | Go through a complete renegotiation cycle. |
@@ -4038,6 +4078,10 @@ def test_op_no_ticket(self) -> None: |
4038 | 4078 | "OP_NO_COMPRESSION unavailable - OpenSSL version may be too old" |
4039 | 4079 | ), |
4040 | 4080 | ) |
| 4081 | + @pytest.mark.skipif( |
| 4082 | + conftest.is_awslc, |
| 4083 | + reason="aws-lc defines OP_NO_COMPRESSION as 0", |
| 4084 | + ) |
4041 | 4085 | def test_op_no_compression(self) -> None: |
4042 | 4086 | """ |
4043 | 4087 | The value of `OpenSSL.SSL.OP_NO_COMPRESSION` is 0x20000, the |
@@ -5100,12 +5144,24 @@ def pump() -> None: |
5100 | 5144 | c.set_ciphertext_mtu(500) |
5101 | 5145 | assert 0 < c.get_cleartext_mtu() < 500 |
5102 | 5146 |
|
| 5147 | + @pytest.mark.skipif( |
| 5148 | + OP_COOKIE_EXCHANGE is None, |
| 5149 | + reason="DTLS cookie exchange not supported", |
| 5150 | + ) |
5103 | 5151 | def test_it_works_at_all(self) -> None: |
5104 | 5152 | self._test_handshake_and_data(srtp_profile=None) |
5105 | 5153 |
|
| 5154 | + @pytest.mark.skipif( |
| 5155 | + OP_COOKIE_EXCHANGE is None, |
| 5156 | + reason="DTLS cookie exchange not supported", |
| 5157 | + ) |
5106 | 5158 | def test_it_works_with_srtp(self) -> None: |
5107 | 5159 | self._test_handshake_and_data(srtp_profile=b"SRTP_AES128_CM_SHA1_80") |
5108 | 5160 |
|
| 5161 | + @pytest.mark.skipif( |
| 5162 | + OP_COOKIE_EXCHANGE is None, |
| 5163 | + reason="DTLS cookie exchange not supported", |
| 5164 | + ) |
5109 | 5165 | def test_cookie_generate_too_long(self) -> None: |
5110 | 5166 | s_ctx = Context(DTLS_METHOD) |
5111 | 5167 |
|
|
0 commit comments