Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions | Variables
pip._vendor.urllib3.contrib.pyopenssl Namespace Reference

Classes

class  PyOpenSSLContext
 
class  UnsupportedExtension
 
class  WrappedSocket
 

Functions

 inject_into_urllib3 ()
 
 extract_from_urllib3 ()
 
 _validate_dependencies_met ()
 
 _dnsname_to_stdlib (name)
 
 get_subj_alt_name (peer_cert)
 
 makefile (self, mode, bufsize=-1)
 
 _verify_callback (cnx, x509, err_no, err_depth, return_code)
 

Variables

 _fileobject = None
 
 category
 
 stacklevel
 
bool HAS_SNI = True
 
dict _openssl_versions
 
dict _stdlib_to_openssl_verify
 
 _openssl_to_stdlib_verify = dict((v, k) for k, v in _stdlib_to_openssl_verify.items())
 
int SSL_WRITE_BLOCKSIZE = 16384
 
bool orig_util_HAS_SNI = util.HAS_SNI
 
 orig_util_SSLContext = util.ssl_.SSLContext
 
 log = logging.getLogger(__name__)
 
 makefile = backport_makefile
 

Detailed Description

TLS with SNI_-support for Python 2. Follow these instructions if you would
like to verify TLS certificates in Python 2. Note, the default libraries do
*not* do certificate checking; you need to do additional work to validate
certificates yourself.

This needs the following packages installed:

* `pyOpenSSL`_ (tested with 16.0.0)
* `cryptography`_ (minimum 1.3.4, from pyopenssl)
* `idna`_ (minimum 2.0, from cryptography)

However, pyopenssl depends on cryptography, which depends on idna, so while we
use all three directly here we end up having relatively few packages required.

You can install them with the following command:

.. code-block:: bash

    $ python -m pip install pyopenssl cryptography idna

To activate certificate checking, call
:func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code
before you begin making HTTP requests. This can be done in a ``sitecustomize``
module, or at any other time before your application begins using ``urllib3``,
like this:

.. code-block:: python

    try:
        import pip._vendor.urllib3.contrib.pyopenssl as pyopenssl
        pyopenssl.inject_into_urllib3()
    except ImportError:
        pass

Now you can use :mod:`urllib3` as you normally would, and it will support SNI
when the required modules are installed.

Activating this module also has the positive side effect of disabling SSL/TLS
compression in Python 2 (see `CRIME attack`_).

.. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit)
.. _pyopenssl: https://www.pyopenssl.org
.. _cryptography: https://cryptography.io
.. _idna: https://github.com/kjd/idna

Function Documentation

◆ _dnsname_to_stdlib()

pip._vendor.urllib3.contrib.pyopenssl._dnsname_to_stdlib (   name)
protected
Converts a dNSName SubjectAlternativeName field to the form used by the
standard library on the given Python version.

Cryptography produces a dNSName as a unicode string that was idna-decoded
from ASCII bytes. We need to idna-encode that string to get it back, and
then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib
uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8).

If the name cannot be idna-encoded then we return None signalling that
the name given should be skipped.

◆ _validate_dependencies_met()

pip._vendor.urllib3.contrib.pyopenssl._validate_dependencies_met ( )
protected
Verifies that PyOpenSSL's package-level dependencies have been met.
Throws `ImportError` if they are not met.

◆ get_subj_alt_name()

pip._vendor.urllib3.contrib.pyopenssl.get_subj_alt_name (   peer_cert)
Given an PyOpenSSL certificate, provides all the subject alternative names.

Variable Documentation

◆ _openssl_versions

dict pip._vendor.urllib3.contrib.pyopenssl._openssl_versions
protected
Initial value:
1= {
2 util.PROTOCOL_TLS: OpenSSL.SSL.SSLv23_METHOD,
3 PROTOCOL_TLS_CLIENT: OpenSSL.SSL.SSLv23_METHOD,
4 ssl.PROTOCOL_TLSv1: OpenSSL.SSL.TLSv1_METHOD,
5}

◆ _stdlib_to_openssl_verify

dict pip._vendor.urllib3.contrib.pyopenssl._stdlib_to_openssl_verify
protected
Initial value:
1= {
2 ssl.CERT_NONE: OpenSSL.SSL.VERIFY_NONE,
3 ssl.CERT_OPTIONAL: OpenSSL.SSL.VERIFY_PEER,
4 ssl.CERT_REQUIRED: OpenSSL.SSL.VERIFY_PEER
5 + OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
6}