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
5
#
include
"qsslkeyingmaterial.h"
6
7
#
ifndef
QT_NO_DEBUG_STREAM
8
#
include
<
QtCore
/
qdebug
.
h
>
9
#
endif
10
#
include
<
QtCore
/
qhashfunctions
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
/*!
15
\class QSslKeyingMaterial
16
\since 6.12
17
18
\brief Describes exported keying material derived from a TLS session.
19
20
\reentrant
21
\ingroup network
22
\ingroup ssl
23
\inmodule QtNetwork
24
\compares equality
25
26
QSslKeyingMaterial represents a request for keying material derived
27
from an established TLS connection using the TLS exporter mechanism.
28
29
The exporter mechanism is defined in RFC 5705 for TLS 1.2 and earlier
30
and in RFC 8446 for TLS 1.3. It allows applications to derive
31
cryptographically separate keying material from the TLS session
32
without exposing the session's traffic keys.
33
34
Each QSslKeyingMaterial object specifies:
35
\list
36
\li an exporter label identifying the purpose of the derived
37
keying material
38
\li an optional context value binding the keying material to
39
application-specific data
40
\li the desired size of the exported keying material
41
\endlist
42
43
The actual keying material is derived by the TLS backend after a
44
successful handshake and can be retrieved via value().
45
46
QSslKeyingMaterial objects are typically configured via
47
QSslConfiguration::setKeyingMaterial() before initiating a TLS
48
connection.
49
50
Example: Deterministic export on client and server
51
\code
52
// Both client and server configure the same label and optional context
53
QSslKeyingMaterial keying("session-label", 32, "app-specific-context");
54
55
// After the TLS handshake completes get data from QSslConfiguration.
56
QByteArray derived = sslConfiguration().keyingMaterial(keying)->value();
57
58
// Both client and server will obtain the same 'derived' bytes
59
// even though they each performed the derivation independently.
60
qDebug() << "Derived keying material:" << derived;
61
\endcode
62
*/
63
64
/*!
65
\fn QSslKeyingMaterial::QSslKeyingMaterial()
66
67
Default-constructs an instance of QSslKeyingMaterial.
68
69
A default instance is never valid.
70
71
\sa isValid()
72
*/
73
74
/*!
75
\fn explicit QSslKeyingMaterial::QSslKeyingMaterial(const QByteArray &label, qsizetype size)
76
\fn explicit QSslKeyingMaterial::QSslKeyingMaterial(const QByteArray &label, qsizetype size, const QByteArray &context)
77
78
Constructs a QSslKeyingMaterial object with the given exporter
79
\a label, output \a size, and optional \a context.
80
81
The \a label identifies the purpose of the exported keying material
82
and must be non-empty. The \a size specifies the number of bytes
83
to be derived from the TLS exporter.
84
85
The optional \a context is application-defined data that is mixed
86
into the key derivation process to provide domain separation.
87
88
The keying material itself is not generated until a TLS handshake
89
has completed successfully.
90
91
\note Under TLS 1.2 (RFC 5705), a null context and an empty (non-null)
92
context produce different keying material: the context length field is
93
omitted entirely when no context is present, yielding a different PRF
94
input. Under TLS 1.3 (RFC 8446), an absent context and an empty context
95
are defined to be equivalent and produce the same keying material.
96
Use \l{QByteArray::isNull()} to distinguish them.
97
98
\sa isValid(), label(), context(), value()
99
*/
100
101
/*!
102
\fn bool QSslKeyingMaterial::isValid() const noexcept
103
104
Returns true if this QSslKeyingMaterial object describes a valid
105
exporter request.
106
107
A QSslKeyingMaterial object is considered valid if it has a
108
non-empty exporter label and a positive output size.
109
110
\sa label(), value()
111
*/
112
113
/*!
114
\fn QByteArray QSslKeyingMaterial::label() const noexcept
115
116
Returns the exporter label used for deriving the keying material.
117
118
The label identifies the purpose of the exported keying material
119
and is included verbatim in the TLS exporter derivation.
120
121
\sa context(), value()
122
*/
123
124
/*!
125
\fn QByteArray QSslKeyingMaterial::context() const noexcept
126
127
Returns the optional context value used for deriving the keying material.
128
129
The context value binds the exported keying material to
130
application-specific data and helps prevent accidental reuse of
131
identical keys across different purposes.
132
133
If no context was specified, a null/empty QByteArray is returned (see
134
\l{QSslKeyingMaterial::QSslKeyingMaterial()}).
135
136
\sa label(), value()
137
*/
138
139
/*!
140
\fn QByteArray QSslKeyingMaterial::value() const noexcept
141
142
Returns the exported keying material.
143
144
The returned QByteArray contains the keying material derived from
145
the TLS session using the configured exporter label and context.
146
147
If the TLS handshake has not completed successfully or if the TLS
148
backend does not support key exporters, this function returns an
149
empty value.
150
151
\note The contents of the returned keying material are
152
security-sensitive and must be handled with care.
153
154
\sa label(), context(), requestedSize()
155
*/
156
157
/*!
158
\fn qsizetype QSslKeyingMaterial::requestedSize() const noexcept
159
160
The desired size of the keying material.
161
162
The desired size is the number of bytes the handshake protocol
163
is asked to generate for the purpose described by the \l label()
164
and \l context() of the requested keying material.
165
166
\sa value()
167
*/
168
169
/*!
170
\fn void QSslKeyingMaterial::swap(QSslKeyingMaterial &other) noexcept
171
\memberswap{keying material}
172
*/
173
174
/*!
175
\fn size_t qHash(const QSslKeyingMaterial &key) noexcept
176
\fn size_t qHash(const QSslKeyingMaterial &key, size_t seed) noexcept
177
\qhashold{QHash}
178
*/
179
size_t qHash(
const
QSslKeyingMaterial &material, size_t seed)
noexcept
180
{
181
return
qHashMulti(seed, material.keyingLabel, material.keyingContext, material.keyingValue,
182
material.keyingValueSize);
183
}
184
185
#
ifndef
QT_NO_DEBUG_STREAM
186
/*!
187
\relates QSslKeyingMaterial
188
189
Writes a textual representation of the keying material \a keying
190
to the debug object \a debug.
191
192
\sa {Debugging Techniques}
193
*/
194
QDebug operator<<(QDebug debug,
const
QSslKeyingMaterial
&keying)
195
{
196
QDebugStateSaver saver(debug);
197
debug.resetFormat().nospace();
198
debug <<
"QSslKeyingMaterial("
199
<< keying.label() <<
','
<< keying.context()
200
<<
", requested size: "
<< keying.requestedSize()
201
<<
", actual size: "
<< keying.value().size() <<
')'
;
202
return
debug;
203
}
204
#
endif
205
206
QT_END_NAMESPACE
QSslKeyingMaterial
Describes exported keying material derived from a TLS session.
Definition
qsslkeyingmaterial.h:26
qtbase
src
network
ssl
qsslkeyingmaterial.cpp
Generated on
for Qt by
1.16.1