#include <QMetaMethod>
#include <QMetaProperty>
#include <QRegExp>
+#include <QSslSocket>
#include <QThread>
#include <QTime>
#include <QEvent>
dispatchPackedFunc(QVariant(packedFunc));
}
+bool SignalProxy::IODevicePeer::isSecure() const {
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_device);
+ if(sslSocket)
+ return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6;
+
+ QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
+ if(socket)
+ return socket->localAddress() == QHostAddress::LocalHost || socket->localAddress() == QHostAddress::LocalHostIPv6;
+
+ return false;
+}
+
QString SignalProxy::IODevicePeer::address() const {
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
if(socket)
void SignalProxy::init() {
connect(&_heartBeatTimer, SIGNAL(timeout()), this, SLOT(sendHeartBeat()));
_heartBeatTimer.start(30 * 1000);
+ _secure = false;
+ updateSecureState();
}
void SignalProxy::initServer() {
connect(iodev, SIGNAL(disconnected()), this, SLOT(removePeerBySender()));
connect(iodev, SIGNAL(readyRead()), this, SLOT(dataAvailable()));
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(iodev);
+ if(sslSocket) {
+ connect(iodev, SIGNAL(encrypted()), this, SLOT(updateSecureState()));
+ }
+
if(!iodev->parent())
iodev->setParent(this);
if(_peers.count() == 1)
emit connected();
+ updateSecureState();
return true;
}
if(_peers.count() == 1)
emit connected();
+ updateSecureState();
return true;
}
delete peer;
+ updateSecureState();
+
if(_peers.isEmpty())
emit disconnected();
}
signalsuffix = signalsuffix.mid(baseName.count()).toLower();
slotprefix = slotprefix.left(slotprefix.count() - baseName.count()).toLower();
}
-
+
uint sizediff = qAbs(slotprefix.size() - signalsuffix.size());
int ratio = editingDistance(slotprefix, signalsuffix) - sizediff;
// if(ratio < 2) {
iter++;
}
}
+
+void SignalProxy::updateSecureState() {
+ bool wasSecure = _secure;
+
+ _secure = !_peers.isEmpty();
+ PeerHash::const_iterator peerIter;
+ for(peerIter = _peers.constBegin(); peerIter != _peers.constEnd(); peerIter++) {
+ _secure &= (*peerIter)->isSecure();
+ }
+
+ if(wasSecure != _secure)
+ emit secureStateChanged(_secure);
+}
*/
static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item, bool compressed = false);
+ bool isSecure() const { return _secure; }
+
static QString methodBaseName(const QMetaMethod &method);
const QList<int> &argTypes(QObject *obj, int methodId);
void sendHeartBeat();
void receiveHeartBeat(AbstractPeer *peer, const QVariantList ¶ms);
void receiveHeartBeatReply(AbstractPeer *peer, const QVariantList ¶ms);
-
+
+ void updateSecureState();
+
signals:
void peerRemoved(QIODevice *dev);
void connected();
void disconnected();
void objectInitialized(SyncableObject *);
void lagUpdated(int lag);
-
+ void securityChanged(bool);
+ void secureStateChanged(bool);
+
private:
void init();
void initServer();
virtual ~AbstractPeer() {}
inline PeerType type() const { return _type; }
virtual void dispatchSignal(const RequestType &requestType, const QVariantList ¶ms) = 0;
+ virtual bool isSecure() const = 0;
private:
PeerType _type;
};
public:
IODevicePeer(QIODevice *device, bool compress) : AbstractPeer(AbstractPeer::IODevicePeer), _device(device), byteCount(0), usesCompression(compress), sentHeartBeats(0), lag(0) {}
virtual void dispatchSignal(const RequestType &requestType, const QVariantList ¶ms);
+ virtual bool isSecure() const;
inline void dispatchPackedFunc(const QVariant &packedFunc) { SignalProxy::writeDataToDevice(_device, packedFunc, usesCompression); }
QString address() const;
inline bool isOpen() const { return _device->isOpen(); }
public:
SignalProxyPeer(SignalProxy *sender, SignalProxy *receiver) : AbstractPeer(AbstractPeer::SignalProxyPeer), sender(sender), receiver(receiver) {}
virtual void dispatchSignal(const RequestType &requestType, const QVariantList ¶ms);
+ virtual inline bool isSecure() const { return true; }
private:
SignalProxy *sender;
SignalProxy *receiver;
ProxyMode _proxyMode;
QTimer _heartBeatTimer;
+
+ bool _secure; // determines if all connections are in a secured state (using ssl or internal connections)
friend class SignalRelay;
};
QMetaObject::invokeMethod(this, methodname.toAscii(), genericvalue);
properties[SignalProxy::methodBaseName(method)] = value;
- // qDebug() << ">>> SYNC:" << methodBaseName(method) << value;
}
// properties["Payload"] = QByteArray(10000000, 'a'); // for testing purposes
return properties;
connect(ui.nicknameList, SIGNAL(itemSelectionChanged()), this, SLOT(setWidgetStates()));
#ifdef HAVE_SSL
- ui.keyAndCertSettings->setCurrentIndex(1);
+ if(Client::signalProxy()->isSecure())
+ ui.keyAndCertSettings->setCurrentIndex(2);
+ else
+ ui.keyAndCertSettings->setCurrentIndex(1);
#else
ui.keyAndCertSettings->setCurrentIndex(0);
#endif