Python _ssl.PROTOCOL_SSLv23() Examples
The following are 20
code examples of _ssl.PROTOCOL_SSLv23().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
_ssl
, or try the search function
.
Example #1
Source File: test__ssl.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_constants(self): self.assertEqual(_ssl.CERT_NONE, 0) self.assertEqual(_ssl.CERT_OPTIONAL, 1) self.assertEqual(_ssl.CERT_REQUIRED, 2) self.assertEqual(_ssl.PROTOCOL_SSLv2, 0) self.assertEqual(_ssl.PROTOCOL_SSLv23, 2) self.assertEqual(_ssl.PROTOCOL_SSLv3, 1) self.assertEqual(_ssl.PROTOCOL_TLSv1, 3) self.assertEqual(_ssl.PROTOCOL_TLSv1_1, 4) self.assertEqual(_ssl.PROTOCOL_TLSv1_2, 5) self.assertEqual(_ssl.OP_NO_SSLv2, 0x1000000) self.assertEqual(_ssl.OP_NO_SSLv3, 0x2000000) self.assertEqual(_ssl.OP_NO_TLSv1, 0x4000000) self.assertEqual(_ssl.OP_NO_TLSv1_1, 0x10000000) self.assertEqual(_ssl.OP_NO_TLSv1_2, 0x8000000) self.assertEqual(_ssl.SSL_ERROR_EOF, 8) self.assertEqual(_ssl.SSL_ERROR_INVALID_ERROR_CODE, 10) self.assertEqual(_ssl.SSL_ERROR_SSL, 1) self.assertEqual(_ssl.SSL_ERROR_SYSCALL, 5) self.assertEqual(_ssl.SSL_ERROR_WANT_CONNECT, 7) self.assertEqual(_ssl.SSL_ERROR_WANT_READ, 2) self.assertEqual(_ssl.SSL_ERROR_WANT_WRITE, 3) self.assertEqual(_ssl.SSL_ERROR_WANT_X509_LOOKUP, 4) self.assertEqual(_ssl.SSL_ERROR_ZERO_RETURN, 6)
Example #2
Source File: ssl.py From canape with GNU General Public License v3.0 | 6 votes |
def sslwrap_simple(sock, keyfile=None, certfile=None): """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" if hasattr(sock, "_sock"): sock = sock._sock ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, PROTOCOL_SSLv23, None) try: sock.getpeername() except socket_error: # no, no connection yet pass else: # yes, do the handshake ssl_sock.do_handshake() return ssl_sock
Example #3
Source File: ssl.py From RevitBatchProcessor with GNU General Public License v3.0 | 6 votes |
def sslwrap_simple(sock, keyfile=None, certfile=None): """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" if hasattr(sock, "_sock"): sock = sock._sock ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, PROTOCOL_SSLv23, None) try: sock.getpeername() except socket_error: # no, no connection yet pass else: # yes, do the handshake ssl_sock.do_handshake() return ssl_sock
Example #4
Source File: ssl.py From pmatic with GNU General Public License v2.0 | 6 votes |
def sslwrap_simple(sock, keyfile=None, certfile=None): """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" if hasattr(sock, "_sock"): sock = sock._sock ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, PROTOCOL_SSLv23, None) try: sock.getpeername() except socket_error: # no, no connection yet pass else: # yes, do the handshake ssl_sock.do_handshake() return ssl_sock
Example #5
Source File: ssl.py From BinderFilter with MIT License | 6 votes |
def sslwrap_simple(sock, keyfile=None, certfile=None): """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" if hasattr(sock, "_sock"): sock = sock._sock ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, PROTOCOL_SSLv23, None) try: sock.getpeername() except socket_error: # no, no connection yet pass else: # yes, do the handshake ssl_sock.do_handshake() return ssl_sock
Example #6
Source File: test__ssl.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_constants(self): self.assertEqual(real_ssl.CERT_NONE, 0) self.assertEqual(real_ssl.CERT_OPTIONAL, 1) self.assertEqual(real_ssl.CERT_REQUIRED, 2) self.assertEqual(real_ssl.PROTOCOL_SSLv2, 0) self.assertEqual(real_ssl.PROTOCOL_SSLv23, 2) self.assertEqual(real_ssl.PROTOCOL_SSLv3, 1) self.assertEqual(real_ssl.PROTOCOL_TLSv1, 3) self.assertEqual(real_ssl.PROTOCOL_TLSv1_1, 4) self.assertEqual(real_ssl.PROTOCOL_TLSv1_2, 5) self.assertEqual(real_ssl.OP_NO_SSLv2, 0x1000000) self.assertEqual(real_ssl.OP_NO_SSLv3, 0x2000000) self.assertEqual(real_ssl.OP_NO_TLSv1, 0x4000000) self.assertEqual(real_ssl.OP_NO_TLSv1_1, 0x10000000) self.assertEqual(real_ssl.OP_NO_TLSv1_2, 0x8000000) self.assertEqual(real_ssl.SSL_ERROR_EOF, 8) self.assertEqual(real_ssl.SSL_ERROR_INVALID_ERROR_CODE, 9) self.assertEqual(real_ssl.SSL_ERROR_SSL, 1) self.assertEqual(real_ssl.SSL_ERROR_SYSCALL, 5) self.assertEqual(real_ssl.SSL_ERROR_WANT_CONNECT, 7) self.assertEqual(real_ssl.SSL_ERROR_WANT_READ, 2) self.assertEqual(real_ssl.SSL_ERROR_WANT_WRITE, 3) self.assertEqual(real_ssl.SSL_ERROR_WANT_X509_LOOKUP, 4) self.assertEqual(real_ssl.SSL_ERROR_ZERO_RETURN, 6)
Example #7
Source File: ssl.py From meddle with MIT License | 6 votes |
def sslwrap_simple(sock, keyfile=None, certfile=None): """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" if hasattr(sock, "_sock"): sock = sock._sock ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, PROTOCOL_SSLv23, None) try: sock.getpeername() except socket_error: # no, no connection yet pass else: # yes, do the handshake ssl_sock.do_handshake() return ssl_sock
Example #8
Source File: ssl.py From BinderFilter with MIT License | 5 votes |
def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): return SSLSocket(sock, keyfile=keyfile, certfile=certfile, server_side=server_side, cert_reqs=cert_reqs, ssl_version=ssl_version, ca_certs=ca_certs, do_handshake_on_connect=do_handshake_on_connect, suppress_ragged_eofs=suppress_ragged_eofs, ciphers=ciphers) # some utility functions
Example #9
Source File: ssl.py From BinderFilter with MIT License | 5 votes |
def __init__(self, sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): socket.__init__(self, _sock=sock._sock) # The initializer for socket overrides the methods send(), recv(), etc. # in the instancce, which we don't need -- but we want to provide the # methods defined in SSLSocket. for attr in _delegate_methods: try: delattr(self, attr) except AttributeError: pass if ciphers is None and ssl_version != _SSLv2_IF_EXISTS: ciphers = _DEFAULT_CIPHERS if certfile and not keyfile: keyfile = certfile # see if it's connected try: socket.getpeername(self) except socket_error, e: if e.errno != errno.ENOTCONN: raise # no, no connection yet self._connected = False self._sslobj = None
Example #10
Source File: ssl.py From pmatic with GNU General Public License v2.0 | 5 votes |
def __init__(self, sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): socket.__init__(self, _sock=sock._sock) # The initializer for socket overrides the methods send(), recv(), etc. # in the instancce, which we don't need -- but we want to provide the # methods defined in SSLSocket. for attr in _delegate_methods: try: delattr(self, attr) except AttributeError: pass if ciphers is None and ssl_version != _SSLv2_IF_EXISTS: ciphers = _DEFAULT_CIPHERS if certfile and not keyfile: keyfile = certfile # see if it's connected try: socket.getpeername(self) except socket_error, e: if e.errno != errno.ENOTCONN: raise # no, no connection yet self._connected = False self._sslobj = None
Example #11
Source File: ssl.py From pmatic with GNU General Public License v2.0 | 5 votes |
def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): return SSLSocket(sock, keyfile=keyfile, certfile=certfile, server_side=server_side, cert_reqs=cert_reqs, ssl_version=ssl_version, ca_certs=ca_certs, do_handshake_on_connect=do_handshake_on_connect, suppress_ragged_eofs=suppress_ragged_eofs, ciphers=ciphers) # some utility functions
Example #12
Source File: ssl.py From meddle with MIT License | 5 votes |
def __init__(self, sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): socket.__init__(self, _sock=sock._sock) # The initializer for socket overrides the methods send(), recv(), etc. # in the instancce, which we don't need -- but we want to provide the # methods defined in SSLSocket. for attr in _delegate_methods: try: delattr(self, attr) except AttributeError: pass if certfile and not keyfile: keyfile = certfile # see if it's connected try: socket.getpeername(self) except socket_error, e: if e.errno != errno.ENOTCONN: raise # no, no connection yet self._connected = False self._sslobj = None
Example #13
Source File: x509.py From addon with GNU General Public License v3.0 | 5 votes |
def create_ssl_context(cert_byes, pk_bytes, password=None, encoding=Encoding.PEM): """Create an SSL Context with the supplied cert/password. :param cert_bytes array of bytes containing the cert encoded using the method supplied in the ``encoding`` parameter :param pk_bytes array of bytes containing the private key encoded using the method supplied in the ``encoding`` parameter :param password array of bytes containing the passphrase to be used with the supplied private key. None if unencrypted. Defaults to None. :param encoding ``cryptography.hazmat.primitives.serialization.Encoding`` details the encoding method used on the ``cert_bytes`` and ``pk_bytes`` parameters. Can be either PEM or DER. Defaults to PEM. """ backend = default_backend() cert = None key = None if encoding == Encoding.PEM: cert = x509.load_pem_x509_certificate(cert_byes, backend) key = load_pem_private_key(pk_bytes, password, backend) elif encoding == Encoding.DER: cert = x509.load_der_x509_certificate(cert_byes, backend) key = load_der_private_key(pk_bytes, password, backend) else: raise ValueError('Invalid encoding provided: Must be PEM or DER') if not (cert and key): raise ValueError('Cert and key could not be parsed from ' 'provided data') check_cert_dates(cert) ssl_context = PyOpenSSLContext(PROTOCOL) ssl_context._ctx.use_certificate(X509.from_cryptography(cert)) ssl_context._ctx.use_privatekey(PKey.from_cryptography_key(key)) return ssl_context
Example #14
Source File: x509.py From bazarr with GNU General Public License v3.0 | 5 votes |
def create_ssl_context(cert_byes, pk_bytes, password=None, encoding=Encoding.PEM): """Create an SSL Context with the supplied cert/password. :param cert_bytes array of bytes containing the cert encoded using the method supplied in the ``encoding`` parameter :param pk_bytes array of bytes containing the private key encoded using the method supplied in the ``encoding`` parameter :param password array of bytes containing the passphrase to be used with the supplied private key. None if unencrypted. Defaults to None. :param encoding ``cryptography.hazmat.primitives.serialization.Encoding`` details the encoding method used on the ``cert_bytes`` and ``pk_bytes`` parameters. Can be either PEM or DER. Defaults to PEM. """ backend = default_backend() cert = None key = None if encoding == Encoding.PEM: cert = x509.load_pem_x509_certificate(cert_byes, backend) key = load_pem_private_key(pk_bytes, password, backend) elif encoding == Encoding.DER: cert = x509.load_der_x509_certificate(cert_byes, backend) key = load_der_private_key(pk_bytes, password, backend) else: raise ValueError('Invalid encoding provided: Must be PEM or DER') if not (cert and key): raise ValueError('Cert and key could not be parsed from ' 'provided data') check_cert_dates(cert) ssl_context = PyOpenSSLContext(PROTOCOL) ssl_context._ctx.use_certificate(X509.from_cryptography(cert)) ssl_context._ctx.use_privatekey(PKey.from_cryptography_key(key)) return ssl_context
Example #15
Source File: ssl.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def __init__(self, sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): socket.__init__(self, _sock=sock._sock) # The initializer for socket overrides the methods send(), recv(), etc. # in the instancce, which we don't need -- but we want to provide the # methods defined in SSLSocket. for attr in _delegate_methods: try: delattr(self, attr) except AttributeError: pass if certfile and not keyfile: keyfile = certfile # see if it's connected try: socket.getpeername(self) except socket_error, e: if e.errno != errno.ENOTCONN: raise # no, no connection yet self._connected = False self._sslobj = None
Example #16
Source File: ssl.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): return SSLSocket(sock, keyfile=keyfile, certfile=certfile, server_side=server_side, cert_reqs=cert_reqs, ssl_version=ssl_version, ca_certs=ca_certs, do_handshake_on_connect=do_handshake_on_connect, suppress_ragged_eofs=suppress_ragged_eofs, ciphers=ciphers) # some utility functions
Example #17
Source File: ssl.py From canape with GNU General Public License v3.0 | 5 votes |
def __init__(self, sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): socket.__init__(self, _sock=sock._sock) # The initializer for socket overrides the methods send(), recv(), etc. # in the instancce, which we don't need -- but we want to provide the # methods defined in SSLSocket. for attr in _delegate_methods: try: delattr(self, attr) except AttributeError: pass if certfile and not keyfile: keyfile = certfile # see if it's connected try: socket.getpeername(self) except socket_error, e: if e.errno != errno.ENOTCONN: raise # no, no connection yet self._connected = False self._sslobj = None
Example #18
Source File: ssl.py From canape with GNU General Public License v3.0 | 5 votes |
def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): return SSLSocket(sock, keyfile=keyfile, certfile=certfile, server_side=server_side, cert_reqs=cert_reqs, ssl_version=ssl_version, ca_certs=ca_certs, do_handshake_on_connect=do_handshake_on_connect, suppress_ragged_eofs=suppress_ragged_eofs, ciphers=ciphers) # some utility functions
Example #19
Source File: ssl.py From meddle with MIT License | 5 votes |
def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None): return SSLSocket(sock, keyfile=keyfile, certfile=certfile, server_side=server_side, cert_reqs=cert_reqs, ssl_version=ssl_version, ca_certs=ca_certs, do_handshake_on_connect=do_handshake_on_connect, suppress_ragged_eofs=suppress_ragged_eofs, ciphers=ciphers) # some utility functions
Example #20
Source File: irc.py From CloudBot with GNU General Public License v3.0 | 4 votes |
def __init__(self, bot, name, nick, *, channels=None, config=None, server, port=6667, use_ssl=False, ignore_cert_errors=True, timeout=300, local_bind=False): """ :type bot: cloudbot.bot.CloudBot :type name: str :type nick: str :type channels: list[str] :type config: dict[str, unknown] :type server: str :type port: int :type use_ssl: bool :type ignore_cert_errors: bool :type timeout: int """ super().__init__(bot, name, nick, channels=channels, config=config) self.use_ssl = use_ssl self._ignore_cert_errors = ignore_cert_errors self._timeout = timeout self.server = server self.port = port self.local_bind = local_bind # create SSL context if self.use_ssl: self.ssl_context = SSLContext(PROTOCOL_SSLv23) if self._ignore_cert_errors: self.ssl_context.verify_mode = ssl.CERT_NONE else: self.ssl_context.verify_mode = ssl.CERT_REQUIRED else: self.ssl_context = None # if we're connected self._connected = False # if we've quit self._quit = False # transport and protocol self._transport = None self._protocol = None self.capabilities = set(self.config.get('capabilities', []))