Debian Codegraph @

crt/s2n/tests/integrationv2/test_renegotiate_apache.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0
3 import pytest
4 import tempfile
5
6 from configuration import ALL_TEST_CURVES, PROTOCOLS
7 from common import ProviderOptions, Protocols
8 from fixtures import managed_process # noqa: F401
9 from global_flags import get_flag, S2N_PROVIDER_VERSION
10 from providers import Provider, S2N
11 from utils import invalid_test_parameters, get_parameter_name
12 from constants import TEST_CERT_DIRECTORY
13
14 TEST_PROTOCOLS = [x for x in PROTOCOLS if x.value < Protocols.TLS13.value]
15 S2N_RENEG_OPTION = "--renegotiation"
16 S2N_RENEG_ACCEPT = "accept"
17
18 APACHE_SERVER_IP = "127.0.0.1"
19 APACHE_SERVER_PORT = 7777
20
21 APACHE_SERVER_CERT = TEST_CERT_DIRECTORY + "apache_server_cert.pem"
22 APACHE_CLIENT_CERT = TEST_CERT_DIRECTORY + "apache_client_cert.pem"
23 APACHE_CLIENT_KEY = TEST_CERT_DIRECTORY + "apache_client_key.pem"
24
25 CHANGE_CIPHER_SUITE_ENDPOINT = "/change_cipher_suite/"
26 MUTUAL_AUTH_ENDPOINT = "/mutual_auth/"
27
28
29 # The apache server uses RSA 1024 certificates,
30 # which s2n-tls does not support when built with openssl-3.0-fips.
31 def skip_for_openssl3_fips():
32 if "openssl-3.0-fips" in get_flag(S2N_PROVIDER_VERSION):
33 pytest.skip("Certs not supported: https://github.com/aws/s2n-tls/issues/5200")
34
35
36 def create_get_request(route):
37 return f"GET {route} HTTP/1.1\r\nHost: localhost\r\n\r\n"
38
39
40 @pytest.mark.uncollect_if(func=invalid_test_parameters)
41 @pytest.mark.parametrize("protocol", TEST_PROTOCOLS, ids=get_parameter_name)
42 @pytest.mark.parametrize(
43 "endpoint", [CHANGE_CIPHER_SUITE_ENDPOINT, MUTUAL_AUTH_ENDPOINT]
44 )
45 def test_apache_endpoints_fail_with_no_reneg(managed_process, protocol, endpoint): # noqa: F811
46 skip_for_openssl3_fips()
47
48 options = ProviderOptions(
49 mode=Provider.ClientMode,
50 host=APACHE_SERVER_IP,
51 port=APACHE_SERVER_PORT,
52 curve=ALL_TEST_CURVES[0],
53 protocol=protocol,
54 trust_store=APACHE_SERVER_CERT,
55 cert=APACHE_CLIENT_CERT,
56 key=APACHE_CLIENT_KEY,
57 use_client_auth=True,
58 )
59
60 with tempfile.NamedTemporaryFile("w+") as http_request_file:
61 http_request_file.write(create_get_request(endpoint))
62 http_request_file.flush()
63 options.extra_flags = ["--send-file", http_request_file.name]
64
65 s2n_client = managed_process(
66 S2N, options, timeout=20, close_marker="You don't have permission"
67 )
68
69 for results in s2n_client.get_results():
70 results.assert_success()
71
72 assert b"<title>403 Forbidden</title>" in results.stdout
73 assert (
74 b"You don't have permission to access this resource." in results.stdout
75 )
76
77
78 @pytest.mark.uncollect_if(func=invalid_test_parameters)
79 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
80 @pytest.mark.parametrize("protocol", TEST_PROTOCOLS, ids=get_parameter_name)
81 def test_change_cipher_suite_endpoint(managed_process, curve, protocol): # noqa: F811
82 skip_for_openssl3_fips()
83
84 options = ProviderOptions(
85 mode=Provider.ClientMode,
86 host=APACHE_SERVER_IP,
87 port=APACHE_SERVER_PORT,
88 curve=curve,
89 protocol=protocol,
90 trust_store=APACHE_SERVER_CERT,
91 )
92
93 options.extra_flags = [S2N_RENEG_OPTION, S2N_RENEG_ACCEPT]
94
95 with tempfile.NamedTemporaryFile("w+") as http_request_file:
96 http_request_file.write(create_get_request(CHANGE_CIPHER_SUITE_ENDPOINT))
97 http_request_file.flush()
98 options.extra_flags.extend(["--send-file", http_request_file.name])
99
100 s2n_client = managed_process(S2N, options, close_marker="Success.")
101
102 for results in s2n_client.get_results():
103 results.assert_success()
104
105 assert b"<title>Change Cipher Suite</title>" in results.stdout
106 assert b"Success." in results.stdout
107
108
109 @pytest.mark.uncollect_if(func=invalid_test_parameters)
110 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
111 @pytest.mark.parametrize("protocol", TEST_PROTOCOLS, ids=get_parameter_name)
112 def test_mutual_auth_endpoint(managed_process, curve, protocol): # noqa: F811
113 skip_for_openssl3_fips()
114
115 options = ProviderOptions(
116 mode=Provider.ClientMode,
117 host=APACHE_SERVER_IP,
118 port=APACHE_SERVER_PORT,
119 curve=curve,
120 protocol=protocol,
121 trust_store=APACHE_SERVER_CERT,
122 cert=APACHE_CLIENT_CERT,
123 key=APACHE_CLIENT_KEY,
124 use_client_auth=True,
125 )
126
127 options.extra_flags = [S2N_RENEG_OPTION, S2N_RENEG_ACCEPT]
128
129 with tempfile.NamedTemporaryFile("w+") as http_request_file:
130 http_request_file.write(create_get_request(MUTUAL_AUTH_ENDPOINT))
131 http_request_file.flush()
132 options.extra_flags.extend(["--send-file", http_request_file.name])
133
134 s2n_client = managed_process(S2N, options, close_marker="Success.")
135
136 for results in s2n_client.get_results():
137 results.assert_success()
138
139 assert b"<title>Mutual Auth</title>" in results.stdout
140 assert b"Success." in results.stdout