summaryrefslogtreecommitdiffstats
path: root/src/net/SslServer.cpp
diff options
context:
space:
mode:
authorSebastian2010-05-12 19:42:27 +0200
committerSebastian2010-05-12 19:42:27 +0200
commitce3329047d378a14006ce74ec273ac59e3375303 (patch)
tree782430f270b4c7aca1b35d5b7813518e3797c555 /src/net/SslServer.cpp
downloadpvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.gz
pvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.xz
pvs-ce3329047d378a14006ce74ec273ac59e3375303.zip
initial import of latest svn version
Diffstat (limited to 'src/net/SslServer.cpp')
-rw-r--r--src/net/SslServer.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/net/SslServer.cpp b/src/net/SslServer.cpp
new file mode 100644
index 0000000..e353e0a
--- /dev/null
+++ b/src/net/SslServer.cpp
@@ -0,0 +1,130 @@
+/*
+# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# src/net/SslServer.cpp
+# - provide QTcpServer-like behaviour for SSL
+# -----------------------------------------------------------------------------
+*/
+
+#include "SslServer.h"
+#include <QtNetwork/QSslCipher>
+#include <QtNetwork/QSslSocket>
+#include "src/util/CertManager.h"
+
+
+SslServer::SslServer()
+{
+ _tmr = startTimer(7000);
+ //QSslSocket::setDefaultCiphers(QSslSocket::supportedCiphers());
+}
+
+SslServer::~SslServer()
+{
+ killTimer((_tmr));
+}
+
+void SslServer::incomingConnection(int socketDescriptor)
+{
+ QSslSocket *serverSocket = new QSslSocket(this);
+ connect(serverSocket,
+ SIGNAL(sslErrors(const QList<QSslError> &)),
+ this,
+ SLOT(sslErrors(const QList<QSslError> &))
+ );
+ serverSocket->setPrivateKey(CertManager::getPrivateKey("manager"));
+ serverSocket->setLocalCertificate(CertManager::getCertificate("manager"));
+ serverSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
+ serverSocket->setProtocol(QSsl::SslV3);
+ //printf("Keylen %d\n", serverSocket->privateKey().length());
+ if (serverSocket->setSocketDescriptor(socketDescriptor))
+ {
+ // Once the connection is successfully encrypted, raise out newConnection event
+ connect(serverSocket, SIGNAL(encrypted()), this, SIGNAL(newConnection()));
+ serverSocket->startServerEncryption();
+ _pending.push_back(serverSocket);
+ }
+ else
+ {
+ delete serverSocket;
+ }
+}
+
+void SslServer :: sslErrors ( const QList<QSslError> & errors )
+{
+ printf("FIXME: SSL ERRORS on SERVER: %s\n", errors.begin()->errorString().toUtf8().data());
+}
+
+void SslServer::timerEvent (QTimerEvent* event)
+{
+ // Remove all sockets marked for deletion
+ for (QList<QSslSocket*>::iterator it = _delete.begin(); it != _delete.end(); it++)
+ {
+ (*it)->deleteLater();
+ }
+ _delete.clear();
+ // Mark all sockets for deletion where the ssl handshake did not happen after connecting
+ /*
+ bool flag;
+ do
+ {
+ flag = false;
+ for (QList<QSslSocket*>::iterator it = _pending.begin(); it != _pending.end(); it++)
+ {
+ if ((*it)->state() != QAbstractSocket::ConnectedState || !(*it)->isEncrypted())
+ {
+ _delete.push_back(*it);
+ _pending.removeAll(*it);
+ flag = true;
+ break;
+ }
+
+ }
+ }
+ while (flag);
+ */
+ _delete.append(_pending);
+ _pending.clear();
+}
+
+bool SslServer::hasPendingConnections()
+{
+ for (QList<QSslSocket*>::iterator it = _pending.begin(); it != _pending.end(); it++)
+ {
+ printf("State: %d - Encrypted: %d\n", (int)(*it)->state(), (*it)->isEncrypted());
+ if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted()) return true;
+ }
+ return false;
+}
+
+QTcpSocket* SslServer::nextPendingConnection()
+{
+ for (QList<QSslSocket*>::iterator it = _pending.begin(); it != _pending.end(); it++)
+ {
+ if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted())
+ {
+ _pending.removeAll(*it);
+ _delete.removeAll(*it);
+ return *it;
+ }
+ }
+ for (QList<QSslSocket*>::iterator it = _delete.begin(); it != _delete.end(); it++)
+ {
+ if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted())
+ {
+ _pending.removeAll(*it);
+ _delete.removeAll(*it);
+ return *it;
+ }
+ }
+ return NULL;
+}
+
+