Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsslsocket_p.h
Go to the documentation of this file.
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
5#ifndef QSSLSOCKET_P_H
6#define QSSLSOCKET_P_H
7
8#include "qsslsocket.h"
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtNetwork/private/qtnetworkglobal_p.h>
22
23#include <private/qtcpsocket_p.h>
24
25#include "qocspresponse.h"
26#include "qsslconfiguration_p.h"
27#include "qsslkey.h"
28#include "qtlsbackend_p.h"
29
30#include <QtCore/qlist.h>
31#include <QtCore/qmutex.h>
32#include <QtCore/qstringlist.h>
33
34#include <memory>
35
37
38class QSslContext;
39class QTlsBackend;
40
41class Q_NETWORK_EXPORT QSslSocketPrivate : public QTcpSocketPrivate
42{
43 Q_DECLARE_PUBLIC(QSslSocket)
44public:
46 virtual ~QSslSocketPrivate();
47
48 void init();
49 bool verifyProtocolSupported(const char *where);
51
56 QList<QSslError> ignoreErrorsList;
58
60
61 // if set, this hostname is used for certificate validation instead of the hostname
62 // that was used for connecting to.
64
66
68
69 static bool supportsSsl();
70 static void ensureInitialized();
71
72 static QList<QSslCipher> defaultCiphers();
73 static QList<QSslCipher> defaultDtlsCiphers();
74 static QList<QSslCipher> supportedCiphers();
75 static void setDefaultCiphers(const QList<QSslCipher> &ciphers);
76 static void setDefaultDtlsCiphers(const QList<QSslCipher> &ciphers);
77 static void setDefaultSupportedCiphers(const QList<QSslCipher> &ciphers);
78
79 static QList<QSslEllipticCurve> supportedEllipticCurves();
80 static void setDefaultSupportedEllipticCurves(const QList<QSslEllipticCurve> &curves);
81 static void resetDefaultEllipticCurves();
82
83 static QList<QSslCertificate> defaultCaCertificates();
84 static QList<QSslCertificate> systemCaCertificates();
85 static void setDefaultCaCertificates(const QList<QSslCertificate> &certs);
86 static void addDefaultCaCertificate(const QSslCertificate &cert);
87 static void addDefaultCaCertificates(const QList<QSslCertificate> &certs);
88 static bool isMatchingHostname(const QSslCertificate &cert, const QString &peerName);
89 static bool isMatchingHostname(const QString &cn, const QString &hostname);
90
91 // The socket itself, including private slots.
92 QTcpSocket *plainSocket = nullptr;
93 void createPlainSocket(QIODevice::OpenMode openMode);
94 static void pauseSocketNotifiers(QSslSocket*);
95 static void resumeSocketNotifiers(QSslSocket*);
96 // ### The 2 methods below should be made member methods once the QSslContext class is made public
97 static void checkSettingSslContext(QSslSocket*, std::shared_ptr<QSslContext>);
98 static std::shared_ptr<QSslContext> sslContext(QSslSocket *socket);
99 bool isPaused() const;
100 void setPaused(bool p);
101 bool bind(const QHostAddress &address, quint16, QAbstractSocket::BindMode) override;
102 void _q_connectedSlot();
103 void _q_hostFoundSlot();
104 void _q_disconnectedSlot();
105 void _q_stateChangedSlot(QAbstractSocket::SocketState);
106 void _q_errorSlot(QAbstractSocket::SocketError);
107 void _q_readyReadSlot();
108 void _q_channelReadyReadSlot(int);
109 void _q_bytesWrittenSlot(qint64);
110 void _q_channelBytesWrittenSlot(int, qint64);
111 void _q_readChannelFinishedSlot();
112 void _q_flushWriteBuffer();
113 void _q_flushReadBuffer();
114 void _q_resumeImplementation();
115
116 static QList<QByteArray> unixRootCertDirectories(); // used also by QSslContext
117
118 qint64 peek(char *data, qint64 maxSize) override;
119 QByteArray peek(qint64 maxSize) override;
120 bool flush() override;
121
122 void startClientEncryption();
123 void startServerEncryption();
124 void transmit();
125 void disconnectFromHost();
126 void disconnected();
127 QSslCipher sessionCipher() const;
128 QSsl::SslProtocol sessionProtocol() const;
129 void continueHandshake();
130
131 static bool rootCertOnDemandLoadingSupported();
132 static void setRootCertOnDemandLoadingSupported(bool supported);
133
134 static QTlsBackend *tlsBackendInUse();
135
136 // Needed by TlsCryptograph:
137 QSslSocket::SslMode tlsMode() const;
138 bool isRootsOnDemandAllowed() const;
139 QString verificationName() const;
140 QString tlsHostName() const;
141 QTcpSocket *plainTcpSocket() const;
142 bool verifyErrorsHaveBeenIgnored();
143 bool isAutoStartingHandshake() const;
144 bool isPendingClose() const;
145 void setPendingClose(bool pc);
146 qint64 maxReadBufferSize() const;
147 void setMaxReadBufferSize(qint64 maxSize);
148 void setEncrypted(bool enc);
149 QRingBufferRef &tlsWriteBuffer();
150 QRingBufferRef &tlsBuffer();
151 bool &tlsEmittedBytesWritten();
152 bool *readyReadPointer();
153
154protected:
155
156 bool hasUndecryptedData() const;
157 bool paused;
159
160 static inline QMutex backendMutex;
162 static inline QTlsBackend *tlsBackend = nullptr;
163
164 std::unique_ptr<QTlsPrivate::TlsCryptograph> backend;
165};
166
168
169#endif
SocketState
This enum describes the different states in which a socket can be.
SocketError
This enum describes the socket errors that can occur.
\inmodule QtCore
Definition qbytearray.h:57
The QHostAddress class provides an IP address.
\inmodule QtCore
Definition qmutex.h:281
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslCipher class represents an SSL cryptographic cipher.
Definition qsslcipher.h:22
bool * readyReadEmittedPointer
QString verificationPeerName
QSslSocket::SslMode mode
bool allowRootCertOnDemandLoading
std::unique_ptr< QTlsPrivate::TlsCryptograph > backend
static QString activeBackendName
static QMutex backendMutex
QList< QSslError > ignoreErrorsList
static bool s_loadRootCertsOnDemand
QSslConfigurationPrivate configuration
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition qsslsocket.h:29
SslMode
Describes the connection modes available for QSslSocket.
Definition qsslsocket.h:33
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTcpSocket class provides a TCP socket.
Definition qtcpsocket.h:18
QTlsBackend is a factory class, providing implementations for the QSsl classes.
SslProtocol
Describes the protocol of the cipher.
Definition qssl.h:50
Combined button and popup list for selecting options.
static void ensureInitialized()
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
GLfloat GLfloat p
[1]
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned short quint16
Definition qtypes.h:48
long long qint64
Definition qtypes.h:60
QTcpSocket * socket
[1]
QList< QSslCertificate > cert
[0]
socket disconnectFromHost()
[0]
socketLayer bind(QHostAddress::Any, 4000)
const auto certs
[1]