Beispiel #1
0
void QTlsServer::incomingConnection(int socketDescriptor)
{
	QSslSocket* serverSocket = new QSslSocket;
	QObject::connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(displayTlsErrors(const QList<QSslError>&)));

	if (serverSocket->setSocketDescriptor(socketDescriptor))
	{
		QFile file("server-key.pem");
		if (!file.open(QIODevice::ReadOnly))
		{
			std::cout << "can't open key" << "server-key.pem";
			return;
		}
		QSslKey key(&file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, QByteArray("qtwebsocket-server-key"));
		file.close();
		serverSocket->setPrivateKey(key);

		if (!serverSocket->addCaCertificates("ca.pem"))
		{
			std::cout << "open certificate ca error" << "ca.pem";
			return;
		}
		
		serverSocket->setLocalCertificate("server-crt.pem");
		serverSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
		//serverSocket->ignoreSslErrors();

		QObject::connect(serverSocket, SIGNAL(encrypted()), this, SLOT(tlsSocketEncrypted()));
		serverSocket->startServerEncryption();
	}
	else
	{
		serverSocket->deleteLater();
	}
}
Beispiel #2
0
void SslServer::incomingConnection(int socketDescriptor)
{
    QSslSocket *serverSocket = new QSslSocket(this);
    if (serverSocket->setSocketDescriptor(socketDescriptor)) {
        if (isCertValid()) {
            serverSocket->setLocalCertificate(_cert);
            serverSocket->setPrivateKey(_key);
            serverSocket->addCaCertificates(_ca);
        }
        _pendingConnections << serverSocket;
        emit newConnection();
    }
    else {
        delete serverSocket;
    }
}