Switched to sha512/sha256 by using QCA
This commit is contained in:
parent
0f3031a5ab
commit
9f684a43d2
4 changed files with 41 additions and 10 deletions
|
@ -27,6 +27,9 @@ CONFIGURE_FILE(
|
|||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/parsed/)
|
||||
|
||||
FIND_PACKAGE(QCA REQUIRED)
|
||||
SET( Plugin_LIBRARIES ${QCA_LIBRARY} )
|
||||
|
||||
SET(TELLDUS_LIVE_PUBLIC_KEY "" CACHE STRING "Telldus Live! public key")
|
||||
SET(TELLDUS_LIVE_PRIVATE_KEY "" CACHE STRING "Telldus Live! private key")
|
||||
SET(TELLDUS_LIVE_HOST "live.telldus.se" CACHE STRING "Telldus Live! Connection Host")
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <QtNetwork>
|
||||
#include <QtCore>
|
||||
#include <QDesktopServices>
|
||||
#include <QCryptographicHash>
|
||||
#include <QtCrypto>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -13,13 +13,21 @@ public:
|
|||
QTimer timer;
|
||||
bool registered;
|
||||
QUrl registerUrl;
|
||||
QString mac;
|
||||
QString mac, hashMethod;
|
||||
QCA::Initializer qcaInit;
|
||||
};
|
||||
|
||||
LiveObject::LiveObject( QScriptEngine *engine, QObject * parent )
|
||||
: QObject(parent)
|
||||
{
|
||||
d = new PrivateData;
|
||||
d->hashMethod = "sha1";
|
||||
foreach(QString hash, QStringList() << "sha512" << "sha256") {
|
||||
if (QCA::isSupported(hash.toLocal8Bit())) {
|
||||
d->hashMethod = hash;
|
||||
break;
|
||||
}
|
||||
}
|
||||
d->registered = false;
|
||||
d->socket = new QSslSocket(this);
|
||||
d->socket->setProtocol( QSsl::TlsV1 );
|
||||
|
@ -115,6 +123,7 @@ void LiveObject::p_connected() {
|
|||
LiveMessage msg("Register");
|
||||
msg.append(d->mac);
|
||||
msg.append(TELLDUS_LIVE_PUBLIC_KEY);
|
||||
msg.append(d->hashMethod);
|
||||
this->sendMessage(msg);
|
||||
emit connected();
|
||||
}
|
||||
|
@ -146,6 +155,21 @@ void LiveObject::sslErrors( const QList<QSslError> & errors ) {
|
|||
}
|
||||
}
|
||||
|
||||
QByteArray LiveObject::signatureForMessage( const QByteArray &message ) {
|
||||
if (QCA::isSupported(d->hashMethod.toLocal8Bit())) {
|
||||
QCA::Hash signature(d->hashMethod);
|
||||
signature.update(message);
|
||||
signature.update(TELLDUS_LIVE_PRIVATE_KEY);
|
||||
return signature.final().toByteArray().toHex();
|
||||
}
|
||||
|
||||
//Fallback to builtin function
|
||||
QCryptographicHash signature( QCryptographicHash::Sha1 );
|
||||
signature.addData(message);
|
||||
signature.addData(TELLDUS_LIVE_PRIVATE_KEY);
|
||||
return signature.result().toHex();
|
||||
}
|
||||
|
||||
QNetworkInterface LiveObject::interfaceFromAddress( const QHostAddress &address ) {
|
||||
QList<QNetworkInterface> interfaceList = QNetworkInterface::allInterfaces();
|
||||
foreach (QNetworkInterface i, interfaceList) {
|
||||
|
@ -158,10 +182,3 @@ QNetworkInterface LiveObject::interfaceFromAddress( const QHostAddress &address
|
|||
return QNetworkInterface();
|
||||
}
|
||||
|
||||
QByteArray LiveObject::signatureForMessage( const QByteArray &message ) {
|
||||
QCryptographicHash signature( QCryptographicHash::Sha1 );
|
||||
signature.addData(message);
|
||||
signature.addData(TELLDUS_LIVE_PRIVATE_KEY);
|
||||
|
||||
return signature.result().toHex();
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ private slots:
|
|||
|
||||
private:
|
||||
void sendMessage(const LiveMessage &message);
|
||||
QByteArray signatureForMessage( const QByteArray &message );
|
||||
static QNetworkInterface interfaceFromAddress( const QHostAddress &address );
|
||||
static QByteArray signatureForMessage( const QByteArray &message );
|
||||
|
||||
class PrivateData;
|
||||
PrivateData *d;
|
||||
|
|
11
telldus-gui/cmake/FindQCA.cmake
Normal file
11
telldus-gui/cmake/FindQCA.cmake
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
FIND_LIBRARY( QCA_LIBRARY QCA )
|
||||
|
||||
IF (WIN32)
|
||||
GET_FILENAME_COMPONENT(QCA_PATH ${QCA_LIBRARY} PATH)
|
||||
MESSAGE(${QCA_PATH})
|
||||
INCLUDE_DIRECTORIES(
|
||||
${QCA_PATH}/../include/QtCrypto/
|
||||
)
|
||||
|
||||
ENDIF (WIN32)
|
Loading…
Add table
Add a link
Reference in a new issue