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
qocspresponse.cpp
Go to the documentation of this file.
1// Copyright (C) 2011 Richard J. Moore <rich@kde.org>
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
8
10
11QT_BEGIN_NAMESPACE
12
13QT_IMPL_METATYPE_EXTERN(QOcspResponse)
14
15/*!
16 \class QOcspResponse
17 \brief This class represents Online Certificate Status Protocol response.
18 \since 5.13
19
20 \ingroup network
21 \ingroup ssl
22 \inmodule QtNetwork
23
24 The QOcspResponse class represents the revocation status of a server's certificate,
25 received by the client-side socket during the TLS handshake. QSslSocket must be
26 configured with OCSP stapling enabled.
27
28 \sa QSslSocket, QSslSocket::ocspResponses(), certificateStatus(),
29 revocationReason(), responder(), subject(), QOcspCertificateStatus, QOcspRevocationReason,
30 QSslConfiguration::setOcspStaplingEnabled(), QSslConfiguration::ocspStaplingEnabled(),
31 QSslConfiguration::peerCertificate()
32*/
33
34/*!
35 \enum QOcspCertificateStatus
36 \brief Describes the Online Certificate Status
37 \relates QOcspResponse
38 \since 5.13
39
40 \ingroup network
41 \ingroup ssl
42 \inmodule QtNetwork
43
44 \value Good The certificate is not revoked, but this does not necessarily
45 mean that the certificate was ever issued or that the time at which
46 the response was produced is within the certificate's validity interval.
47 \value Revoked This state indicates that the certificate has been revoked
48 (either permanently or temporarily - on hold).
49 \value Unknown This state indicates that the responder doesn't know about
50 the certificate being requested.
51
52 \sa QOcspRevocationReason
53*/
54
55/*!
56 \enum QOcspRevocationReason
57 \brief Describes the reason for revocation
58 \relates QOcspResponse
59 \since 5.13
60
61 \ingroup network
62 \ingroup ssl
63 \inmodule QtNetwork
64
65
66 This enumeration describes revocation reasons, defined in \l{RFC 5280, section 5.3.1}
67
68 \value None
69 \value Unspecified
70 \value KeyCompromise
71 \value CACompromise
72 \value AffiliationChanged
73 \value Superseded
74 \value CessationOfOperation
75 \value CertificateHold
76 \value RemoveFromCRL
77*/
79/*!
80 \since 5.13
81
82 Creates a new response with status QOcspCertificateStatus::Unknown
83 and revocation reason QOcspRevocationReason::None.
84
85 \sa QOcspCertificateStatus
86*/
87QOcspResponse::QOcspResponse()
88 : d(new QOcspResponsePrivate)
89{
90}
91
92/*!
93 \since 5.13
94
95 Copy-constructs a QOcspResponse instance.
96*/
97QOcspResponse::QOcspResponse(const QOcspResponse &) = default;
98
99/*!
100 \since 5.13
101
102 Move-constructs a QOcspResponse instance.
103*/
104QOcspResponse::QOcspResponse(QOcspResponse &&) noexcept = default;
105
106/*!
107 \since 5.13
108
109 Destroys the response.
110*/
111QOcspResponse::~QOcspResponse() = default;
112
113/*!
114 \since 5.13
115
116 Copy-assigns \a other and returns a reference to this response.
117*/
118QOcspResponse &QOcspResponse::operator=(const QOcspResponse &) = default;
119
120/*!
121 \since 5.13
122
123 Move-assigns \a other to this QOcspResponse instance.
124*/
125QOcspResponse &QOcspResponse::operator=(QOcspResponse &&) noexcept = default;
126
127/*!
128 \fn void QOcspResponse::swap(QOcspResponse &other)
129 \since 5.13
130 \memberswap{response}
131*/
132
133/*!
134 \since 5.13
135
136 Returns the certificate status.
137
138 \sa QOcspCertificateStatus
139*/
140QOcspCertificateStatus QOcspResponse::certificateStatus() const
141{
142 return d->certificateStatus;
143}
144
145/*!
146 \since 5.13
147
148 Returns the reason for revocation.
149*/
150QOcspRevocationReason QOcspResponse::revocationReason() const
151{
152 return d->revocationReason;
153}
154
155/*!
156 \since 5.13
157
158 This function returns a certificate used to sign OCSP response.
159*/
160QSslCertificate QOcspResponse::responder() const
161{
162 return d->signerCert;
163}
164
165/*!
166 \since 5.13
167
168 This function returns a certificate, for which this response was issued.
169*/
170QSslCertificate QOcspResponse::subject() const
171{
172 return d->subjectCert;
173}
174
175/*!
176 \fn bool QOcspResponse::operator==(const QOcspResponse &lhs, const QOcspResponse &rhs)
177
178 Returns \c true if \a lhs and \a rhs are the responses for the same
179 certificate, signed by the same responder, have the same
180 revocation reason and the same certificate status.
181
182 \since 5.13
183*/
184
185/*!
186 \fn bool QOcspResponse::operator!=(const QOcspResponse &lhs, const QOcspResponse &rhs)
187
188 Returns \c true if \a lhs and \a rhs are responses for different certificates,
189 or signed by different responders, or have different revocation reasons, or different
190 certificate statuses.
191
192 \since 5.13
193*/
194
195/*!
196 \internal
197*/
198bool QOcspResponse::isEqual(const QOcspResponse &other) const
199{
200 return d == other.d || *d == *other.d;
201}
202
203/*!
204 \fn size_t qHash(const QOcspResponse &key, size_t seed)
205 \since 5.13
206 \qhashold{QHash}
207*/
208size_t qHash(const QOcspResponse &response, size_t seed) noexcept
209{
210 const QOcspResponsePrivate *d = response.d.data();
211 Q_ASSERT(d);
212
213 QtPrivate::QHashCombine hasher(seed);
214 size_t hash = hasher(seed, int(d->certificateStatus));
215 hash = hasher(hash, int(d->revocationReason));
216 if (!d->signerCert.isNull())
217 hash = hasher(hash, d->signerCert);
218 if (!d->subjectCert.isNull())
219 hash = hasher(hash, d->subjectCert);
220
221 return hash;
222}
223
224QT_END_NAMESPACE
size_t qHash(const QOcspResponse &response, size_t seed) noexcept