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>
34
SslServer::SslServer(QObject *parent)
38
static bool sslWarningShown = false;
39
if(!setCertificate(Quassel::configDirPath() + "quasselCert.pem")) {
40
if(!sslWarningShown) {
42
<< "SslServer: Unable to set certificate file\n"
43
<< " Quassel Core will still work, but cannot provide SSL for client connections.\n"
44
<< " Please see http://quassel-irc.org/faq/cert to learn how to enable SSL support.";
50
QTcpSocket *SslServer::nextPendingConnection() {
51
if(_pendingConnections.isEmpty())
54
return _pendingConnections.takeFirst();
57
void SslServer::incomingConnection(int socketDescriptor) {
58
QSslSocket *serverSocket = new QSslSocket(this);
59
if(serverSocket->setSocketDescriptor(socketDescriptor)) {
61
serverSocket->setLocalCertificate(_cert);
62
serverSocket->setPrivateKey(_key);
64
_pendingConnections << serverSocket;
71
bool SslServer::setCertificate(const QString &path) {
78
if(!certFile.exists()) {
79
quWarning() << "SslServer: Certificate file" << qPrintable(path) << "does not exist";
83
if(!certFile.open(QIODevice::ReadOnly)) {
85
<< "SslServer: Failed to open certificate file" << qPrintable(path)
86
<< "error:" << certFile.error();
89
_cert = QSslCertificate(&certFile);
91
if(!certFile.reset()) {
92
quWarning() << "SslServer: IO error reading certificate file";
96
_key = QSslKey(&certFile, QSsl::Rsa);
100
quWarning() << "SslServer:" << qPrintable(path) << "contains no certificate data";
103
if(!_cert.isValid()) {
104
quWarning() << "SslServer: Invalid certificate";
108
quWarning() << "SslServer:" << qPrintable(path) << "contains no key data";