665e9b
From e8ed37e0d24a1cc7482ab816ed5f25243395b2ef Mon Sep 17 00:00:00 2001
665e9b
From: Christian Heimes <cheimes@redhat.com>
665e9b
Date: Mon, 14 Dec 2020 14:13:53 +0100
665e9b
Subject: [PATCH] Revert "remove NPN bindings -- you should be using ALPN!
665e9b
 (#4765)"
665e9b
665e9b
This reverts commit 99bf4e4605cbe54bad597da1ebe4cc323909083c.
665e9b
---
665e9b
 src/_cffi_src/openssl/ssl.py          | 20 +++++++++++++++++++-
665e9b
 tests/hazmat/bindings/test_openssl.py |  4 ++++
665e9b
 2 files changed, 23 insertions(+), 1 deletion(-)
665e9b
665e9b
diff --git a/src/_cffi_src/openssl/ssl.py b/src/_cffi_src/openssl/ssl.py
665e9b
index c38e309a1..fa854f5dd 100644
665e9b
--- a/src/_cffi_src/openssl/ssl.py
665e9b
+++ b/src/_cffi_src/openssl/ssl.py
665e9b
@@ -138,6 +138,8 @@ static const long SSL3_RANDOM_SIZE;
665e9b
 static const long TLS_ST_BEFORE;
665e9b
 static const long TLS_ST_OK;
665e9b
 
665e9b
+static const long OPENSSL_NPN_NEGOTIATED;
665e9b
+
665e9b
 typedef ... SSL_METHOD;
665e9b
 typedef ... SSL_CTX;
665e9b
 
665e9b
@@ -401,9 +403,25 @@ SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *);
665e9b
 
665e9b
 long SSL_session_reused(SSL *);
665e9b
 
665e9b
+void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *,
665e9b
+                                           int (*)(SSL *,
665e9b
+                                                   const unsigned char **,
665e9b
+                                                   unsigned int *,
665e9b
+                                                   void *),
665e9b
+                                           void *);
665e9b
+void SSL_CTX_set_next_proto_select_cb(SSL_CTX *,
665e9b
+                                      int (*)(SSL *,
665e9b
+                                              unsigned char **,
665e9b
+                                              unsigned char *,
665e9b
+                                              const unsigned char *,
665e9b
+                                              unsigned int,
665e9b
+                                              void *),
665e9b
+                                      void *);
665e9b
 int SSL_select_next_proto(unsigned char **, unsigned char *,
665e9b
                           const unsigned char *, unsigned int,
665e9b
                           const unsigned char *, unsigned int);
665e9b
+void SSL_get0_next_proto_negotiated(const SSL *,
665e9b
+                                    const unsigned char **, unsigned *);
665e9b
 
665e9b
 int sk_SSL_CIPHER_num(Cryptography_STACK_OF_SSL_CIPHER *);
665e9b
 const SSL_CIPHER *sk_SSL_CIPHER_value(Cryptography_STACK_OF_SSL_CIPHER *, int);
665e9b
@@ -601,7 +619,7 @@ static const long Cryptography_HAS_TLSv1_2 = 1;
665e9b
 static const long Cryptography_HAS_SSL_OP_MSIE_SSLV2_RSA_PADDING = 1;
665e9b
 static const long Cryptography_HAS_SSL_OP_NO_TICKET = 1;
665e9b
 static const long Cryptography_HAS_SSL_SET_SSL_CTX = 1;
665e9b
-static const long Cryptography_HAS_NEXTPROTONEG = 0;
665e9b
+static const long Cryptography_HAS_NEXTPROTONEG = 1;
665e9b
 static const long Cryptography_HAS_ALPN = 1;
665e9b
 
665e9b
 #if CRYPTOGRAPHY_IS_LIBRESSL
665e9b
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
665e9b
index ecee34091..aeb12a0dc 100644
665e9b
--- a/tests/hazmat/bindings/test_openssl.py
665e9b
+++ b/tests/hazmat/bindings/test_openssl.py
665e9b
@@ -137,3 +137,7 @@ class TestOpenSSL(object):
665e9b
         )
665e9b
         with pytest.raises(RuntimeError):
665e9b
             _verify_openssl_version(lib)
665e9b
+
665e9b
+    def test_npn_binding(self):
665e9b
+        b = Binding()
665e9b
+        assert b.lib.Cryptography_HAS_NEXTPROTONEG
665e9b
-- 
665e9b
2.29.2
665e9b