Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsslkeyingmaterial.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Governikus GmbH & Co. KG.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7#include "qsslsocket_p.h"
8
9#ifndef QT_NO_DEBUG_STREAM
10#include <QDebug>
11#endif
12
14
15QT_IMPL_METATYPE_EXTERN(QSslKeyingMaterial)
16
17/*!
18 \class QSslKeyingMaterial
19 \since 6.12
20
21 \brief Describes exported keying material derived from a TLS session.
22
23 \reentrant
24 \ingroup network
25 \ingroup ssl
26 \inmodule QtNetwork
27
28 QSslKeyingMaterial represents a request for keying material derived
29 from an established TLS connection using the TLS exporter mechanism.
30
31 The exporter mechanism is defined in RFC 5705 for TLS 1.2 and earlier
32 and in RFC 8446 for TLS 1.3. It allows applications to derive
33 cryptographically separate keying material from the TLS session
34 without exposing the session's traffic keys.
35
36 Each QSslKeyingMaterial object specifies:
37 \list
38 \li an exporter label identifying the purpose of the derived
39 keying material
40 \li an optional context value binding the keying material to
41 application-specific data
42 \li the desired size of the exported keying material
43 \endlist
44
45 The actual keying material is derived by the TLS backend after a
46 successful handshake and can be retrieved via value().
47
48 QSslKeyingMaterial objects are typically configured via
49 QSslConfiguration::setKeyingMaterial() before initiating a TLS
50 connection.
51
52 Example: Deterministic export on client and server
53 \code
54 // Both client and server configure the same label and optional context
55 QSslKeyingMaterial keying("session-label", 32, "app-specific-context");
56
57 // After the TLS handshake completes get data from QSslConfiguration.
58 QByteArray derived = sslConfiguration().keyingMaterial(keying)->value();
59
60 // Both client and server will obtain the same 'derived' bytes
61 // even though they each performed the derivation independently.
62 qDebug() << "Derived keying material:" << derived;
63 \endcode
64*/
65
66/*!
67 \fn explicit QSslKeyingMaterial::QSslKeyingMaterial(const QByteArray &label, int size, const QByteArray &context) noexcept
68
69 Constructs a QSslKeyingMaterial object with the given exporter
70 \a label, output \a size, and optional \a context.
71
72 The \a label identifies the purpose of the exported keying material
73 and must be non-empty. The \a size specifies the number of bytes
74 to be derived from the TLS exporter.
75
76 The optional \a context is application-defined data that is mixed
77 into the key derivation process to provide domain separation.
78
79 The keying material itself is not generated until a TLS handshake
80 has completed successfully.
81
82 \sa isValid(), label(), context(), value()
83*/
84
85/*!
86 \fn bool QSslKeyingMaterial::isValid() const noexcept
87
88 Returns true if this QSslKeyingMaterial object describes a valid
89 exporter request.
90
91 A QSslKeyingMaterial object is considered valid if it has a
92 non-empty exporter label and a positive output size.
93
94 \sa label(), value()
95*/
96
97/*!
98 \fn QByteArray QSslKeyingMaterial::label() const noexcept
99
100 Returns the exporter label used for deriving the keying material.
101
102 The label identifies the purpose of the exported keying material
103 and is included verbatim in the TLS exporter derivation.
104
105 \sa context(), value()
106*/
107
108/*!
109 \fn QByteArray QSslKeyingMaterial::context() const noexcept
110
111 Returns the optional context value used for deriving the keying material.
112
113 The context value binds the exported keying material to
114 application-specific data and helps prevent accidental reuse of
115 identical keys across different purposes.
116
117 If no context was specified, an empty QByteArray is returned.
118
119 \sa label(), value()
120*/
121
122/*!
123 \fn QByteArray QSslKeyingMaterial::value() const noexcept
124
125 Returns the exported keying material.
126
127 The returned QByteArray contains the keying material derived from
128 the TLS session using the configured exporter label and context.
129
130 If the TLS handshake has not completed successfully or if the TLS
131 backend does not support key exporters, this function returns an
132 empty value.
133
134 \note The contents of the returned keying material are#
135 security-sensitive and must be handled with care.
136
137 \sa label(), context(), size()
138*/
139
140/*!
141 \fn int QSslKeyingMaterial::size() const noexcept
142
143 The desired size of the keying material.
144
145 The desired size is the number of bytes the handshake protocol
146 is asked to generate for the purpose described by the \l label()
147 and \l context() of the requested keying material.
148
149 \sa value()
150*/
151
152#ifndef QT_NO_DEBUG_STREAM
153/*!
154 \relates QSslKeyingMaterial
155
156 Writes a textual representation of the keying material \a keying
157 to the debug object \a debug.
158
159 \sa {Debugging Techniques}
160*/
161QDebug operator<<(QDebug debug, QSslKeyingMaterial keying)
162{
163 QDebugStateSaver saver(debug);
164 debug.resetFormat().nospace();
165 debug << "QSslKeyingMaterial("
166 << keying.label() << ',' << keying.context()
167 << ", requested size: " << keying.size()
168 << ", actual size: " << keying.value().size() << ')';
169 return debug;
170}
171#endif
172
173QT_END_NAMESPACE
Combined button and popup list for selecting options.