PySide6.QtNetwork.QSslKeyingMaterial¶
- class QSslKeyingMaterial¶
Describes exported keying material derived from a TLS session. More…
Added in version 6.12.
Synopsis¶
Methods¶
def
__init__()def
clone()def
context()def
isValid()def
label()def
__ne__()def
__eq__()def
requestedSize()def
swap()def
value()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
QSslKeyingMaterialrepresents a request for keying material derived from an established TLS connection using the TLS exporter mechanism.The exporter mechanism is defined in RFC 5705 for TLS 1.2 and earlier and in RFC 8446 for TLS 1.3. It allows applications to derive cryptographically separate keying material from the TLS session without exposing the session’s traffic keys.
Each
QSslKeyingMaterialobject specifies:an exporter label identifying the purpose of the derived keying material
an optional context value binding the keying material to application-specific data
the desired size of the exported keying material
The actual keying material is derived by the TLS backend after a successful handshake and can be read with
value().QSslKeyingMaterialobjects are typically configured viasetKeyingMaterial()before initiating a TLS connection.Example: Deterministic export on client and server
// Both client and server configure the same label and optional context QSslKeyingMaterial keying("session-label", 32, "app-specific-context"); // After the TLS handshake completes get data from QSslConfiguration. QByteArray derived = sslConfiguration().takeKeyingMaterial(keying)->value(); // Both client and server will obtain the same 'derived' bytes // even though they each performed the derivation independently. use(derived);
Security Considerations¶
Exported keying material is a secret. QByteArray is a copy-on-write container, so every
QSslKeyingMaterialobject holding a value shares one buffer, and the secret remains in memory for as long as any of those objects lives. An application that needs to guarantee it holds the only remaining reference must release the Qt-internal ones explicitly.After a successful handshake the value lives in exactly one place inside Qt: the
QSslKeyingMaterialentry in the socket’s internalQSslConfiguration. EachQSslConfigurationreturned bysslConfiguration()is an independent copy of that configuration, sharing the value’s buffer with it.Both
takeKeyingMaterial()overloads hand the values over instead of sharing them: what they return holds the only reference to the value, and the entries they leave behind in the configuration they were called on are valuelessclones. Copy the value out of the returned object withvalue()and let the object itself go out of scope, then write the configuration back to the socket: that overwrites the socket’s entry with the valueless one, dropping the last reference Qt holds.QSslConfiguration config = socket->sslConfiguration(); // Copy the value out of the temporary that owns it, and let it die: QByteArray secret = config.takeKeyingMaterial(request)->value(); // Overwrite the socket's copy with the entry left behind, which has no value: socket->setSslConfiguration(config);
The following copies are outside the socket’s control and must be dealt with separately:
Any other
QSslConfigurationcopy the application still holds, including one stored in aQNetworkRequestor installed withsetDefaultConfiguration(). Taking the value from one copy does not affect the others.A configuration that was never written back to the socket. Taking the values out of a
QSslConfigurationonly strips that copy of the configuration; the socket keeps its own until it is given the valueless entries.Any
QSslKeyingMaterialcopy the application made itself. Useclone()when a copy of a request is needed without its value.
The socket also drops the values when it starts a new handshake, because its entries are reset to valueless clones then, and when it is destroyed. Neither replaces the explicit step above for a socket that stays alive.
- __init__()¶
Default-constructs an instance of
QSslKeyingMaterial.A default instance is never valid.
See also
- __init__(other)
- Parameters:
other –
QSslKeyingMaterial
- __init__(label, size)
- Parameters:
label –
QByteArraysize – int
Constructs a
QSslKeyingMaterialobject with the given exporterlabel, outputsize, and optionalcontext.The
labelidentifies the purpose of the exported keying material and must be non-empty. Thesizespecifies the number of bytes to be derived from the TLS exporter.The optional
contextis application-defined data that is mixed into the key derivation process to provide domain separation.The keying material itself is not generated until a TLS handshake has completed successfully.
Note
Under TLS 1.2 (RFC 5705), a null context and an empty (non-null) context produce different keying material: the context length field is omitted entirely when no context is present, yielding a different PRF input. Under TLS 1.3 (RFC 8446), an absent context and an empty context are defined to be equivalent and produce the same keying material. Use QByteArray::isNull() to distinguish them.
- __init__(label, size, context)
- Parameters:
label –
QByteArraysize – int
context –
QByteArray
Constructs a
QSslKeyingMaterialobject with the given exporterlabel, outputsize, and optionalcontext.The
labelidentifies the purpose of the exported keying material and must be non-empty. Thesizespecifies the number of bytes to be derived from the TLS exporter.The optional
contextis application-defined data that is mixed into the key derivation process to provide domain separation.The keying material itself is not generated until a TLS handshake has completed successfully.
Note
Under TLS 1.2 (RFC 5705), a null context and an empty (non-null) context produce different keying material: the context length field is omitted entirely when no context is present, yielding a different PRF input. Under TLS 1.3 (RFC 8446), an absent context and an empty context are defined to be equivalent and produce the same keying material. Use QByteArray::isNull() to distinguish them.
- clone()¶
- Return type:
Returns a copy of this keying material request, without its
value().The returned object carries the exporter
label(),context()andrequestedSize(), so it can be used to request the same keying material again, but itsvalue()is empty. Use it to initialize a copy, or to reset an entry, without carrying the value along.See also
- context()¶
- Return type:
Returns the optional context value used for deriving the keying material.
The context value binds the exported keying material to application-specific data and helps prevent accidental reuse of identical keys across different purposes.
If no context was specified, a null/empty QByteArray is returned (see
QSslKeyingMaterial()).- isValid()¶
- Return type:
bool
Returns true if this
QSslKeyingMaterialobject describes a valid exporter request.A
QSslKeyingMaterialobject is considered valid if it has a non-empty exporter label and a positive output size.- label()¶
- Return type:
Returns the exporter label used for deriving the keying material.
The label identifies the purpose of the exported keying material and is included verbatim in the TLS exporter derivation.
- __ne__(rhs)¶
- Parameters:
rhs –
QSslKeyingMaterial- Return type:
bool
- __eq__(rhs)¶
- Parameters:
rhs –
QSslKeyingMaterial- Return type:
bool
- requestedSize()¶
- Return type:
int
The desired size of the keying material.
The desired size is the number of bytes the handshake protocol is asked to generate for the purpose described by the
label()andcontext()of the requested keying material.See also
- swap(other)¶
- Parameters:
other –
QSslKeyingMaterial
Swaps this keying material with
other. This operation is very fast and never fails.- value()¶
- Return type:
Returns the exported keying material.
The returned QByteArray contains the keying material derived from the TLS session using the configured exporter label and context.
If the TLS handshake has not completed successfully or if the TLS backend does not support key exporters, this function returns an empty value.
Note
The contents of the returned keying material are security-sensitive and must be handled with care. See
Security Considerationsfor how to keep the returned QByteArray the only copy of it.See also