Commit some more work converting the QTcpServer into an SslServer. The API test will now connect without failures - but it hangs there (no incoming messages detected)

This commit is contained in:
Ken Moore
2016-01-08 10:33:01 -05:00
parent 8abeeac890
commit fbbc72c3a4
4 changed files with 69 additions and 5 deletions

58
src/server/SslServer.h Normal file
View File

@@ -0,0 +1,58 @@
// ===============================
// PC-BSD REST/JSON API Server
// Available under the 3-clause BSD License
// Written by: Ken Moore <ken@pcbsd.org> July 2015
// =================================
// This class is a simple subclass of QTcpServer to use SSL connections instead
// =================================
#ifndef _PCBSD_REST_WEB_SSL_SERVER_H
#define _PCBSD_REST_WEB_SSL_SERVER_H
#include <QTcpServer>
#include <QSslSocket>
#include <QTcpSocket>
#include <QQueue>
#include <QSslConfiguration>
#include <QDebug>
class SslServer : public QTcpServer{
Q_OBJECT
private:
QQueue<QSslSocket*> pendingConnections;
public:
SslServer(QObject *parent=0) : QTcpServer(parent){}
~SslServer(){}
bool hasPendingConnections() const{
return !pendingConnections.isEmpty();
}
QSslSocket* nextPendingConnection(){
if( pendingConnections.isEmpty() ){ return 0; }
else{ return pendingConnections.dequeue(); }
}
protected:
void incomingConnection(qintptr socketDescriptor){
QSslSocket *serverSocket = new QSslSocket(this);
qDebug() << "New Ssl Connection:";
//setup any supported encruption types here
serverSocket->setSslConfiguration(QSslConfiguration::defaultConfiguration());
serverSocket->setProtocol(QSsl::SslV3); //no TLS support (all sorts of issues with that)
//serverSocket->setPrivateKey();
//serverSocket->setLocalCertificate();
qDebug() << " - Supported Protocols:" << serverSocket->sslConfiguration().protocol();
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
pendingConnections.enqueue(serverSocket);
//connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
qDebug() << " - Starting Server Encryption Handshake";
serverSocket->startServerEncryption();
} else {
delete serverSocket;
}
}
};
#endif

View File

@@ -87,7 +87,12 @@ bool WebServer::setupWebSocket(quint16 port){
}
bool WebServer::setupTcp(quint16 port){
TCPServer = new QTcpServer(this);
if(!QSslSocket::supportsSsl()){ qDebug() << "No SSL Support on this system!!!"; return false; }
else{
qDebug() << "Using SSL Library:";
qDebug() << " - Version:" << QSslSocket::sslLibraryVersionString();
}
TCPServer = new SslServer(this);
//Setup Connections
connect(TCPServer, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) );
connect(TCPServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) );
@@ -123,7 +128,7 @@ void WebServer::NewSocketConnection(){
if(WSServer!=0){
if(WSServer->hasPendingConnections()){ sock = new WebSocket( WSServer->nextPendingConnection(), generateID(), AUTH); }
}else if(TCPServer!=0){
if(TCPServer->hasPendingConnections()){ sock = new WebSocket( static_cast<QSslSocket*>(TCPServer->nextPendingConnection()), generateID(), AUTH); }
if(TCPServer->hasPendingConnections()){ sock = new WebSocket( TCPServer->nextPendingConnection(), generateID(), AUTH); }
}
if(sock==0){ return; } //no new connection
qDebug() << "New Socket Connection";

View File

@@ -21,7 +21,7 @@
#include "WebSocket.h"
#include "AuthorizationManager.h"
#include "SslServer.h"
class WebServer : public QObject{
Q_OBJECT
public:
@@ -35,7 +35,7 @@ public slots:
private:
QWebSocketServer *WSServer;
QTcpServer *TCPServer;
SslServer *TCPServer;
QList<WebSocket*> OpenSockets;
AuthorizationManager *AUTH;
QFileSystemWatcher *watcher;

View File

@@ -9,7 +9,8 @@ HEADERS += WebServer.h \
syscache-client.h \
dispatcher-client.h \
RestStructs.h \
AuthorizationManager.h
AuthorizationManager.h \
SslServer.h
SOURCES += main.cpp \
WebServer.cpp \