Skip to content

Commit 3bfefbf

Browse files
committed
machine fingerprint generation [optional]
1 parent 7708b56 commit 3bfefbf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

dist/machine/soauth.mjs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
import os from 'node:os';
34
import _sodium from 'libsodium-wrappers';
45

56
await _sodium.ready;
@@ -113,6 +114,34 @@ export const decrypt = function (data) {
113114
}
114115
}
115116

117+
export const fingerprint = function (raw = false) {
118+
// cpu
119+
const cpuData = {};
120+
121+
if (Array.isArray(os.cpus())) {
122+
cpuData.cores = os.cpus().length;
123+
cpuData.models = os.cpus().map(v => v.model);
124+
}
125+
126+
const information = {
127+
os: os.type(),
128+
user: os.userInfo(),
129+
architecture: os.arch(),
130+
cpu: cpuData,
131+
endianness: os.endianness(),
132+
hostname: os.hostname(),
133+
machine: os.machine(),
134+
network: JSON.stringify(os.networkInterfaces()),
135+
platform: os.platform(),
136+
memory: os.totalmem()
137+
}
138+
139+
if (raw) return information;
140+
141+
const buffer = SOAUTH.sodium.crypto_generichash(SOAUTH.sodium.crypto_generichash_BYTES_MAX, JSON.stringify(information));
142+
return SOAUTH.sodium.to_hex(buffer);
143+
}
144+
116145
export default {
117-
serialize_message, setup, get_pubkey, encrypt, decrypt
146+
serialize_message, setup, get_pubkey, encrypt, decrypt, fingerprint
118147
}

machine-test/index.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const options = {
2525
},
2626
};
2727

28+
console.log("");
29+
console.log("NOTE:");
30+
console.log("We are using 'test-machine' as Fingerprint for demo purpose.");
31+
console.log("But we can generate a somewhat unique fingerprint with fingerprint().");
32+
console.log("Fingerprint", soauth.fingerprint());
33+
console.log("");
34+
2835
const req = http.request(options, (res) => {
2936
res.setEncoding('utf8');
3037

0 commit comments

Comments
 (0)