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);
}
#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;
void ClientCertManager::setSslCert(const QByteArray &encoded) {
_certIdentity->setSslCert(QSslCertificate(encoded));
}
+
+
+#endif // HAVE_SSL
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; }
bool _isDirty;
QSslKey _sslKey;
QSslCertificate _sslCert;
+#endif //HAVE_SSL
};
// ========================================
// ClientCertManager
// ========================================
+#ifdef HAVE_SSL
class ClientCertManager : public CertManager {
Q_OBJECT
private:
CertIdentity *_certIdentity;
};
+#endif //HAVE_SSL
#endif //CLIENTIDENTITY_H
#include <QMetaMethod>
#include <QMetaProperty>
#include <QRegExp>
+#ifdef HAVE_SSL
#include <QSslSocket>
+#endif
#include <QThread>
#include <QTime>
#include <QEvent>
}
bool SignalProxy::IODevicePeer::isSecure() const {
+#ifdef HAVE_SSL
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_device);
if(sslSocket)
return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6;
+#endif
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
if(socket)
connect(iodev, SIGNAL(disconnected()), this, SLOT(removePeerBySender()));
connect(iodev, SIGNAL(readyRead()), this, SLOT(dataAvailable()));
+#ifdef HAVE_SSL
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(iodev);
if(sslSocket) {
connect(iodev, SIGNAL(encrypted()), this, SLOT(updateSecureState()));
}
+#endif
if(!iodev->parent())
iodev->setParent(this);
#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())
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
// ========================================
setAllowClientUpdates(true);
}
+void CoreCertManager::setId(IdentityId id) {
+ renameObject(QString::number(id.toInt()));
+}
+
void CoreCertManager::setSslKey(const QByteArray &encoded) {
identity.setSslKey(encoded);
CertManager::setSslKey(encoded);
identity.setSslCert(encoded);
CertManager::setSslCert(encoded);
}
-
-void CoreCertManager::setId(IdentityId id) {
- renameObject(QString::number(id.toInt()));
-}
+#endif //HAVE_SSL
#include "identity.h"
+#ifdef HAVE_SSL
#include <QSslKey>
#include <QSslCertificate>
+#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
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
/*** 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;
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();
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);
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<QString> nicks;
//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() {
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()));
}
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
}
}
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() {
}
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()]);
}
}
+#ifdef HAVE_SSL
void IdentitiesSettingsPage::on_continueUnsecured_clicked() {
_editSsl = true;
}
ui.certOrgLabel->setProperty("sslCert", cert.toPem());
}
+#endif //HAVE_SSL
/*****************************************************************************************/
}
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);
#include "ui_saveidentitiesdlg.h"
#include "ui_nickeditdlg.h"
+#ifdef HAVE_SSL
#include <QSslCertificate>
#include <QSslKey>
+#endif
class QAbstractItemModel;
void save();
void load();
+#ifdef HAVE_SSL
protected:
virtual bool eventFilter(QObject *watched, QEvent *event);
+#endif
private slots:
void coreConnectionStateChanged(bool);
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;
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();
};