-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqcsslserver.cpp
31 lines (29 loc) · 1.43 KB
/
qcsslserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "qcsslserver.h"
QcSSLServer::QcSSLServer(QObject *parent) : QTcpServer(parent) {}
void QcSSLServer::incomingConnection(qintptr socketDescriptor) {
QSslSocket *pQSslSocket= new QSslSocket(this);
pQSslSocket->setProtocol(QSsl::TlsV1_2);
QFile FileIn(SslKeyCertificateEmbedded ? ":/certs/certs/KeyPrivate.key" : SslKeyPrivate);
if (FileIn.open(QIODevice::ReadOnly)) {
QSslKey SslKey(FileIn.readAll(), QSsl::Rsa);
FileIn.close();
pQSslSocket->setPrivateKey(SslKey);
FileIn.setFileName(SslKeyCertificateEmbedded ? ":/certs/certs/Certificate.crt" : SslCertificate);
if (FileIn.open(QIODevice::ReadOnly)) {
QSslCertificate SslLocalCertificate(FileIn.readAll());
FileIn.close();
pQSslSocket->setLocalCertificate(SslLocalCertificate);
if (pQSslSocket->setSocketDescriptor(socketDescriptor)) {
pQSslSocket->startServerEncryption();
if (!pQSslSocket->isEncrypted()) {
if (pQSslSocket->waitForEncrypted(10000)) {
this->addPendingConnection(pQSslSocket);
} else {
emit GenericError(pQSslSocket->errorString());
delete pQSslSocket;
}
}
} else delete pQSslSocket;
} else emit GenericError(FileIn.errorString());
} else emit GenericError(FileIn.errorString());
}