forked from organicmaps/organicmaps
[qt] Integrated tomcrypt sha1 for unique user id
This commit is contained in:
parent
5beb3e8cde
commit
f373f4e1d5
7 changed files with 40 additions and 16 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = expat freetype fribidi zlib bzip2 jansson protobuf
|
||||
SUBDIRS = expat freetype fribidi zlib bzip2 jansson protobuf tomcrypt
|
||||
|
||||
!iphonesimulator-g++42 {
|
||||
!iphonedevice-g++42 {
|
||||
|
|
|
@ -45,7 +45,7 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
|
|||
|
||||
/* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
|
||||
#ifndef ARGTYPE
|
||||
#define ARGTYPE 0
|
||||
#define ARGTYPE 4
|
||||
#endif
|
||||
|
||||
/* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code
|
||||
|
|
17
3party/tomcrypt/tomcrypt.pro
Normal file
17
3party/tomcrypt/tomcrypt.pro
Normal file
|
@ -0,0 +1,17 @@
|
|||
TARGET = tomcrypt
|
||||
ROOT_DIR = ../..
|
||||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
INCLUDEPATH += src/headers
|
||||
|
||||
TEMPLATE = lib
|
||||
CONFIG += staticlib
|
||||
|
||||
DEFINES += LTC_NO_ROLC
|
||||
|
||||
SOURCES += \
|
||||
src/hashes/sha2/sha256.c \
|
||||
src/hashes/sha1.c \
|
||||
|
||||
HEADERS += \
|
||||
src/headers/tomcrypt.h \
|
|
@ -5,10 +5,12 @@ TEMPLATE = lib
|
|||
CONFIG += staticlib
|
||||
|
||||
ROOT_DIR = ..
|
||||
DEPENDENCIES = base version
|
||||
DEPENDENCIES = base tomcrypt
|
||||
|
||||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
INCLUDEPATH += ../3party/tomcrypt/src/headers
|
||||
|
||||
QT *= core network
|
||||
|
||||
SOURCES += \
|
||||
|
|
|
@ -4,7 +4,7 @@ CONFIG -= app_bundle
|
|||
TEMPLATE = app
|
||||
|
||||
ROOT_DIR = ../..
|
||||
DEPENDENCIES = platform coding base
|
||||
DEPENDENCIES = platform coding base tomcrypt
|
||||
|
||||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
#include "../base/logging.hpp"
|
||||
#include "../base/assert.hpp"
|
||||
|
||||
#include "../coding/bit_shift.hpp"
|
||||
|
||||
#include "../version/version.hpp"
|
||||
|
||||
#include "../std/target_os.hpp"
|
||||
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#include <QFSFileEngine>
|
||||
#include <QDateTime>
|
||||
|
@ -33,11 +31,7 @@ static QString MacAddress()
|
|||
&& hwAddr.size() == 17) // mac length with semicolons
|
||||
{
|
||||
hwAddr.remove(':');
|
||||
bool success = false;
|
||||
qulonglong numAddr = hwAddr.toULongLong(&success, 16);
|
||||
numAddr = bits::ror(numAddr, 11);
|
||||
if (success)
|
||||
return QString("%1").arg(numAddr);
|
||||
return hwAddr;
|
||||
}
|
||||
}
|
||||
// no valid interface was found
|
||||
|
@ -67,13 +61,24 @@ static QString UniqueClientId()
|
|||
if (result.size() == 0)
|
||||
result = QString("------------");
|
||||
}
|
||||
// calculate one-way hash
|
||||
QByteArray const original = QByteArray::fromHex(result.toLocal8Bit());
|
||||
unsigned char out[100] = { 0 };
|
||||
hash_state md;
|
||||
if (CRYPT_OK == sha1_init(&md)
|
||||
&& CRYPT_OK == sha1_process(&md, reinterpret_cast<unsigned char const *>(original.constData()),
|
||||
original.size())
|
||||
&& CRYPT_OK == sha1_done(&md, out))
|
||||
{
|
||||
return QByteArray(reinterpret_cast<char const *>(out)).toHex();
|
||||
}
|
||||
// if encryption failed, do not encrypt data
|
||||
return result;
|
||||
}
|
||||
|
||||
static QString UserAgent()
|
||||
{
|
||||
static QString userAgent = QString("MWM(" OMIM_OS_NAME ")/") + QString(VERSION_STRING)
|
||||
+ QString("/") + UniqueClientId();
|
||||
static QString userAgent = UniqueClientId();
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Main application in qt.
|
||||
ROOT_DIR = ..
|
||||
DEPENDENCIES = map storage indexer yg platform geometry coding base freetype expat fribidi version
|
||||
DEPENDENCIES = map storage indexer yg platform geometry coding base freetype expat fribidi tomcrypt version
|
||||
|
||||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue