update id - use longer sha1 hash for id

This commit is contained in:
Carsten Haitzler 2022-08-20 08:51:50 +01:00
parent 3c46a6796a
commit 2294ea9f8a
1 changed files with 15 additions and 3 deletions

View File

@ -146,8 +146,12 @@ static void
_update_machid_get(void) _update_machid_get(void)
{ {
FILE *f; FILE *f;
char buf[4096], *c; static const char appid[] = "EnL+7',xkDv&!@*)df%@#hcs$;l%o$fc#^$%&%$FDFeJ$%c^$#";
static const char hex[] = "0123456789abcdef";
char buf[4096], buf2[4096 + 1024], *c;
unsigned char sha[20];
size_t len; size_t len;
int i;
f = fopen("/etc/machine-id", "r"); f = fopen("/etc/machine-id", "r");
if (!f) f = fopen("/var/lib/dbus/machine-id", "r"); if (!f) f = fopen("/var/lib/dbus/machine-id", "r");
@ -159,7 +163,7 @@ _update_machid_get(void)
if (f) if (f)
{ {
len = fread(buf, 1, sizeof(buf) - 1, f); len = fread(buf, 1, sizeof(buf) - 1, f);
if (len > 10) if ((len > 10) && (len < 4000))
{ {
buf[len] = 0; buf[len] = 0;
for (c = buf; *c; c++) for (c = buf; *c; c++)
@ -170,6 +174,14 @@ _update_machid_get(void)
break; break;
} }
} }
snprintf(buf2, sizeof(buf2), "{{%s}}/{{%s}}", buf, appid);
e_sha1_sum((unsigned char *)buf2, strlen(buf2), sha);
for (i = 0; i < 20; i++)
{
buf[(i * 2) + 0] = hex[((sha[i] >> 4) & 0xf)];
buf[(i * 2) + 1] = hex[((sha[i] ) & 0xf)];
}
buf[(i * 2)] = 0;
machid = strdup(buf); machid = strdup(buf);
fclose(f); fclose(f);
return; return;
@ -187,7 +199,6 @@ _update_machid_get(void)
t = ecore_time_unix_get(); t = ecore_time_unix_get();
fprintf(f, "%1.16f-%i-%i\n", t, rand(), rand()); fprintf(f, "%1.16f-%i-%i\n", t, rand(), rand());
fclose(f); fclose(f);
_update_machid_get();
return; return;
} }
// this just is all a wash - just use this // this just is all a wash - just use this
@ -259,6 +270,7 @@ e_update_init(void)
_update_timeout_cb(NULL); _update_timeout_cb(NULL);
e_config->update.check = 1; e_config->update.check = 1;
} }
_update_machid_get();
} }
return 1; return 1;
} }