diff options
| author | Javier <dev.git@javispedro.com> | 2014-12-14 06:03:21 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-12-14 06:03:21 +0100 |
| commit | ab362bf43227552bab209fea792d60d370ce0260 (patch) | |
| tree | 9060d1f9be58b3f4ba73df345fc3e0200994bbaa /daemon/jskitobjects.cpp | |
| parent | 6ad0d9aee73808c95a7af5cac932b63ff2ce15dd (diff) | |
implement account and device tokens
Diffstat (limited to 'daemon/jskitobjects.cpp')
| -rw-r--r-- | daemon/jskitobjects.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/daemon/jskitobjects.cpp b/daemon/jskitobjects.cpp index 5f5acaf..fe924e8 100644 --- a/daemon/jskitobjects.cpp +++ b/daemon/jskitobjects.cpp @@ -4,9 +4,12 @@ #include <QAuthenticator> #include <QBuffer> #include <QDir> +#include <QCryptographicHash> #include <limits> #include "jskitobjects.h" +static const char *token_salt = "0feeb7416d3c4546a19b04bccd8419b1"; + JSKitPebble::JSKitPebble(const AppInfo &info, JSKitManager *mgr) : QObject(mgr), _appInfo(info), _mgr(mgr) { @@ -88,6 +91,42 @@ void JSKitPebble::openURL(const QUrl &url) emit _mgr->appOpenUrl(url); } +QString JSKitPebble::getAccountToken() const +{ + // We do not have any account system, so we just fake something up. + QCryptographicHash hasher(QCryptographicHash::Md5); + + hasher.addData(token_salt, strlen(token_salt)); + hasher.addData(_appInfo.uuid().toByteArray()); + + QString token = _mgr->_settings->property("accountToken").toString(); + if (token.isEmpty()) { + token = QUuid::createUuid().toString(); + logger()->debug() << "created new account token" << token; + _mgr->_settings->setProperty("accountToken", token); + } + hasher.addData(token.toLatin1()); + + QString hash = hasher.result().toHex(); + logger()->debug() << "returning account token" << hash; + + return hash; +} + +QString JSKitPebble::getWatchToken() const +{ + QCryptographicHash hasher(QCryptographicHash::Md5); + + hasher.addData(token_salt, strlen(token_salt)); + hasher.addData(_appInfo.uuid().toByteArray()); + hasher.addData(_mgr->_watch->serialNumber().toLatin1()); + + QString hash = hasher.result().toHex(); + logger()->debug() << "returning watch token" << hash; + + return hash; +} + QJSValue JSKitPebble::createXMLHttpRequest() { JSKitXMLHttpRequest *xhr = new JSKitXMLHttpRequest(_mgr, 0); |
