Skip to content

Commit

Permalink
Deprecated NPN (#820)
Browse files Browse the repository at this point in the history
* Deprecated NPN

* arithmetic is hard

* oops

* oops
  • Loading branch information
alex authored and reaperhulk committed Feb 22, 2019
1 parent df2480d commit be2bd54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Backward-incompatible changes:
Deprecations:
^^^^^^^^^^^^^

*none*
- Deprecated ``OpenSSL.SSL.Context.set_npn_advertise_callback``, ``OpenSSL.SSL.Context.set_npn_select_callback``, and ``OpenSSL.SSL.Connection.get_next_proto_negotiated``.
ALPN should be used instead.
`#820 <https://github.com/pyca/pyopenssl/pull/820>`_


Changes:
Expand Down
9 changes: 9 additions & 0 deletions src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import socket
import warnings
from sys import platform
from functools import wraps, partial
from itertools import count, chain
Expand Down Expand Up @@ -626,6 +627,11 @@ def SSLeay_version(type):
return _ffi.string(_lib.SSLeay_version(type))


def _warn_npn():
warnings.warn("NPN is deprecated. Protocols should switch to using ALPN.",
DeprecationWarning, stacklevel=3)


def _make_requires(flag, error):
"""
Builds a decorator that ensures that functions that rely on OpenSSL
Expand Down Expand Up @@ -1415,6 +1421,7 @@ def set_npn_advertise_callback(self, callback):
.. versionadded:: 0.15
"""
_warn_npn()
self._npn_advertise_helper = _NpnAdvertiseHelper(callback)
self._npn_advertise_callback = self._npn_advertise_helper.callback
_lib.SSL_CTX_set_next_protos_advertised_cb(
Expand All @@ -1433,6 +1440,7 @@ def set_npn_select_callback(self, callback):
.. versionadded:: 0.15
"""
_warn_npn()
self._npn_select_helper = _NpnSelectHelper(callback)
self._npn_select_callback = self._npn_select_helper.callback
_lib.SSL_CTX_set_next_proto_select_cb(
Expand Down Expand Up @@ -2437,6 +2445,7 @@ def get_next_proto_negotiated(self):
.. versionadded:: 0.15
"""
_warn_npn()
data = _ffi.new("unsigned char **")
data_len = _ffi.new("unsigned int *")

Expand Down

0 comments on commit be2bd54

Please sign in to comment.