Skip to content

Commit

Permalink
Initial code for generating uid
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Feb 6, 2024
1 parent 65f9b1d commit 0c61797
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
43 changes: 43 additions & 0 deletions src/systray/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define PRE_20H1_DWMWA_USE_IMMERSIVE_DARK_MODE 19
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#else
#include <QtCore/QMessageAuthenticationCode>
#include <QtCore/QStandardPaths>
#include <dlfcn.h>
#include <pwd.h>
Expand All @@ -32,6 +33,17 @@
#include <linux/limits.h>
#endif

constexpr const uint8_t mod_desktop_hash[] = {
0xe4, 0xf7, 0x0d, 0xe9, 0x77, 0xb8, 0x47, 0xe0, 0xba, 0x2e, 0x70, 0x14, 0x93, 0x7a, 0xce, 0xa7
};

constexpr uint8_t char2u8(const uint8_t c)
{
return c >= '0' && c <= '9' ? c - '0'
: c >= 'a' && c <= 'f' ? 0xa + c - 'a'
: 0;
}

void initEvironment()
{
// base environment details
Expand Down Expand Up @@ -126,6 +138,37 @@ void initEvironment()
const size_t dataDirLen = std::strlen(dataDir);
#endif

// generate UID
#if defined(__APPLE__)
// TODO
#elif defined(_WIN32)
// TODO
#else
if (FILE* const f = fopen("/etc/machine-id", "r"))
{
size_t len;
if (fread(path, PATH_MAX - 1, 1, f) == 0 && (len = strlen(path)) >= 33)
{
uint8_t idkey[16];
for (int i=0; i<16; ++i)
{
idkey[i] = char2u8(path[i*2]) << 4;
idkey[i] |= char2u8(path[i*2+1]) << 0;
}

QMessageAuthenticationCode qhash(QCryptographicHash::Sha256);
qhash.setKey(QByteArray::fromRawData(reinterpret_cast<const char*>(idkey), sizeof(idkey)));
qhash.addData(reinterpret_cast<const char*>(mod_desktop_hash), sizeof(mod_desktop_hash));

QByteArray qresult(qhash.result().toHex(':').toUpper());
qresult.truncate(32 + 15);

setenv("MOD_DEVICE_UID", qresult.constData(), 1);
}
fclose(f);
}
#endif

// set path to factory pedalboards
#ifdef _WIN32
std::memcpy(path, appDir, appDirLen * sizeof(WCHAR));
Expand Down
5 changes: 0 additions & 5 deletions utils/cxfreeze/mod-ui-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def makedirs(path: str):
#os.environ['MOD_API_KEY'] = os.path.join(resdir, '..', 'mod_api_key.pub')
os.environ['MOD_DEVICE_KEY'] = os.path.join(DEVICE_DIR, 'rsa')
os.environ['MOD_DEVICE_TAG'] = os.path.join(DEVICE_DIR, 'tag')
os.environ['MOD_DEVICE_UID'] = os.path.join(DEVICE_DIR, 'uid')

from datetime import datetime
from random import randint
Expand All @@ -77,10 +76,6 @@ def makedirs(path: str):
with open(os.environ['MOD_DEVICE_TAG'], 'w') as fh:
tag = 'MDS-{0}-0-00-000-{1}'.format(datetime.utcnow().strftime('%Y%m%d'), randint(9000, 9999))
fh.write(tag)
if not os.path.isfile(os.environ['MOD_DEVICE_UID']):
with open(os.environ['MOD_DEVICE_UID'], 'w') as fh:
uid = ':'.join(['{0}{1}'.format(randint(0, 9), randint(0, 9)) for i in range(0, 16)])
fh.write(uid)
if not os.path.isfile(os.environ['MOD_DEVICE_KEY']):
try:
key = RSA.generate(2048)
Expand Down

0 comments on commit 0c61797

Please sign in to comment.