SSLServer
::SSLServer(int socket_descriptor,
QObject *parent
) : QObject(parent
) { /* create server socket */
server = new QSslSocket(this);
/* call a slot after 1 second - to terminate the unauthenticated connection */
QTimer::singleShot(1000,
this,
SLOT(abort_connection
()));
/* set socket descriptor */
if(!server->setSocketDescriptor(socket_descriptor)) {
qWarning("Failed to set socket descriptor in SSLServer");
close(socket_descriptor);
delete this;
return;
}
/* add CA certificate: it is used by the handshake process to validate the peer's certificate*/
QSslCertificate ca_cert = handle_certificate(":/central_authority.crt");
server->addCaCertificate(ca_cert);
/* set the server's (LOCAL) digital certificate */
QSslCertificate server_cert = handle_certificate(":/server.crt");
server->setLocalCertificate(server_cert);
/* set the server's (LOCAL) private key -> [key+certificate == prove identity to SSL peer] */
server->setPrivateKey(":/server.key", QSsl::Rsa, QSsl::Pem, "");
/* set cipher protocol */
server->setProtocol(QSsl::SslV3);
/* server has to ask the client to send the certificate */
/* the client ask the server to send the certificate by default */
server->setPeerVerifyMode(QSslSocket::VerifyPeer);
/* starts a delayed SSL handshake */
server->startServerEncryption();
#ifdef SSL_DEBUG
/* wait for socket to complete SSL handshake -> when encrypted it emits encrypted signal */
if(server->waitForEncrypted(1000))
print_socket_info();
#endif
connection_established();
/* if handshake is successful and encrypted socket is ready to use */
connect(server, SIGNAL(encrypted()), this, SLOT(connection_established()));
/* if error occurs the sslErrors() signal is emitted */
connect(server, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(error_occured(const QList<QSslError> &)));
}
void SSLServer::connection_established() {
qDebug() << "SSL Handshake succedded. The socket is now encrypted." << endl;
get_certificate_data();
create_files_dir();
}
SSLServer::SSLServer(int socket_descriptor, QObject *parent) : QObject(parent) {
/* create server socket */
server = new QSslSocket(this);
/* call a slot after 1 second - to terminate the unauthenticated connection */
QTimer::singleShot(1000, this, SLOT(abort_connection()));
/* set socket descriptor */
if(!server->setSocketDescriptor(socket_descriptor)) {
qWarning("Failed to set socket descriptor in SSLServer");
close(socket_descriptor);
delete this;
return;
}
/* add CA certificate: it is used by the handshake process to validate the peer's certificate*/
QSslCertificate ca_cert = handle_certificate(":/central_authority.crt");
server->addCaCertificate(ca_cert);
/* set the server's (LOCAL) digital certificate */
QSslCertificate server_cert = handle_certificate(":/server.crt");
server->setLocalCertificate(server_cert);
/* set the server's (LOCAL) private key -> [key+certificate == prove identity to SSL peer] */
server->setPrivateKey(":/server.key", QSsl::Rsa, QSsl::Pem, "");
/* set cipher protocol */
server->setProtocol(QSsl::SslV3);
/* server has to ask the client to send the certificate */
/* the client ask the server to send the certificate by default */
server->setPeerVerifyMode(QSslSocket::VerifyPeer);
/* starts a delayed SSL handshake */
server->startServerEncryption();
#ifdef SSL_DEBUG
/* wait for socket to complete SSL handshake -> when encrypted it emits encrypted signal */
if(server->waitForEncrypted(1000))
print_socket_info();
#endif
connection_established();
/* if handshake is successful and encrypted socket is ready to use */
connect(server, SIGNAL(encrypted()), this, SLOT(connection_established()));
/* if error occurs the sslErrors() signal is emitted */
connect(server, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(error_occured(const QList<QSslError> &)));
}
void SSLServer::connection_established() {
qDebug() << "SSL Handshake succedded. The socket is now encrypted." << endl;
get_certificate_data();
create_files_dir();
}
To copy to clipboard, switch view to plain text mode
Bookmarks