On this page
ssl.SSLObject
Prev: ssl.SSLErrorNumber | Up: ssl | Next: ssl.SSLSession
Rel: ssl.AlertDescription, ssl.cert_time_to_seconds, ssl.CertificateError, ssl.create_connection
Ref: docs.python.org — ssl.SSLObject
Tags: #public #python3 #stdlib #ssl
Import
import ssl
from ssl import SSLObject
Signature & Overview
ssl.SSLObject(*args, **kwargs)
This class implements an interface on top of a low-level SSL object as implemented by OpenSSL. This object captures the state of an SSL connection but does not provide any network IO itself. IO needs to be performed
Methods & Attributes
SSLObject.cipher(self)— Return the currently selected cipher as a 3-tuple(name, ssl_version, secret_bits).SSLObject.compression(self)— Return the current compression algorithm in use, orNoneif compression was not negotiated or not supported by one of the peers.SSLObject.context(...)— The SSLContext that is currently in use.SSLObject.do_handshake(self)— Start the SSL/TLS handshake.SSLObject.get_channel_binding(self, cb_type='tls-unique')— Get channel binding data for current connection. Raise ValueError if the requestedcb_typeis not supported. Return bytes of the data or None if the data is not available (e.g. before the handshake).SSLObject.get_unverified_chain(self)— Returns raw certificate chain provided by the other end of the SSL channel as a list of DER-encoded bytes.SSLObject.get_verified_chain(self)— Returns verified certificate chain provided by the other end of the SSL channel as a list of DER-encoded bytes.SSLObject.getpeercert(self, binary_form=False)— Returns a formatted version of the data in the certificate provided by the other end of the SSL channel.SSLObject.pending(self)— Return the number of bytes that can be read immediately.SSLObject.read(self, len=1024, buffer=None)— Read up to 'len' bytes from the SSL object and return them.SSLObject.selected_alpn_protocol(self)— Return the currently selected ALPN protocol as a string, orNoneif a next protocol was not negotiated or if ALPN is not supported by one of the peers.SSLObject.selected_npn_protocol(self)— Return the currently selected NPN protocol as a string, orNoneif a next protocol was not negotiated or if NPN is not supported by one of the peers.SSLObject.server_hostname(...)— The currently set server hostname (for SNI), orNoneif no server hostname is set.SSLObject.server_side(...)— Whether this is a server-side socket.SSLObject.session(...)— The SSLSession for client socket.SSLObject.session_reused(...)— Was the client session reused during handshakeSSLObject.shared_ciphers(self)— Return a list of ciphers shared by the client during the handshake or None if this is not a valid server connection.SSLObject.unwrap(self)— Start the SSL shutdown handshake.SSLObject.verify_client_post_handshake(self)—SSLObject.verify_client_post_handshakemethod/property.SSLObject.version(self)— Return a string identifying the protocol version used by the current SSL channel.SSLObject.write(self, data)— Write 'data' to the SSL object and return the number of bytes written.
Usage
import ssl
ctx = ssl.create_default_context()
in_bio, out_bio = ssl.MemoryBIO(), ssl.MemoryBIO()
obj = ctx.wrap_bio(in_bio, out_bio, server_hostname="example.com")
assert isinstance(obj, ssl.SSLObject)
Gotchas
- Created by
SSLContext.wrap_bio(): Drives TLS over in-memoryMemoryBIObuffers rather than an OS socket.
REPL Inspect
from ssl import SSLObject
help(SSLObject)
Linked from
Related notes
- tuts/python3/stdlib_module/ssl/SSLErrorNumber Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/SSLSession Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ssl/AlertDescription Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/cert_time_to_seconds Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/CertificateError Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_connection Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_default_context shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DefaultVerifyPaths shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DER_cert_to_PEM_cert shared tags: #ssl, #stdlib