From 1adc00219ba072da57994764d086beed8ffb7bb4 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 25 Dec 2008 17:21:53 +0100 Subject: [PATCH 1/1] adding tons of ifdefs so quassel will build again without ssl support --- src/client/client.cpp | 2 + src/client/clientidentity.cpp | 22 +++++++--- src/client/clientidentity.h | 10 ++++- src/common/signalproxy.cpp | 6 +++ src/core/coreidentity.cpp | 40 ++++++++++++++----- src/core/coreidentity.h | 20 +++++++--- src/core/coresession.cpp | 6 +++ src/core/sqlitestorage.cpp | 13 ++++++ .../settingspages/identitiessettingspage.cpp | 16 ++++++++ .../settingspages/identitiessettingspage.h | 10 +++++ 10 files changed, 123 insertions(+), 22 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 310e8e49..295e062e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -221,8 +221,10 @@ const Identity *Client::identity(IdentityId id) { void Client::createIdentity(const CertIdentity &id) { QVariantMap additional; +#ifdef HAVE_SSL additional["KeyPem"] = id.sslKey().toPem(); additional["CertPem"] = id.sslCert().toPem(); +#endif emit instance()->requestCreateIdentity(id, additional); } diff --git a/src/client/clientidentity.cpp b/src/client/clientidentity.cpp index 1d93d64b..c8e8df95 100644 --- a/src/client/clientidentity.cpp +++ b/src/client/clientidentity.cpp @@ -24,28 +24,35 @@ #include "signalproxy.h" CertIdentity::CertIdentity(IdentityId id, QObject *parent) - : Identity(id, parent), - _certManager(0), + : Identity(id, parent) +#ifdef HAVE_SSL + , _certManager(0), _isDirty(false) +#endif { } CertIdentity::CertIdentity(const Identity &other, QObject *parent) - : Identity(other, parent), - _certManager(0), + : Identity(other, parent) +#ifdef HAVE_SSL + , _certManager(0), _isDirty(false) +#endif { } CertIdentity::CertIdentity(const CertIdentity &other, QObject *parent) - : Identity(other, parent), - _certManager(0), + : Identity(other, parent) +#ifdef HAVE_SSL + , _certManager(0), _isDirty(other._isDirty), _sslKey(other._sslKey), _sslCert(other._sslCert) +#endif { } +#ifdef HAVE_SSL void CertIdentity::enableEditSsl(bool enable) { if(!enable || _certManager) return; @@ -97,3 +104,6 @@ void ClientCertManager::setSslKey(const QByteArray &encoded) { void ClientCertManager::setSslCert(const QByteArray &encoded) { _certIdentity->setSslCert(QSslCertificate(encoded)); } + + +#endif // HAVE_SSL diff --git a/src/client/clientidentity.h b/src/client/clientidentity.h index 680ac956..62773f1c 100644 --- a/src/client/clientidentity.h +++ b/src/client/clientidentity.h @@ -33,9 +33,14 @@ public: CertIdentity(const Identity &other, QObject *parent = 0); CertIdentity(const CertIdentity &other, QObject *parent = 0); - void enableEditSsl(bool enable = true); +#ifdef HAVE_SSL inline bool isDirty() const { return _isDirty; } +#else + inline bool isDirty() const { return false; } +#endif +#ifdef HAVE_SSL + void enableEditSsl(bool enable = true); inline const QSslKey &sslKey() const { return _sslKey; } inline const QSslCertificate &sslCert() const { return _sslCert; } @@ -56,11 +61,13 @@ private: bool _isDirty; QSslKey _sslKey; QSslCertificate _sslCert; +#endif //HAVE_SSL }; // ======================================== // ClientCertManager // ======================================== +#ifdef HAVE_SSL class ClientCertManager : public CertManager { Q_OBJECT @@ -77,5 +84,6 @@ public slots: private: CertIdentity *_certIdentity; }; +#endif //HAVE_SSL #endif //CLIENTIDENTITY_H diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index a9172fc2..7c43592c 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -32,7 +32,9 @@ #include #include #include +#ifdef HAVE_SSL #include +#endif #include #include #include @@ -214,9 +216,11 @@ void SignalProxy::IODevicePeer::dispatchSignal(const RequestType &requestType, c } bool SignalProxy::IODevicePeer::isSecure() const { +#ifdef HAVE_SSL QSslSocket *sslSocket = qobject_cast(_device); if(sslSocket) return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6; +#endif QAbstractSocket *socket = qobject_cast(_device); if(socket) @@ -335,10 +339,12 @@ bool SignalProxy::addPeer(QIODevice* iodev) { connect(iodev, SIGNAL(disconnected()), this, SLOT(removePeerBySender())); connect(iodev, SIGNAL(readyRead()), this, SLOT(dataAvailable())); +#ifdef HAVE_SSL QSslSocket *sslSocket = qobject_cast(iodev); if(sslSocket) { connect(iodev, SIGNAL(encrypted()), this, SLOT(updateSecureState())); } +#endif if(!iodev->parent()) iodev->setParent(this); diff --git a/src/core/coreidentity.cpp b/src/core/coreidentity.cpp index 6fe0e975..a82ef95e 100644 --- a/src/core/coreidentity.cpp +++ b/src/core/coreidentity.cpp @@ -23,33 +23,48 @@ #include "signalproxy.h" CoreIdentity::CoreIdentity(IdentityId id, QObject *parent) - : Identity(id, parent), - _certManager(*this) + : Identity(id, parent) +#ifdef HAVE_SSL + , _certManager(*this) +#endif { +#ifdef HAVE_SSL connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId))); +#endif } CoreIdentity::CoreIdentity(const Identity &other, QObject *parent) - : Identity(other, parent), - _certManager(*this) + : Identity(other, parent) +#ifdef HAVE_SSL + , _certManager(*this) +#endif { +#ifdef HAVE_SSL connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId))); +#endif } CoreIdentity::CoreIdentity(const CoreIdentity &other, QObject *parent) - : Identity(other, parent), - _sslKey(other._sslKey), + : Identity(other, parent) +#ifdef HAVE_SSL + , _sslKey(other._sslKey), _sslCert(other._sslCert), _certManager(*this) +#endif { +#ifdef HAVE_SSL connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId))); +#endif } void CoreIdentity::synchronize(SignalProxy *proxy) { proxy->synchronize(this); +#ifdef HAVE_SSL proxy->synchronize(&_certManager); +#endif } +#ifdef HAVE_SSL void CoreIdentity::setSslKey(const QByteArray &encoded) { QSslKey key(encoded, QSsl::Rsa); if(key.isNull()) @@ -60,14 +75,18 @@ void CoreIdentity::setSslKey(const QByteArray &encoded) { void CoreIdentity::setSslCert(const QByteArray &encoded) { setSslCert(QSslCertificate(encoded)); } +#endif CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity) { Identity::operator=(identity); +#ifdef HAVE_SSL _sslKey = identity._sslKey; _sslCert = identity._sslCert; +#endif return *this; } +#ifdef HAVE_SSL // ======================================== // CoreCertManager // ======================================== @@ -78,6 +97,10 @@ CoreCertManager::CoreCertManager(CoreIdentity &identity) setAllowClientUpdates(true); } +void CoreCertManager::setId(IdentityId id) { + renameObject(QString::number(id.toInt())); +} + void CoreCertManager::setSslKey(const QByteArray &encoded) { identity.setSslKey(encoded); CertManager::setSslKey(encoded); @@ -87,7 +110,4 @@ void CoreCertManager::setSslCert(const QByteArray &encoded) { identity.setSslCert(encoded); CertManager::setSslCert(encoded); } - -void CoreCertManager::setId(IdentityId id) { - renameObject(QString::number(id.toInt())); -} +#endif //HAVE_SSL diff --git a/src/core/coreidentity.h b/src/core/coreidentity.h index f87f5314..8033030f 100644 --- a/src/core/coreidentity.h +++ b/src/core/coreidentity.h @@ -23,33 +23,39 @@ #include "identity.h" +#ifdef HAVE_SSL #include #include +#endif //HAVE_SSL -class CoreIdentity; class SignalProxy; // ======================================== // CoreCertManager // ======================================== +#ifdef HAVE_SSL +class CoreIdentity; class CoreCertManager : public CertManager { Q_OBJECT public: CoreCertManager(CoreIdentity &identity); + void setId(IdentityId id); + +#ifdef HAVE_SSL virtual const QSslKey &sslKey() const; virtual const QSslCertificate &sslCert() const; public slots: virtual void setSslKey(const QByteArray &encoded); virtual void setSslCert(const QByteArray &encoded); - - void setId(IdentityId id); +#endif private: CoreIdentity &identity; }; +#endif //HAVE_SSL // ========================================= // CoreIdentity @@ -64,29 +70,33 @@ public: void synchronize(SignalProxy *proxy); +#ifdef HAVE_SSL inline const QSslKey &sslKey() const { return _sslKey; } inline void setSslKey(const QSslKey &key) { _sslKey = key; } void setSslKey(const QByteArray &encoded); inline const QSslCertificate &sslCert() const { return _sslCert; } inline void setSslCert(const QSslCertificate &cert) { _sslCert = cert; } void setSslCert(const QByteArray &encoded); +#endif HAVE_SSL CoreIdentity& CoreIdentity::operator=(const CoreIdentity &identity); private: +#ifdef HAVE_SSL QSslKey _sslKey; QSslCertificate _sslCert; CoreCertManager _certManager; +#endif }; +#ifdef HAVE_SSL inline const QSslKey &CoreCertManager::sslKey() const { return identity.sslKey(); } inline const QSslCertificate &CoreCertManager::sslCert() const { return identity.sslCert(); } - - +#endif #endif //COREIDENTITY_H diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 3a05f52b..f18f9269 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -285,11 +285,17 @@ void CoreSession::scriptRequest(QString script) { /*** Identity Handling ***/ void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional) { +#ifndef HAVE_SSL + Q_UNUSED(additional) +#endif + CoreIdentity coreIdentity(identity); +#ifdef HAVE_SSL if(additional.contains("KeyPem")) coreIdentity.setSslKey(additional["KeyPem"].toByteArray()); if(additional.contains("CertPem")) coreIdentity.setSslCert(additional["CertPem"].toByteArray()); +#endif IdentityId id = Core::createIdentity(user(), coreIdentity); if(!id.isValid()) return; diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index a418d055..392459bf 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -214,8 +214,14 @@ IdentityId SqliteStorage::createIdentity(UserId user, CoreIdentity &identity) { query.bindValue(":kickreason", identity.kickReason()); query.bindValue(":partreason", identity.partReason()); query.bindValue(":quitreason", identity.quitReason()); +#ifdef HAVE_SSL query.bindValue(":sslcert", identity.sslCert().toPem()); query.bindValue(":sslkey", identity.sslKey().toPem()); +#else + query.bindValue(":sslcert", QByteArray()); + query.bindValue(":sslkey", QByteArray()); +#endif + safeExec(query); identityId = query.lastInsertId().toInt(); @@ -269,8 +275,13 @@ bool SqliteStorage::updateIdentity(UserId user, const CoreIdentity &identity) { query.bindValue(":kickreason", identity.kickReason()); query.bindValue(":partreason", identity.partReason()); query.bindValue(":quitreason", identity.quitReason()); +#ifdef HAVE_SSL query.bindValue(":sslcert", identity.sslCert().toPem()); query.bindValue(":sslkey", identity.sslKey().toPem()); +#else + query.bindValue(":sslcert", QByteArray()); + query.bindValue(":sslkey", QByteArray()); +#endif query.bindValue(":identityid", identity.id().toInt()); safeExec(query); @@ -344,8 +355,10 @@ QList SqliteStorage::identities(UserId user) { identity.setKickReason(query.value(15).toString()); identity.setPartReason(query.value(16).toString()); identity.setQuitReason(query.value(17).toString()); +#ifdef HAVE_SSL identity.setSslCert(query.value(18).toByteArray()); identity.setSslKey(query.value(19).toByteArray()); +#endif nickQuery.bindValue(":identityid", identity.id().toInt()); QList nicks; diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index e8bb680f..788df96d 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -80,10 +80,12 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) //connect(ui.nicknameList, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(setWidgetStates())); //connect(ui.nicknameList->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(nicklistHasChanged())); +#ifdef HAVE_SSL ui.sslKeyGroupBox->setAcceptDrops(true); ui.sslKeyGroupBox->installEventFilter(this); ui.sslCertGroupBox->setAcceptDrops(true); ui.sslCertGroupBox->installEventFilter(this); +#endif } void IdentitiesSettingsPage::setWidgetStates() { @@ -213,9 +215,13 @@ bool IdentitiesSettingsPage::aboutToSave() { void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) { CertIdentity *identity = new CertIdentity(*Client::identity(id), this); +#ifdef HAVE_SSL identity->enableEditSsl(_editSsl); +#endif insertIdentity(identity); +#ifdef HAVE_SSL connect(identity, SIGNAL(sslSettingsUpdated()), this, SLOT(clientIdentityUpdated())); +#endif connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated())); } @@ -325,8 +331,10 @@ void IdentitiesSettingsPage::displayIdentity(CertIdentity *id, bool dontsave) { ui.kickReason->setText(id->kickReason()); ui.partReason->setText(id->partReason()); ui.quitReason->setText(id->quitReason()); +#ifdef HAVE_SSL showKeyState(id->sslKey()); showCertState(id->sslCert()); +#endif } } @@ -352,8 +360,10 @@ void IdentitiesSettingsPage::saveToIdentity(CertIdentity *id) { id->setKickReason(ui.kickReason->text()); id->setPartReason(ui.partReason->text()); id->setQuitReason(ui.quitReason->text()); +#ifdef HAVE_SSL id->setSslKey(QSslKey(ui.keyTypeLabel->property("sslKey").toByteArray(), (QSsl::KeyAlgorithm)(ui.keyTypeLabel->property("sslKeyType").toInt()))); id->setSslCert(QSslCertificate(ui.certOrgLabel->property("sslCert").toByteArray())); +#endif } void IdentitiesSettingsPage::on_addIdentity_clicked() { @@ -366,7 +376,9 @@ void IdentitiesSettingsPage::on_addIdentity_clicked() { } id = -id.toInt(); CertIdentity *newId = new CertIdentity(id, this); +#ifdef HAVE_SSL newId->enableEditSsl(_editSsl); +#endif if(dlg.duplicateId() != 0) { // duplicate newId->update(*identities[dlg.duplicateId()]); @@ -459,6 +471,7 @@ void IdentitiesSettingsPage::on_nickDown_clicked() { } } +#ifdef HAVE_SSL void IdentitiesSettingsPage::on_continueUnsecured_clicked() { _editSsl = true; @@ -601,6 +614,7 @@ void IdentitiesSettingsPage::showCertState(const QSslCertificate &cert) { } ui.certOrgLabel->setProperty("sslCert", cert.toPem()); } +#endif //HAVE_SSL /*****************************************************************************************/ @@ -659,7 +673,9 @@ SaveIdentitiesDlg::SaveIdentitiesDlg(const QList &toCreate, cons } connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent())); Client::updateIdentity(id->id(), id->toVariantMap()); +#ifdef HAVE_SSL id->requestUpdateSslSettings(); +#endif } foreach(IdentityId id, toRemove) { Client::removeIdentity(id); diff --git a/src/qtui/settingspages/identitiessettingspage.h b/src/qtui/settingspages/identitiessettingspage.h index 1ef82238..37c5ec24 100644 --- a/src/qtui/settingspages/identitiessettingspage.h +++ b/src/qtui/settingspages/identitiessettingspage.h @@ -29,8 +29,10 @@ #include "ui_saveidentitiesdlg.h" #include "ui_nickeditdlg.h" +#ifdef HAVE_SSL #include #include +#endif class QAbstractItemModel; @@ -46,8 +48,10 @@ public slots: void save(); void load(); +#ifdef HAVE_SSL protected: virtual bool eventFilter(QObject *watched, QEvent *event); +#endif private slots: void coreConnectionStateChanged(bool); @@ -67,14 +71,18 @@ private slots: void on_nickUp_clicked(); void on_nickDown_clicked(); +#ifdef HAVE_SSL void on_continueUnsecured_clicked(); void on_clearOrLoadKeyButton_clicked(); void on_clearOrLoadCertButton_clicked(); +#endif void widgetHasChanged(); void setWidgetStates(); +#ifdef HAVE_SSL void sslDragEnterEvent(QDragEnterEvent *event); void sslDropEvent(QDropEvent *event, bool isCert); +#endif private: Ui::IdentitiesSettingsPage ui; @@ -93,10 +101,12 @@ private: void displayIdentity(CertIdentity *, bool dontsave = false); void saveToIdentity(CertIdentity *); +#ifdef HAVE_SSL QSslKey keyByFilename(const QString &filename); void showKeyState(const QSslKey &key); QSslCertificate certByFilename(const QString &filename); void showCertState(const QSslCertificate &cert); +#endif bool testHasChanged(); }; -- 2.20.1