tlslite.messages module
Classes representing TLS messages.
- class tlslite.messages.Certificate(certificateType, version=(3, 2))[source]
Bases:
HandshakeMsg
- property cert_chain
Getter for the cert_chain property.
- class tlslite.messages.CertificateEntry(certificateType)[source]
Bases:
object
Object storing a single certificate from TLS 1.3.
Stores a certificate (or possibly a raw public key) together with associated extensions
- class tlslite.messages.CertificateRequest(version)[source]
Bases:
HelloMessage
- create(certificate_types=None, certificate_authorities=None, sig_algs=None, context=b'', extensions=None)[source]
Creates a Certificate Request message. For TLS 1.3 only the context and extensions parameters should be provided, the others are ignored. For TLS versions below 1.3 instead only the first three parameters are considered.
- property supported_signature_algs
Returns the list of supported algorithms.
We store the list in an extension even for TLS < 1.3 Extensions are used/valid only for TLS 1.3 but they are a good unified storage mechanism for all versions.
- class tlslite.messages.CertificateStatus[source]
Bases:
HandshakeMsg
Handling of the CertificateStatus message from RFC 6066.
Handling of the handshake protocol message that includes the OCSP staple.
- Variables:
- class tlslite.messages.CertificateVerify(version)[source]
Bases:
HandshakeMsg
Serializer for TLS handshake protocol Certificate Verify message.
- create(signature, signatureAlgorithm=None)[source]
Provide data for serialisation of message.
- Parameters:
signature – signature carried in the message
signatureAlgorithm – signature algorithm used to make the signature (TLSv1.2 only)
- class tlslite.messages.ClientFinished[source]
Bases:
SSL2Finished
Handling of SSLv2 CLIENT-FINISHED message.
- Variables:
verify_data (bytearray) – payload of the message, should be the CONNECTION-ID
- class tlslite.messages.ClientHello(ssl2=False)[source]
Bases:
HelloMessage
Class for handling the ClientHello SSLv2/SSLv3/TLS message.
- Variables:
certificate_types (list) – list of supported certificate types (deprecated)
srp_username (bytearray) – name of the user in SRP extension (deprecated)
~.supports_npn (boolean) – NPN extension presence (deprecated)
~.tack (boolean) – TACK extension presence (deprecated)
~.server_name (bytearray) – first host_name (type 0) present in SNI extension (deprecated)
extensions (list of
TLSExtension
) – list of TLS extensions parsed from wire or to send, seeTLSExtension
and child classes for exact examples
- property certificate_types
Return the list of certificate types supported.
Deprecated since version 0.5: use extensions field to get the extension for inspection
- create(version, random, session_id, cipher_suites, certificate_types=None, srpUsername=None, tack=False, supports_npn=None, serverName=None, extensions=None)[source]
Create a ClientHello message for sending.
- Parameters:
version (tuple) – the highest supported TLS version encoded as two int tuple
random (bytearray) – client provided random value, in old versions of TLS (before 1.2) the first 32 bits should include system time, also used as the “challenge” field in SSLv2
session_id (bytearray) – ID of session, set when doing session resumption
cipher_suites (list) – list of ciphersuites advertised as supported
certificate_types (list) – list of supported certificate types, uses TLS extension for signalling, as such requires TLS1.0 to work
srpUsername (bytearray) – utf-8 encoded username for SRP, TLS extension
tack (boolean) – whatever to advertise support for TACK, TLS extension
supports_npn (boolean) – whatever to advertise support for NPN, TLS extension
serverName (bytearray) – the hostname to request in server name indication extension, TLS extension. Note that SNI allows to set multiple hostnames and values that are not hostnames, use
SNIExtension
together withextensions
to use it.extensions (list of
TLSExtension
) – list of extensions to advertise
- psk_truncate()[source]
Return a truncated encoding of message without binders.
In TLS 1.3, with PSK exchange, the ClientHello message is signed by the binders in it. Return the part that is symmetrically signed by those binders.
See “PSK Binder” in draft-ietf-tls-tls13-23.
- Return type:
- property server_name
Return first host_name present in SNI extension.
Deprecated since version 0.5: use extensions field to get the extension for inspection
- Return type:
- property srp_username
Return username for the SRP.
Deprecated since version 0.5: use extensions field to get the extension for inspection
- property supports_npn
Return whether client supports NPN extension.
Deprecated since version 0.5: use extensions field to get the extension for inspection
- Return type:
boolean
- property tack
Return whether the client supports TACK.
Deprecated since version 0.5: use extensions field to get the extension for inspection
- Return type:
boolean
- class tlslite.messages.ClientKeyExchange(cipherSuite, version=None)[source]
Bases:
HandshakeMsg
Handling of TLS Handshake protocol ClientKeyExchange message.
- Variables:
cipherSuite (int) – the cipher suite id used for the connection
~.version (tuple(int, int)) – TLS protocol version used for the connection
srp_A (int) – SRP protocol client answer value
dh_Yc (int) – client Finite Field Diffie-Hellman protocol key share
ecdh_Yc (bytearray) – encoded curve coordinates
encryptedPreMasterSecret (bytearray) – client selected PremMaster secret encrypted with server public key (from certificate)
- createRSA(encryptedPreMasterSecret)[source]
Set the encrypted PreMaster Secret.
returns self
- Return type:
- createSRP(srp_A)[source]
Set the SRP client answer.
returns self
- Parameters:
srp_A (int) – client SRP answer
- Return type:
- class tlslite.messages.ClientMasterKey[source]
Bases:
HandshakeMsg
Handling of SSLv2 CLIENT-MASTER-KEY message.
- Variables:
- class tlslite.messages.EncryptedExtensions[source]
Bases:
HelloMessage
Handling of the TLS1.3 Encrypted Extensions message.
- class tlslite.messages.Finished(version, hash_length=None)[source]
Bases:
HandshakeMsg
- class tlslite.messages.Heartbeat[source]
Bases:
object
Handling Heartbeat messages from RFC 6520
- Variables:
message_type – type of message (response or request)
payload – payload
padding – random padding of selected length
- create(message_type, payload, padding_length)[source]
Create heartbeat request or response with selected parameters
- class tlslite.messages.HelloMessage(*args, **kwargs)[source]
Bases:
HandshakeMsg
Class for sharing code between
ClientHello
andServerHello
.- addExtension(ext)[source]
Add extension to internal list of extensions.
- Parameters:
ext (TLSExtension) – extension object to add to list
- getExtension(extType)[source]
Return extension of given type if present, None otherwise.
- Return type:
- Raises:
TLSInternalError – when there are multiple extensions of the same type
- class tlslite.messages.HelloRequest[source]
Bases:
HandshakeMsg
Handling of Hello Request messages.
- class tlslite.messages.KeyUpdate[source]
Bases:
HandshakeMsg
Handling KeyUpdate message from RFC 8446
- Variables:
message_type (int) – type of message (update_not_requested or update_requested)
- class tlslite.messages.Message(contentType, data)[source]
Bases:
object
Generic TLS message.
- class tlslite.messages.NewSessionTicket[source]
Bases:
HelloMessage
Handling of the TLS1.3 New Session Ticket message.
- class tlslite.messages.NewSessionTicket1_0[source]
Bases:
HelloMessage
Handling of the TLS1.0-TLS1.2 NewSessionTicket message.
- class tlslite.messages.NextProtocol[source]
Bases:
HandshakeMsg
- class tlslite.messages.RecordHeader(ssl2)[source]
Bases:
object
Generic interface to SSLv2 and SSLv3 (and later) record headers.
- class tlslite.messages.RecordHeader2[source]
Bases:
RecordHeader
SSLv2 record header.
- Variables:
padding (int) – number of bytes added at end of message to make it multiple of block cipher size
securityEscape (boolean) – whether the record contains a security escape message
- class tlslite.messages.RecordHeader3[source]
Bases:
RecordHeader
SSLv3 (and later) TLS record header.
- property typeName
- class tlslite.messages.SSL2Finished(msg_type)[source]
Bases:
HandshakeMsg
Handling of the SSL2 FINISHED messages.
- class tlslite.messages.ServerFinished[source]
Bases:
SSL2Finished
Handling of SSLv2 SERVER-FINISHED message.
- Variables:
verify_data (bytearray) – payload of the message, should be SESSION-ID
- class tlslite.messages.ServerHello[source]
Bases:
HelloMessage
Handling of Server Hello messages.
- Variables:
server_version (tuple) – protocol version encoded as two int tuple
random (bytearray) – server random value
session_id (bytearray) – session identifier for resumption
cipher_suite (int) – server selected cipher_suite
compression_method (int) – server selected compression method
next_protos (list of bytearray) – list of advertised protocols in NPN extension
next_protos_advertised (list of bytearray) – list of protocols advertised in NPN extension
certificate_type (int) – certificate type selected by server
extensions (list) – list of TLS extensions present in server_hello message, see
TLSExtension
and child classes for exact examples
- create(version, random, session_id, cipher_suite, certificate_type=None, tackExt=None, next_protos_advertised=None, extensions=None)[source]
Initialize the object for deserialisation.
- property next_protos
Return the advertised protocols in NPN extension.
- Return type:
list of bytearrays
- property next_protos_advertised
Return the advertised protocols in NPN extension.
- Return type:
list of bytearrays
- property tackExt
Return the TACK extension.
- class tlslite.messages.ServerHello2[source]
Bases:
HandshakeMsg
SERVER-HELLO message from SSLv2.
- Variables:
session_id_hit (int) – non zero if the client provided session ID was matched in server’s session cache
certificate_type (int) – type of certificate sent
server_version (tuple of ints) – protocol version selected by server
certificate (bytearray) – certificate sent by server
ciphers (array of int) – list of ciphers supported by server
session_id (bytearray) – idendifier of negotiated session
- class tlslite.messages.ServerHelloDone[source]
Bases:
HandshakeMsg
- class tlslite.messages.ServerKeyExchange(cipherSuite, version)[source]
Bases:
HandshakeMsg
Handling TLS Handshake protocol Server Key Exchange messages.
- Variables:
cipherSuite (int) – id of ciphersuite selected in Server Hello message
srp_N (int) – SRP protocol prime
srp_N_len (int) – length of srp_N in bytes
srp_g (int) – SRP protocol generator
srp_g_len (int) – length of srp_g in bytes
srp_s (bytearray) – SRP protocol salt value
srp_B (int) – SRP protocol server public value
srp_B_len (int) – length of srp_B in bytes
dh_p (int) – FFDHE protocol prime
dh_p_len (int) – length of dh_p in bytes
dh_g (int) – FFDHE protocol generator
dh_g_len (int) – length of dh_g in bytes
dh_Ys (int) – FFDH protocol server key share
dh_Ys_len (int) – length of dh_Ys in bytes
curve_type (int) – Type of curve used (explicit, named, etc.)
named_curve (int) – TLS ID of named curve
ecdh_Ys (bytearray) – ECDH protocol encoded point key share
signature (bytearray) – signature performed over the parameters by server
hashAlg (int) – id of hash algorithm used for signature
signAlg (int) – id of signature algorithm used for signature
- __init__(cipherSuite, version)[source]
Initialise Server Key Exchange for reading or writing.
- Parameters:
cipherSuite (int) – id of ciphersuite selected by server
- class tlslite.messages.SessionTicketPayload[source]
Bases:
object
Serialisation and deserialisation of server state for resumption.
This is the internal (meant to be encrypted) representation of server state that is sent to the client in the NewSessionTicket message.
- Variables:
~.version (int) – implementation detail for forward compatibility
master_secret (bytearray) – master secret for TLS 1.2-, resumption master secret for TLS 1.3
protocol_version (tuple) – version of protocol that was previously negotiated in this session
cipher_suite (int) – numerical ID of ciphersuite that was negotiated previously
nonce (bytearray) – nonce for TLS 1.3 KDF
creation_time (int) – Unix time in seconds when was the ticket created
client_cert_chain (X509CertChain) – Client X509 Certificate Chain
encrypt_then_mac (bool) – The session used the encrypt_then_mac extension
extended_master_secret (bool) – The session used the extended_master_secret extension
- property client_cert_chain
Getter for the client_cert_chain property.
- tlslite.messages.bytes_to_int(bytes, byteorder='big', *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Indicates whether two’s complement is used to represent the integer.