hardware fingerprint

This commit is contained in:
SPRINX0\prochazka 2024-09-04 16:08:45 +02:00
parent a256acb203
commit 787d6596bf
2 changed files with 75 additions and 2 deletions

View File

@ -16,6 +16,7 @@ const { getAuthProviderFromReq } = require('../auth/authProvider');
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
const storage = require('./storage');
const { getAuthProxyUrl } = require('../utility/authProxy');
const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
const lock = new AsyncLock();
@ -188,12 +189,12 @@ module.exports = {
startTrial_meta: true,
async startTrial() {
try {
const ipResp = await axios.default.get('https://api.ipify.org?format=json');
const fingerprint = await getPublicHardwareFingerprint();
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, {
type: 'premium-trial',
days: 30,
publicIp: ipResp.data.ip,
fingerprint,
});
const { token } = resp.data;

View File

@ -0,0 +1,72 @@
const axios = require('axios');
const os = require('os');
const crypto = require('crypto');
async function getPublicIp() {
try {
const resp = await axios.default.get('https://api.ipify.org?format=json');
return resp.data.ip || 'unknown-ip';
} catch (err) {
return 'unknown-ip';
}
}
function getMacAddress() {
const interfaces = os.networkInterfaces();
for (let iface of Object.values(interfaces)) {
for (let config of iface) {
if (config.mac && config.mac !== '00:00:00:00:00:00') {
return config.mac;
}
}
}
return '00:00:00:00:00:00';
}
async function getHardwareFingerprint() {
const publicIp = await getPublicIp();
const macAddress = getMacAddress();
const platform = os.platform();
const release = os.release();
const hostname = os.hostname();
const totalMemory = os.totalmem();
return {
publicIp,
macAddress,
platform,
release,
hostname,
totalMemory,
};
}
async function getHardwareFingerprintHash(data = undefined) {
if (!data) {
data = await getHardwareFingerprint();
}
const fingerprintData = JSON.stringify(data);
const hash = crypto.createHash('sha256').update(fingerprintData).digest('hex');
return hash;
}
async function getPublicHardwareFingerprint() {
const fingerprint = await getHardwareFingerprint();
const hash = await getHardwareFingerprintHash(fingerprint);
return {
hash,
payload: {
platform: fingerprint.platform,
},
};
}
// getHardwareFingerprint().then(console.log);
// getHardwareFingerprintHash().then(console.log);
// getPublicHardwareFingerprint().then(console.log);
module.exports = {
getHardwareFingerprint,
getHardwareFingerprintHash,
getPublicHardwareFingerprint,
};