QT_USE_NAMESPACE //! [constructor] SslEchoServer::SslEchoServer(quint16 port, QObject *parent) : QObject(parent), m_pWebSocketServer(Q_NULLPTR), m_clients() { m_pWebSocketServer = new QWebSocketServer(QStringLiteral("SSL Echo Server"), QWebSocketServer::SecureMode, this); QSslConfiguration sslConfiguration; QFile certFile(QStringLiteral("./localhost.cert")); QFile keyFile(QStringLiteral("./localhost.key")); certFile.open(QIODevice::ReadOnly); keyFile.open(QIODevice::ReadOnly); QSslCertificate certificate(&certFile, QSsl::Pem); QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem); certFile.close(); keyFile.close(); sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); sslConfiguration.setLocalCertificate(certificate); sslConfiguration.setPrivateKey(sslKey); sslConfiguration.setProtocol(QSsl::TlsV1SslV3); m_pWebSocketServer->setSslConfiguration(sslConfiguration); if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { qDebug() << "SSL Echo Server listening on port" << port; connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &SslEchoServer::onNewConnection); connect(m_pWebSocketServer, &QWebSocketServer::sslErrors, this, &SslEchoServer::onSslErrors); } }
QT_USE_NAMESPACE //! [constructor] BCWebSocketServer::BCWebSocketServer(quint16 port, QObject *parent) : QObject(parent), m_pWebSocketServer(Q_NULLPTR), m_clients() { m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Bitcoin Exchange Server"), QWebSocketServer::NonSecureMode, //**** To be Changed after setting up OpenSSL this); QSslConfiguration sslConfiguration; QFile certFile(QStringLiteral("./localhost.cert")); QFile keyFile(QStringLiteral("./localhost.key")); /*if ( */ certFile.open(stderr, QIODevice::ReadOnly | QIODevice::Text ) ; //&& keyFile.open(stderr, QIODevice::ReadOnly | QIODevice::Text) ; // ) { QSslCertificate certificate(&certFile, QSsl::Pem); QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem); certFile.close(); keyFile.close(); sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); sslConfiguration.setLocalCertificate(certificate); sslConfiguration.setPrivateKey(sslKey); sslConfiguration.setProtocol(QSsl::TlsV1SslV3); m_pWebSocketServer->setSslConfiguration(sslConfiguration); if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { qDebug() << "Bitcoin Exchange Server listening on port" << port; connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &BCWebSocketServer::onNewConnection); connect(m_pWebSocketServer, &QWebSocketServer::sslErrors, this, &BCWebSocketServer::onSslErrors); } _logged = false; _lang = NULL; this->data.rank = 0; } }