|
| 1 | +import socket |
| 2 | +import ssl |
| 3 | + |
| 4 | +def test_fluent_tls(): |
| 5 | + hostname = 'www.python.org' |
| 6 | + context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 7 | + |
| 8 | + with socket.create_connection((hostname, 443)) as sock: |
| 9 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 10 | + print(ssock.version()) |
| 11 | + |
| 12 | + |
| 13 | +def test_fluent_tls_no_TLSv1(): |
| 14 | + hostname = 'www.python.org' |
| 15 | + context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 16 | + context.options |= ssl.OP_NO_TLSv1 |
| 17 | + |
| 18 | + with socket.create_connection((hostname, 443)) as sock: |
| 19 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 20 | + print(ssock.version()) |
| 21 | + |
| 22 | +def test_fluent_tls_safe(): |
| 23 | + hostname = 'www.python.org' |
| 24 | + context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 25 | + context.options |= ssl.OP_NO_TLSv1 |
| 26 | + context.options |= ssl.OP_NO_TLSv1_1 |
| 27 | + |
| 28 | + with socket.create_connection((hostname, 443)) as sock: |
| 29 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 30 | + print(ssock.version()) |
| 31 | + |
| 32 | +def test_fluent_ssl(): |
| 33 | + hostname = 'www.python.org' |
| 34 | + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 35 | + |
| 36 | + with socket.create_connection((hostname, 443)) as sock: |
| 37 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 38 | + print(ssock.version()) |
| 39 | + |
| 40 | + |
| 41 | +def test_fluent_ssl_no_TLSv1(): |
| 42 | + hostname = 'www.python.org' |
| 43 | + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 44 | + context.options |= ssl.OP_NO_TLSv1 |
| 45 | + |
| 46 | + with socket.create_connection((hostname, 443)) as sock: |
| 47 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 48 | + print(ssock.version()) |
| 49 | + |
| 50 | +def test_fluent_ssl_safe(): |
| 51 | + hostname = 'www.python.org' |
| 52 | + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 53 | + context.options |= ssl.OP_NO_TLSv1 |
| 54 | + context.options |= ssl.OP_NO_TLSv1_1 |
| 55 | + |
| 56 | + with socket.create_connection((hostname, 443)) as sock: |
| 57 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 58 | + print(ssock.version()) |
| 59 | + |
| 60 | +def test_fluent_ssl_safe_combined(): |
| 61 | + hostname = 'www.python.org' |
| 62 | + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 63 | + context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 |
| 64 | + |
| 65 | + with socket.create_connection((hostname, 443)) as sock: |
| 66 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 67 | + print(ssock.version()) |
| 68 | + |
| 69 | +# From Python 3.7 |
| 70 | +# see https://docs.python.org/3/library/ssl.html#ssl.SSLContext.minimum_version |
| 71 | +def test_fluent_ssl_unsafe_version(): |
| 72 | + hostname = 'www.python.org' |
| 73 | + context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 74 | + context.minimum_version = ssl.TLSVersion.TLSv1_1 |
| 75 | + |
| 76 | + with socket.create_connection((hostname, 443)) as sock: |
| 77 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 78 | + print(ssock.version()) |
| 79 | + |
| 80 | +def test_fluent_ssl_safe_version(): |
| 81 | + hostname = 'www.python.org' |
| 82 | + context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 83 | + context.minimum_version = ssl.TLSVersion.TLSv1_3 |
| 84 | + |
| 85 | + with socket.create_connection((hostname, 443)) as sock: |
| 86 | + with context.wrap_socket(sock, server_hostname=hostname) as ssock: |
| 87 | + print(ssock.version()) |
0 commit comments