-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython-3.14-openssl4.patch
More file actions
223 lines (207 loc) · 8.33 KB
/
Copy pathpython-3.14-openssl4.patch
File metadata and controls
223 lines (207 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
--- a/Modules/_ssl.c 2026-06-10 12:03:53.000000000 +0200
+++ b/Modules/_ssl.c 2026-07-18 23:39:50.078170246 +0200
@@ -122,17 +122,31 @@
#endif
/* Include generated data (error codes) */
-/* See make_ssl_data.h for notes on adding a new version. */
-#if (OPENSSL_VERSION_NUMBER >= 0x30401000L)
-#include "_ssl_data_35.h"
+/* See Tools/ssl/make_ssl_data.py for notes on adding a new version. */
+#if (OPENSSL_VERSION_NUMBER >= 0x40000000L)
+# include "_ssl_data_40.h"
+#elif (OPENSSL_VERSION_NUMBER >= 0x30401000L)
+# include "_ssl_data_35.h"
#elif (OPENSSL_VERSION_NUMBER >= 0x30100000L)
-#include "_ssl_data_340.h"
+# include "_ssl_data_340.h"
#elif (OPENSSL_VERSION_NUMBER >= 0x30000000L)
-#include "_ssl_data_300.h"
+# include "_ssl_data_300.h"
#elif (OPENSSL_VERSION_NUMBER >= 0x10101000L)
-#include "_ssl_data_111.h"
+# include "_ssl_data_111.h"
#else
-#error Unsupported OpenSSL version
+# error Unsupported OpenSSL version
+#endif
+
+/* OpenSSL 4.0 removed legacy SSL/TLS protocol methods and versions. */
+#if (OPENSSL_VERSION_NUMBER >= 0x40000000L)
+# define OPENSSL_NO_SSL3
+# define OPENSSL_NO_TLS1
+# define OPENSSL_NO_TLS1_1
+# define OPENSSL_NO_TLS1_2
+# define OPENSSL_NO_SSL3_METHOD
+# define OPENSSL_NO_TLS1_METHOD
+# define OPENSSL_NO_TLS1_1_METHOD
+# define OPENSSL_NO_TLS1_2_METHOD
#endif
/* OpenSSL API 1.1.0+ does not include version methods */
@@ -1134,7 +1148,7 @@
static PyObject *
_create_tuple_for_attribute(_sslmodulestate *state,
- ASN1_OBJECT *name, ASN1_STRING *value)
+ const ASN1_OBJECT *name, const ASN1_STRING *value)
{
Py_ssize_t buflen;
PyObject *pyattr;
@@ -1163,16 +1177,16 @@
}
static PyObject *
-_create_tuple_for_X509_NAME (_sslmodulestate *state, X509_NAME *xname)
+_create_tuple_for_X509_NAME(_sslmodulestate *state, const X509_NAME *xname)
{
PyObject *dn = NULL; /* tuple which represents the "distinguished name" */
PyObject *rdn = NULL; /* tuple to hold a "relative distinguished name" */
PyObject *rdnt;
PyObject *attr = NULL; /* tuple to hold an attribute */
int entry_count = X509_NAME_entry_count(xname);
- X509_NAME_ENTRY *entry;
- ASN1_OBJECT *name;
- ASN1_STRING *value;
+ const X509_NAME_ENTRY *entry;
+ const ASN1_OBJECT *name;
+ const ASN1_STRING *value;
int index_counter;
int rdn_level = -1;
int retcode;
@@ -6513,9 +6527,15 @@
ADD_INT_CONST("PROTOCOL_TLS", PY_SSL_VERSION_TLS);
ADD_INT_CONST("PROTOCOL_TLS_CLIENT", PY_SSL_VERSION_TLS_CLIENT);
ADD_INT_CONST("PROTOCOL_TLS_SERVER", PY_SSL_VERSION_TLS_SERVER);
+#ifndef OPENSSL_NO_TLS1
ADD_INT_CONST("PROTOCOL_TLSv1", PY_SSL_VERSION_TLS1);
+#endif
+#ifndef OPENSSL_NO_TLS1_1
ADD_INT_CONST("PROTOCOL_TLSv1_1", PY_SSL_VERSION_TLS1_1);
+#endif
+#ifndef OPENSSL_NO_TLS1_2
ADD_INT_CONST("PROTOCOL_TLSv1_2", PY_SSL_VERSION_TLS1_2);
+#endif
#define ADD_OPTION(NAME, VALUE) if (sslmodule_add_option(m, NAME, (VALUE)) < 0) return -1
--- a/Modules/_ssl/cert.c 2026-06-10 12:03:53.000000000 +0200
+++ b/Modules/_ssl/cert.c 2026-07-18 23:39:50.078308528 +0200
@@ -128,7 +128,8 @@
}
static PyObject*
-_x509name_print(_sslmodulestate *state, X509_NAME *name, int indent, unsigned long flags)
+_x509name_print(_sslmodulestate *state, const X509_NAME *name,
+ int indent, unsigned long flags)
{
PyObject *res;
BIO *biobuf;
--- a/Lib/test/test_ssl.py 2026-06-10 12:03:53.000000000 +0200
+++ b/Lib/test/test_ssl.py 2026-07-18 23:39:50.079515213 +0200
@@ -396,7 +396,7 @@
ssl.OP_NO_COMPRESSION
self.assertEqual(ssl.HAS_SNI, True)
self.assertEqual(ssl.HAS_ECDH, True)
- self.assertEqual(ssl.HAS_TLSv1_2, True)
+ self.assertIsInstance(ssl.HAS_TLSv1_2, bool)
self.assertEqual(ssl.HAS_TLSv1_3, True)
ssl.OP_NO_SSLv2
ssl.OP_NO_SSLv3
@@ -587,11 +587,11 @@
# Some sanity checks follow
# >= 1.1.1
self.assertGreaterEqual(n, 0x10101000)
- # < 4.0
- self.assertLess(n, 0x40000000)
+ # < 5.0
+ self.assertLess(n, 0x50000000)
major, minor, fix, patch, status = t
self.assertGreaterEqual(major, 1)
- self.assertLess(major, 4)
+ self.assertLess(major, 5)
self.assertGreaterEqual(minor, 0)
self.assertLess(minor, 256)
self.assertGreaterEqual(fix, 0)
@@ -657,12 +657,14 @@
ssl.OP_NO_TLSv1_2,
ssl.OP_NO_TLSv1_3
]
- protocols = [
- ssl.PROTOCOL_TLSv1,
- ssl.PROTOCOL_TLSv1_1,
- ssl.PROTOCOL_TLSv1_2,
- ssl.PROTOCOL_TLS
- ]
+ protocols = []
+ if hasattr(ssl, 'PROTOCOL_TLSv1'):
+ protocols.append(ssl.PROTOCOL_TLSv1)
+ if hasattr(ssl, 'PROTOCOL_TLSv1_1'):
+ protocols.append(ssl.PROTOCOL_TLSv1_1)
+ if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
+ protocols.append(ssl.PROTOCOL_TLSv1_2)
+ protocols.append(ssl.PROTOCOL_TLS)
versions = [
ssl.TLSVersion.SSLv3,
ssl.TLSVersion.TLSv1,
@@ -1156,6 +1158,7 @@
ssl.TLSVersion.TLSv1,
ssl.TLSVersion.TLSv1_1,
ssl.TLSVersion.TLSv1_2,
+ ssl.TLSVersion.TLSv1_3,
ssl.TLSVersion.SSLv3,
}
)
@@ -1169,7 +1172,7 @@
with self.assertRaises(ValueError):
ctx.minimum_version = 42
- if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
+ if has_tls_protocol('PROTOCOL_TLSv1_1'):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
self.assertIn(
@@ -1717,23 +1720,24 @@
self.assertFalse(ctx.check_hostname)
self._assert_context_options(ctx)
- if has_tls_protocol(ssl.PROTOCOL_TLSv1):
+ if has_tls_protocol('PROTOCOL_TLSv1'):
with warnings_helper.check_warnings():
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
self._assert_context_options(ctx)
- with warnings_helper.check_warnings():
- ctx = ssl._create_stdlib_context(
- ssl.PROTOCOL_TLSv1_2,
- cert_reqs=ssl.CERT_REQUIRED,
- check_hostname=True
- )
- self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1_2)
- self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
- self.assertTrue(ctx.check_hostname)
- self._assert_context_options(ctx)
+ if has_tls_protocol('PROTOCOL_TLSv1_2'):
+ with warnings_helper.check_warnings():
+ ctx = ssl._create_stdlib_context(
+ ssl.PROTOCOL_TLSv1_2,
+ cert_reqs=ssl.CERT_REQUIRED,
+ check_hostname=True
+ )
+ self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1_2)
+ self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
+ self.assertTrue(ctx.check_hostname)
+ self._assert_context_options(ctx)
ctx = ssl._create_stdlib_context(purpose=ssl.Purpose.CLIENT_AUTH)
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_SERVER)
@@ -3629,10 +3633,10 @@
client_options=ssl.OP_NO_TLSv1_2)
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2')
- if has_tls_protocol(ssl.PROTOCOL_TLSv1):
+ if has_tls_protocol('PROTOCOL_TLSv1'):
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
- if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
+ if has_tls_protocol('PROTOCOL_TLSv1_1'):
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
@@ -4481,7 +4485,9 @@
sni_name='supermessage')
# Allow for flexible libssl error messages.
- regex = "(SSLV3_ALERT_HANDSHAKE_FAILURE|NO_PRIVATE_VALUE)"
+ regex = ("(TLS_ALERT_HANDSHAKE_FAILURE"
+ "|SSLV3_ALERT_HANDSHAKE_FAILURE"
+ "|NO_PRIVATE_VALUE)")
self.assertRegex(cm.exception.reason, regex)
self.assertEqual(catch.unraisable.exc_type, ZeroDivisionError)