/src/qtbase/src/network/ssl/qsslcertificateextension.cpp
Line | Count | Source |
1 | | // Copyright (C) 2011 Richard J. Moore <rich@kde.org> |
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 | | /*! |
6 | | \class QSslCertificateExtension |
7 | | \brief The QSslCertificateExtension class provides an API for accessing the |
8 | | extensions of an X509 certificate. |
9 | | \since 5.0 |
10 | | |
11 | | \reentrant |
12 | | \ingroup network |
13 | | \ingroup ssl |
14 | | \ingroup shared |
15 | | \inmodule QtNetwork |
16 | | |
17 | | QSslCertificateExtension provides access to an extension stored in |
18 | | an X509 certificate. The information available depends on the type |
19 | | of extension being accessed. |
20 | | |
21 | | All X509 certificate extensions have the following properties: |
22 | | |
23 | | \table |
24 | | \header |
25 | | \li Property |
26 | | \li Description |
27 | | \row |
28 | | \li name |
29 | | \li The human readable name of the extension, eg. 'basicConstraints'. |
30 | | \row |
31 | | \li criticality |
32 | | \li This is a boolean value indicating if the extension is critical |
33 | | to correctly interpreting the certificate. |
34 | | \row |
35 | | \li oid |
36 | | \li The ASN.1 object identifier that specifies which extension this |
37 | | is. |
38 | | \row |
39 | | \li supported |
40 | | \li If this is true the structure of the extension's value will not |
41 | | change between Qt versions. |
42 | | \row |
43 | | \li value |
44 | | \li A QVariant with a structure dependent on the type of extension. |
45 | | \endtable |
46 | | |
47 | | Whilst this class provides access to any type of extension, only |
48 | | some are guaranteed to be returned in a format that will remain |
49 | | unchanged between releases. The isSupported() method returns \c true |
50 | | for extensions where this is the case. |
51 | | |
52 | | The extensions currently supported, and the structure of the value |
53 | | returned are as follows: |
54 | | |
55 | | \table |
56 | | \header |
57 | | \li Name |
58 | | \li OID |
59 | | \li Details |
60 | | \row |
61 | | \li basicConstraints |
62 | | \li 2.5.29.19 |
63 | | \li Returned as a QVariantMap. The key 'ca' contains a boolean value, |
64 | | the optional key 'pathLenConstraint' contains an integer. |
65 | | \row |
66 | | \li authorityInfoAccess |
67 | | \li 1.3.6.1.5.5.7.1.1 |
68 | | \li Returned as a QVariantMap. There is a key for each access method, |
69 | | with the value being a URI. |
70 | | \row |
71 | | \li subjectKeyIdentifier |
72 | | \li 2.5.29.14 |
73 | | \li Returned as a QVariant containing a QString. The string is the key |
74 | | identifier. |
75 | | \row |
76 | | \li authorityKeyIdentifier |
77 | | \li 2.5.29.35 |
78 | | \li Returned as a QVariantMap. The optional key 'keyid' contains the key |
79 | | identifier as a hex string stored in a QByteArray. The optional key |
80 | | 'serial' contains the authority key serial number as a qlonglong. |
81 | | Currently there is no support for the general names field of this |
82 | | extension. |
83 | | \endtable |
84 | | |
85 | | In addition to the supported extensions above, many other common extensions |
86 | | will be returned in a reasonably structured way. Extensions that the SSL |
87 | | backend has no support for at all will be returned as a QByteArray. |
88 | | |
89 | | Further information about the types of extensions certificates can |
90 | | contain can be found in RFC 5280. |
91 | | |
92 | | \sa QSslCertificate::extensions() |
93 | | */ |
94 | | |
95 | | #include "qsslcertificateextension.h" |
96 | | #include "qsslcertificateextension_p.h" |
97 | | |
98 | | QT_BEGIN_NAMESPACE |
99 | | |
100 | | /*! |
101 | | Constructs a QSslCertificateExtension. |
102 | | */ |
103 | | QSslCertificateExtension::QSslCertificateExtension() |
104 | 0 | : d(new QSslCertificateExtensionPrivate) |
105 | 0 | { |
106 | 0 | } |
107 | | |
108 | | /*! |
109 | | Constructs a copy of \a other. |
110 | | */ |
111 | | QSslCertificateExtension::QSslCertificateExtension(const QSslCertificateExtension &other) |
112 | 0 | : d(other.d) |
113 | 0 | { |
114 | 0 | } |
115 | | |
116 | | /*! |
117 | | Destroys the extension. |
118 | | */ |
119 | | QSslCertificateExtension::~QSslCertificateExtension() |
120 | 0 | { |
121 | 0 | } |
122 | | |
123 | | /*! |
124 | | Assigns \a other to this extension and returns a reference to this extension. |
125 | | */ |
126 | | QSslCertificateExtension &QSslCertificateExtension::operator=(const QSslCertificateExtension &other) |
127 | 0 | { |
128 | 0 | d = other.d; |
129 | 0 | return *this; |
130 | 0 | } |
131 | | |
132 | | /*! |
133 | | \fn void QSslCertificateExtension::swap(QSslCertificateExtension &other) |
134 | | \memberswap{certificate extension instance} |
135 | | */ |
136 | | |
137 | | /*! |
138 | | Returns the ASN.1 OID of this extension. |
139 | | */ |
140 | | QString QSslCertificateExtension::oid() const |
141 | 0 | { |
142 | 0 | return d->oid; |
143 | 0 | } |
144 | | |
145 | | /*! |
146 | | Returns the name of the extension. If no name is known for the |
147 | | extension then the OID will be returned. |
148 | | */ |
149 | | QString QSslCertificateExtension::name() const |
150 | 0 | { |
151 | 0 | return d->name; |
152 | 0 | } |
153 | | |
154 | | /*! |
155 | | Returns the value of the extension. The structure of the value |
156 | | returned depends on the extension type. |
157 | | */ |
158 | | QVariant QSslCertificateExtension::value() const |
159 | 0 | { |
160 | 0 | return d->value; |
161 | 0 | } |
162 | | |
163 | | /*! |
164 | | Returns the criticality of the extension. |
165 | | */ |
166 | | bool QSslCertificateExtension::isCritical() const |
167 | 0 | { |
168 | 0 | return d->critical; |
169 | 0 | } |
170 | | |
171 | | /*! |
172 | | Returns the true if this extension is supported. In this case, |
173 | | supported simply means that the structure of the QVariant returned |
174 | | by the value() accessor will remain unchanged between versions. |
175 | | Unsupported extensions can be freely used, however there is no |
176 | | guarantee that the returned data will have the same structure |
177 | | between versions. |
178 | | */ |
179 | | bool QSslCertificateExtension::isSupported() const |
180 | 0 | { |
181 | 0 | return d->supported; |
182 | 0 | } |
183 | | |
184 | | QT_END_NAMESPACE |