1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTLSKEY_OPENSSL_H
5#define QTLSKEY_OPENSSL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
20#include "../shared/qtlskey_base_p.h"
21
22#include <QtNetwork/private/qtlsbackend_p.h>
23#include <QtNetwork/private/qsslkey_p.h>
24
25#include <QtNetwork/qssl.h>
26
27#include <QtCore/qbytearray.h>
28#include <QtCore/qglobal.h>
29
30#include <openssl/rsa.h>
31#include <openssl/dsa.h>
32#include <openssl/dh.h>
33
34#ifdef OPENSSL_NO_DEPRECATED_3_0
35typedef struct evp_pkey_st EVP_PKEY;
36typedef struct dsa_st DSA;
37typedef struct rsa_st RSA;
38typedef struct dh_st DH;
39typedef struct ec_key_st EC_KEY;
40#endif // OPENSSL_NO_DEPRECATED_3_0
41
42QT_BEGIN_NAMESPACE
43
44QT_REQUIRE_CONFIG(ssl);
45
46namespace QTlsPrivate {
47
48class TlsKeyOpenSSL final : public TlsKeyBase
49{
50public:
51 TlsKeyOpenSSL()
52 : opaque(nullptr)
53 {
54 clear(deep: false);
55 }
56 ~TlsKeyOpenSSL()
57 {
58 clear(deep: true);
59 }
60
61 void decodeDer(KeyType type, KeyAlgorithm algorithm, const QByteArray &der,
62 const QByteArray &passPhrase, bool deepClear) override;
63 void decodePem(KeyType type, KeyAlgorithm algorithm, const QByteArray &pem,
64 const QByteArray &passPhrase, bool deepClear) override;
65
66 QByteArray toPem(const QByteArray &passPhrase) const override;
67 QByteArray derFromPem(const QByteArray &pem, QMap<QByteArray, QByteArray> *headers) const override;
68
69 void fromHandle(Qt::HANDLE opaque, KeyType expectedType) override;
70
71 void clear(bool deep) override;
72 Qt::HANDLE handle() const override;
73 int length() const override;
74
75 QByteArray decrypt(Cipher cipher, const QByteArray &data,
76 const QByteArray &key, const QByteArray &iv) const override;
77 QByteArray encrypt(Cipher cipher, const QByteArray &data,
78 const QByteArray &key, const QByteArray &iv) const override;
79
80 static TlsKeyOpenSSL *publicKeyFromX509(X509 *x);
81
82 union {
83 EVP_PKEY *opaque;
84 RSA *rsa;
85 DSA *dsa;
86 DH *dh;
87#ifndef OPENSSL_NO_EC
88 EC_KEY *ec;
89#endif
90 EVP_PKEY *genericKey;
91 };
92
93 bool fromEVP_PKEY(EVP_PKEY *pkey);
94};
95
96} // namespace QTlsPrivate
97
98QT_END_NAMESPACE
99
100#endif // QTLSKEY_OPENSSL_H
101

source code of qtbase/src/plugins/tls/openssl/qtlskey_openssl_p.h