Line 0
Link Here
|
|
|
1 |
From 7316c6d4a57931e9786c06eae168b227d7463317 Mon Sep 17 00:00:00 2001 |
2 |
From: Christian Heimes <christian@python.org> |
3 |
Date: Tue, 5 Sep 2017 16:00:44 +0200 |
4 |
Subject: [PATCH] [3.6] bpo-30622: Change NPN detection: (GH-2079) (#3314) |
5 |
|
6 |
* Change NPN detection: |
7 |
|
8 |
Version breakdown, support disabled (pre-patch/post-patch): |
9 |
- pre-1.0.1: OPENSSL_NPN_NEGOTIATED will not be defined -> False/False |
10 |
- 1.0.1 and 1.0.2: OPENSSL_NPN_NEGOTIATED will not be defined -> |
11 |
False/False |
12 |
- 1.1.0+: OPENSSL_NPN_NEGOTIATED will be defined and |
13 |
OPENSSL_NO_NEXTPROTONEG will be defined -> True/False |
14 |
|
15 |
Version breakdown support enabled (pre-patch/post-patch): |
16 |
- pre-1.0.1: OPENSSL_NPN_NEGOTIATED will not be defined -> False/False |
17 |
- 1.0.1 and 1.0.2: OPENSSL_NPN_NEGOTIATED will be defined and |
18 |
OPENSSL_NO_NEXTPROTONEG will not be defined -> True/True |
19 |
- 1.1.0+: OPENSSL_NPN_NEGOTIATED will be defined and |
20 |
OPENSSL_NO_NEXTPROTONEG will not be defined -> True/True |
21 |
|
22 |
* Refine NPN guard: |
23 |
|
24 |
- If NPN is disabled, but ALPN is available we need our callback |
25 |
- Make clinic's ssl behave the same way |
26 |
|
27 |
This created a working ssl module for me, with NPN disabled and ALPN |
28 |
enabled for OpenSSL 1.1.0f. |
29 |
|
30 |
Concerns to address: |
31 |
The initial commit for NPN support into OpenSSL [1], had the |
32 |
OPENSSL_NPN_* variables defined inside the OPENSSL_NO_NEXTPROTONEG |
33 |
guard. The question is if that ever made it into a release. |
34 |
This would need an ugly hack, something like: |
35 |
|
36 |
GH-if defined(OPENSSL_NO_NEXTPROTONEG) && \ |
37 |
!defined(OPENSSL_NPN_NEGOTIATED) |
38 |
GH- define OPENSSL_NPN_UNSUPPORTED 0 |
39 |
GH- define OPENSSL_NPN_NEGOTIATED 1 |
40 |
GH- define OPENSSL_NPN_NO_OVERLAP 2 |
41 |
GH-endif |
42 |
|
43 |
[1] https://github.com/openssl/openssl/commit/68b33cc5c7 |
44 |
(cherry picked from commit b2d096b) |
45 |
--- |
46 |
Modules/_ssl.c | 16 +++++++++------- |
47 |
Modules/clinic/_ssl.c.h | 6 +++--- |
48 |
2 files changed, 12 insertions(+), 10 deletions(-) |
49 |
|
50 |
diff --git a/Modules/_ssl.c b/Modules/_ssl.c |
51 |
index ae38386ca02..6b6f2b1135c 100644 |
52 |
--- Modules/_ssl.c.orig |
53 |
+++ Modules/_ssl.c |
54 |
@@ -279,7 +279,7 @@ static unsigned int _ssl_locks_count = 0; |
55 |
typedef struct { |
56 |
PyObject_HEAD |
57 |
SSL_CTX *ctx; |
58 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
59 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
60 |
unsigned char *npn_protocols; |
61 |
int npn_protocols_len; |
62 |
#endif |
63 |
@@ -1693,7 +1693,7 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self) |
64 |
return PyUnicode_FromString(version); |
65 |
} |
66 |
|
67 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
68 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
69 |
/*[clinic input] |
70 |
_ssl._SSLSocket.selected_npn_protocol |
71 |
[clinic start generated code]*/ |
72 |
@@ -2645,7 +2645,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version) |
73 |
return NULL; |
74 |
} |
75 |
self->ctx = ctx; |
76 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
77 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
78 |
self->npn_protocols = NULL; |
79 |
#endif |
80 |
#ifdef HAVE_ALPN |
81 |
@@ -2780,7 +2780,7 @@ context_dealloc(PySSLContext *self) |
82 |
PyObject_GC_UnTrack(self); |
83 |
context_clear(self); |
84 |
SSL_CTX_free(self->ctx); |
85 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
86 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
87 |
PyMem_FREE(self->npn_protocols); |
88 |
#endif |
89 |
#ifdef HAVE_ALPN |
90 |
@@ -2858,7 +2858,7 @@ _ssl__SSLContext_get_ciphers_impl(PySSLContext *self) |
91 |
#endif |
92 |
|
93 |
|
94 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
95 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) || defined(HAVE_ALPN) |
96 |
static int |
97 |
do_protocol_selection(int alpn, unsigned char **out, unsigned char *outlen, |
98 |
const unsigned char *server_protocols, unsigned int server_protocols_len, |
99 |
@@ -2882,7 +2882,9 @@ do_protocol_selection(int alpn, unsigned char **out, unsigned char *outlen, |
100 |
|
101 |
return SSL_TLSEXT_ERR_OK; |
102 |
} |
103 |
+#endif |
104 |
|
105 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
106 |
/* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */ |
107 |
static int |
108 |
_advertiseNPN_cb(SSL *s, |
109 |
@@ -2925,7 +2927,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self, |
110 |
Py_buffer *protos) |
111 |
/*[clinic end generated code: output=72b002c3324390c6 input=319fcb66abf95bd7]*/ |
112 |
{ |
113 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
114 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
115 |
PyMem_Free(self->npn_protocols); |
116 |
self->npn_protocols = PyMem_Malloc(protos->len); |
117 |
if (self->npn_protocols == NULL) |
118 |
@@ -5391,7 +5393,7 @@ PyInit__ssl(void) |
119 |
Py_INCREF(r); |
120 |
PyModule_AddObject(m, "HAS_ECDH", r); |
121 |
|
122 |
-#ifdef OPENSSL_NPN_NEGOTIATED |
123 |
+#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
124 |
r = Py_True; |
125 |
#else |
126 |
r = Py_False; |
127 |
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h |
128 |
index 75f8f5a60bb..6f748903f4e 100644 |
129 |
--- Modules/clinic/_ssl.c.h.orig |
130 |
+++ Modules/clinic/_ssl.c.h |
131 |
@@ -132,7 +132,7 @@ _ssl__SSLSocket_version(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
132 |
return _ssl__SSLSocket_version_impl(self); |
133 |
} |
134 |
|
135 |
-#if defined(OPENSSL_NPN_NEGOTIATED) |
136 |
+#if (defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)) |
137 |
|
138 |
PyDoc_STRVAR(_ssl__SSLSocket_selected_npn_protocol__doc__, |
139 |
"selected_npn_protocol($self, /)\n" |
140 |
@@ -151,7 +151,7 @@ _ssl__SSLSocket_selected_npn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ign |
141 |
return _ssl__SSLSocket_selected_npn_protocol_impl(self); |
142 |
} |
143 |
|
144 |
-#endif /* defined(OPENSSL_NPN_NEGOTIATED) */ |
145 |
+#endif /* (defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)) */ |
146 |
|
147 |
#if defined(HAVE_ALPN) |
148 |
|
149 |
@@ -1168,4 +1168,4 @@ _ssl_enum_crls(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kw |
150 |
#ifndef _SSL_ENUM_CRLS_METHODDEF |
151 |
#define _SSL_ENUM_CRLS_METHODDEF |
152 |
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ |
153 |
-/*[clinic end generated code: output=56cead8610faa505 input=a9049054013a1b77]*/ |
154 |
+/*[clinic end generated code: output=a8b184655068c238 input=a9049054013a1b77]*/ |