mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
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:
58
src/server/SslServer.h
Normal file
58
src/server/SslServer.h
Normal 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
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user