1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | |
41 | #ifndef QSSLCERTIFICATE_OPENSSL_P_H |
42 | #define QSSLCERTIFICATE_OPENSSL_P_H |
43 | |
44 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
45 | #include "qsslcertificate.h" |
46 | |
47 | // |
48 | // W A R N I N G |
49 | // ------------- |
50 | // |
51 | // This file is not part of the Qt API. It exists purely as an |
52 | // implementation detail. This header file may change from version to |
53 | // version without notice, or even be removed. |
54 | // |
55 | // We mean it. |
56 | // |
57 | |
58 | #ifndef QT_NO_SSL |
59 | #include "qsslsocket_p.h" |
60 | #endif |
61 | #include "qsslcertificateextension.h" |
62 | #include <QtCore/qdatetime.h> |
63 | #include <QtCore/qmap.h> |
64 | |
65 | #ifndef QT_NO_OPENSSL |
66 | #include <openssl/x509.h> |
67 | #else |
68 | struct X509; |
69 | struct X509_EXTENSION; |
70 | struct ASN1_OBJECT; |
71 | #endif |
72 | |
73 | #if QT_CONFIG(schannel) |
74 | #include <wincrypt.h> |
75 | #endif |
76 | |
77 | QT_BEGIN_NAMESPACE |
78 | |
79 | // forward declaration |
80 | |
81 | class QSslCertificatePrivate |
82 | { |
83 | public: |
84 | QSslCertificatePrivate() |
85 | : null(true), x509(nullptr) |
86 | { |
87 | #ifndef QT_NO_SSL |
88 | QSslSocketPrivate::ensureInitialized(); |
89 | #endif |
90 | } |
91 | |
92 | ~QSslCertificatePrivate() |
93 | { |
94 | #ifndef QT_NO_OPENSSL |
95 | if (x509) |
96 | q_X509_free(x509); |
97 | #endif |
98 | #if QT_CONFIG(schannel) |
99 | if (certificateContext) |
100 | CertFreeCertificateContext(certificateContext); |
101 | #endif |
102 | } |
103 | |
104 | bool null; |
105 | QByteArray versionString; |
106 | QByteArray serialNumberString; |
107 | |
108 | QMultiMap<QByteArray, QString> issuerInfo; |
109 | QMultiMap<QByteArray, QString> subjectInfo; |
110 | QDateTime notValidAfter; |
111 | QDateTime notValidBefore; |
112 | |
113 | #ifdef QT_NO_OPENSSL |
114 | bool subjectMatchesIssuer; |
115 | QSsl::KeyAlgorithm publicKeyAlgorithm; |
116 | QByteArray publicKeyDerData; |
117 | QMultiMap<QSsl::AlternativeNameEntryType, QString> subjectAlternativeNames; |
118 | QList<QSslCertificateExtension> extensions; |
119 | |
120 | QByteArray derData; |
121 | |
122 | bool parse(const QByteArray &data); |
123 | bool parseExtension(const QByteArray &data, QSslCertificateExtension *extension); |
124 | #endif |
125 | X509 *x509; |
126 | |
127 | void init(const QByteArray &data, QSsl::EncodingFormat format); |
128 | |
129 | static QByteArray asn1ObjectId(ASN1_OBJECT *object); |
130 | static QByteArray asn1ObjectName(ASN1_OBJECT *object); |
131 | static QByteArray QByteArray_from_X509(X509 *x509, QSsl::EncodingFormat format); |
132 | static QString text_from_X509(X509 *x509); |
133 | static QSslCertificate QSslCertificate_from_X509(X509 *x509); |
134 | static QList<QSslCertificate> certificatesFromPem(const QByteArray &pem, int count = -1); |
135 | static QList<QSslCertificate> certificatesFromDer(const QByteArray &der, int count = -1); |
136 | static bool isBlacklisted(const QSslCertificate &certificate); |
137 | static QSslCertificateExtension convertExtension(X509_EXTENSION *ext); |
138 | static QByteArray subjectInfoToString(QSslCertificate::SubjectInfo info); |
139 | |
140 | friend class QSslSocketBackendPrivate; |
141 | |
142 | QAtomicInt ref; |
143 | |
144 | #if QT_CONFIG(schannel) |
145 | const CERT_CONTEXT *certificateContext = nullptr; |
146 | |
147 | static QSslCertificate QSslCertificate_from_CERT_CONTEXT(const CERT_CONTEXT *certificateContext); |
148 | #endif |
149 | }; |
150 | |
151 | QT_END_NAMESPACE |
152 | |
153 | #endif // QSSLCERTIFICATE_OPENSSL_P_H |
154 | |