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 #ifdef Q_OS_WINRT 74 #include <wrl.h> 75 #include <windows.security.cryptography.certificates.h> 76 #endif 77 78 #if QT_CONFIG(schannel) 79 #include <wincrypt.h> 80 #endif 81 82 QT_BEGIN_NAMESPACE 83 84 // forward declaration 85 86 class QSslCertificatePrivate 87 { 88 public: QSslCertificatePrivate()89 QSslCertificatePrivate() 90 : null(true), x509(nullptr) 91 { 92 #ifndef QT_NO_SSL 93 QSslSocketPrivate::ensureInitialized(); 94 #endif 95 } 96 ~QSslCertificatePrivate()97 ~QSslCertificatePrivate() 98 { 99 #ifndef QT_NO_OPENSSL 100 if (x509) 101 q_X509_free(x509); 102 #endif 103 #if QT_CONFIG(schannel) 104 if (certificateContext) 105 CertFreeCertificateContext(certificateContext); 106 #endif 107 } 108 109 bool null; 110 QByteArray versionString; 111 QByteArray serialNumberString; 112 113 QMultiMap<QByteArray, QString> issuerInfo; 114 QMultiMap<QByteArray, QString> subjectInfo; 115 QDateTime notValidAfter; 116 QDateTime notValidBefore; 117 118 #ifdef QT_NO_OPENSSL 119 bool subjectMatchesIssuer; 120 QSsl::KeyAlgorithm publicKeyAlgorithm; 121 QByteArray publicKeyDerData; 122 QMultiMap<QSsl::AlternativeNameEntryType, QString> subjectAlternativeNames; 123 QList<QSslCertificateExtension> extensions; 124 125 QByteArray derData; 126 127 bool parse(const QByteArray &data); 128 bool parseExtension(const QByteArray &data, QSslCertificateExtension *extension); 129 #endif 130 X509 *x509; 131 132 void init(const QByteArray &data, QSsl::EncodingFormat format); 133 134 static QByteArray asn1ObjectId(ASN1_OBJECT *object); 135 static QByteArray asn1ObjectName(ASN1_OBJECT *object); 136 static QByteArray QByteArray_from_X509(X509 *x509, QSsl::EncodingFormat format); 137 static QString text_from_X509(X509 *x509); 138 static QSslCertificate QSslCertificate_from_X509(X509 *x509); 139 static QList<QSslCertificate> certificatesFromPem(const QByteArray &pem, int count = -1); 140 static QList<QSslCertificate> certificatesFromDer(const QByteArray &der, int count = -1); 141 static bool isBlacklisted(const QSslCertificate &certificate); 142 static QSslCertificateExtension convertExtension(X509_EXTENSION *ext); 143 static QByteArray subjectInfoToString(QSslCertificate::SubjectInfo info); 144 145 friend class QSslSocketBackendPrivate; 146 147 QAtomicInt ref; 148 149 #ifdef Q_OS_WINRT 150 Microsoft::WRL::ComPtr<ABI::Windows::Security::Cryptography::Certificates::ICertificate> certificate; 151 152 static QSslCertificate QSslCertificate_from_Certificate(ABI::Windows::Security::Cryptography::Certificates::ICertificate *iCertificate); 153 #endif 154 155 #if QT_CONFIG(schannel) 156 const CERT_CONTEXT *certificateContext = nullptr; 157 158 static QSslCertificate QSslCertificate_from_CERT_CONTEXT(const CERT_CONTEXT *certificateContext); 159 #endif 160 }; 161 162 QT_END_NAMESPACE 163 164 #endif // QSSLCERTIFICATE_OPENSSL_P_H 165