1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "sslserver.h"
24 # include <QSslSocket>
35 SslServer::SslServer(QObject *parent)
38 setCertificate(quasselDir().absolutePath() + "/quasselCert.pem");
41 QTcpSocket *SslServer::nextPendingConnection() {
42 if(_pendingConnections.isEmpty())
45 return _pendingConnections.takeFirst();
48 void SslServer::incomingConnection(int socketDescriptor) {
49 QSslSocket *serverSocket = new QSslSocket(this);
50 if(serverSocket->setSocketDescriptor(socketDescriptor)) {
52 serverSocket->setLocalCertificate(_cert);
53 serverSocket->setPrivateKey(_key);
55 _pendingConnections << serverSocket;
62 bool SslServer::setCertificate(const QString &path) {
70 if (! certFile.exists()) {
71 qWarning() << "SslServer: Certificate file" << qPrintable(path) << "does not exist";
75 if (! certFile.open(QIODevice::ReadOnly)) {
77 << "SslServer: Failed to open certificate file" << qPrintable(path)
78 << "error:" << certFile.error();
81 _cert = QSslCertificate(&certFile);
83 if (! certFile.reset()) {
84 qWarning() << "SslServer: IO error reading certificate file";
88 _key = QSslKey(&certFile, QSsl::Rsa);
92 qWarning() << "SslServer:" << qPrintable(path) << "contains no certificate data";
95 if (! _cert.isValid()) {
96 qWarning() << "SslServer: Invalid certificate";
100 qWarning() << "SslServer:" << qPrintable(path) << "contains no key data";