10 #include <QSslCertificate> 35 if (!m_settings->
useSSL()) {
36 QTcpServer::incomingConnection(socketDescriptor);
44 QSslSocket *socket =
new QSslSocket;
45 if (!socket->setSocketDescriptor(socketDescriptor)) {
46 qDebug() <<
"setSocketDescriptor failed";
58 connect(socket, SIGNAL(encrypted()),
60 connect(socket, SIGNAL( sslErrors(
const QList<QSslError>&)),
62 connect(socket, SIGNAL( peerVerifyError(
const QSslError&)),
64 connect(socket, SIGNAL( disconnected()),
71 QList<QSslCertificate> cacerts;
72 QFile cacertf(m_settings->
sslCaCrt());
73 if (cacertf.open(QIODevice::ReadOnly)) {
74 cacerts << QSslCertificate(&cacertf);
82 socket->setPrivateKey(m_settings->
sslKey());
83 socket->setLocalCertificate(m_settings->
sslCrt());
84 socket->setCaCertificates(cacerts);
85 socket->startServerEncryption();
97 QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
114 QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
116 QSslCertificate crt = socket->peerCertificate();
119 #if QT_VERSION > 0x040700 120 addPendingConnection(socket);
122 emit newConnection();
130 if (!
m_verified.contains(socket)) {
return false; }
139 if (!
m_peerCert.contains(socket)) {
return QSslCertificate(); }
149 QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
158 QList<QSslError> ignoreList;
159 for (
int i=0; i<errors.size(); i++) {
161 ignoreList << errors[i];
164 qDebug() <<
"sslError" << errors[i].errorString();
167 QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
168 socket->ignoreSslErrors(ignoreList);
bool ignoreSslError(QSslError error) const
Returns true if the error should be ignored, default true.
const HttpSettings * settings() const
Returs pointer to HttpSettings used in the HttpServer.
void slotEncrypted()
Slot is invoked when the SSL hanshake is complete and connection is established.
const QString & sslCaCrt() const
Returns SSL CA certificate.
General single-threaded, event-driven HTTP server.
void slotSslErrors(const QList< QSslError > &)
Slot is called when an SSL error occured.
HttpTcpServer(HttpServer *)
Constructor creates the class instance.
QHash< QTcpSocket *, bool > m_verified
Verified status of each socket.
void slotDisconnected()
Slot is invoked when the socket disconnets.
QHash< QTcpSocket *, QSslCertificate > m_peerCert
Peer's certificate of each socket.
QSslCertificate peerCertificate(QTcpSocket *) const
Returns peer's certificate.
const QString & sslKey() const
Returns SSL key.
bool verified(QTcpSocket *) const
Returns true if the peer's certificate is valid and signed with server's CA certificate.
bool useSSL() const
Returns status of SSL connections.
void incomingConnection(QINTPTR socketDescriptor)
Method is invoked when incoming connection arrived.
const QString & sslCrt() const
Returns SSL certificate.
Namespace of HTTP server.
void slotPeerVerifyError(const QSslError &)
Slot is called when the peer's certificate is not verified.