QtBase  v6.3.1
qx509_openssl_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 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 #ifndef QX509_OPENSSL_P_H
41 #define QX509_OPENSSL_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtNetwork/private/qtnetworkglobal_p.h>
55 
56 #include "../shared/qx509_base_p.h"
57 
58 #include <QtNetwork/private/qtlsbackend_p.h>
59 
60 #include <QtCore/qvariant.h>
61 #include <QtCore/qglobal.h>
62 #include <QtCore/qstring.h>
63 
64 #include "qopenssl_p.h"
65 
66 #include <algorithm>
67 
69 
70 namespace QTlsPrivate {
71 
73 {
74 public:
77 
78  // TLSTODO: in future may become movable/copyable (ref-counted based
79  // OpenSSL's X509 implementation).
80 
81  bool isEqual(const X509Certificate &rhs) const override;
82  bool isSelfSigned() const override;
84  TlsKey *publicKey() const override;
85 
86  QByteArray toPem() const override;
87  QByteArray toDer() const override;
88  QString toText() const override;
89  Qt::HANDLE handle() const override;
90 
91  size_t hash(size_t seed) const noexcept override;
92 
95  static QSslErrorEntry errorEntryFromStoreContext(X509_STORE_CTX *ctx);
96 
97  static QList<QSslError> verify(const QList<QSslCertificate> &chain, const QString &hostName);
98  static QList<QSslError> verify(const QList<QSslCertificate> &caCertificates,
99  const QList<QSslCertificate> &certificateChain,
100  const QString &hostName);
101 
105  QList<QSslCertificate> *caCertificates,
106  const QByteArray &passPhrase);
107 
108  static QSslError openSSLErrorToQSslError(int errorCode, const QSslCertificate &cert);
109 private:
110  void parseExtensions();
111  static X509CertificateExtension convertExtension(X509_EXTENSION *ext);
112 
113  X509 *x509 = nullptr;
114 
116 };
117 
118 extern "C" int qt_X509Callback(int ok, X509_STORE_CTX *ctx);
119 
120 } // namespace QTlsPrivate
121 
123 
124 #endif // QX509_OPENSSL_P_H
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:70
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslError class provides an SSL error.
Definition: qsslerror.h:57
The QSslKey class provides an interface for private and public keys.
Definition: qsslkey.h:59
The QString class provides a Unicode character string.
Definition: qstring.h:388
static QSslErrorEntry errorEntryFromStoreContext(X509_STORE_CTX *ctx)
static QSslCertificate certificateFromX509(X509 *x)
QByteArray toPem() const override
static bool importPkcs12(QIODevice *device, QSslKey *key, QSslCertificate *cert, QList< QSslCertificate > *caCertificates, const QByteArray &passPhrase)
static QList< QSslCertificate > certificatesFromDer(const QByteArray &der, int count)
QByteArray toDer() const override
QString toText() const override
static QSslError openSSLErrorToQSslError(int errorCode, const QSslCertificate &cert)
static QList< QSslCertificate > certificatesFromPem(const QByteArray &pem, int count)
TlsKey * publicKey() const override
size_t hash(size_t seed) const noexcept override
bool isEqual(const X509Certificate &rhs) const override
Qt::HANDLE handle() const override
static QList< QSslError > verify(const QList< QSslCertificate > &chain, const QString &hostName)
static QList< QSslCertificate > stackOfX509ToQSslCertificates(STACK_OF(X509) *x509)
QMultiMap< QSsl::AlternativeNameEntryType, QString > subjectAlternativeNames() const override
int qt_X509Callback(int ok, X509_STORE_CTX *ctx)
void * HANDLE
Definition: qnamespace.h:1561
#define Q_DISABLE_COPY_MOVE(Class)
Definition: qglobal.h:519
GLint GLint GLint GLint GLint x
[0]
GLuint64 key
GLenum GLenum GLsizei count
STACK_OF(X509) *q_X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx)
QList< QSslCertificate > cert
[0]
Definition: qopenssl_p.h:109
#define rhs