Created
November 16, 2012 09:26
-
-
Save fatih/4085851 to your computer and use it in GitHub Desktop.
void Server::incomingConnection(int socketDescriptor)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Server::incomingConnection(int socketDescriptor) | |
| { | |
| QSslSocket *socket = new QSslSocket(this); | |
| socket->setProtocol(QSsl::SslV3); // TODO: Or other protocols, like tls, sslv2? Research... | |
| // For now these files should be reside in the same folder as the application | |
| socket->setPrivateKey("server.key"); // $ openssl genrsa -out server.key 2048 | |
| socket->setLocalCertificate("server.crt"); // $ openssl req -new -x509 -key server.key -out server.crt -days 1095 | |
| if (socket->setSocketDescriptor(socketDescriptor)) { | |
| pendingConnections->enqueue(socket); // Will be used in nextPendingConnection() | |
| // newConnection() is emmited within QTcpServerPrivate. No need to emit it manually. | |
| // However encrypted() is emitted if QSslSocket enters encrypted mode. | |
| // Useful for debugging or other stuff. | |
| // TODO: we might need sslErrors() signal implementation | |
| connect(socket, SIGNAL(encrypted()), this, SLOT(ready())); | |
| socket->startServerEncryption(); // Initiate the SSL handshake | |
| } | |
| else { | |
| delete socket; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment