Vydané zdroje
Stáhnout zdroje ZIP
CH-J Server Manager
Procházejte adresáře a soubory konkrétního vydání aplikace.
Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.
1
"use strict";2
const path = require("node:path");3
const { NativeRunner, biometricError } = require("./nativeRunner");4
const PROVIDERS = Object.freeze({ darwin: { provider: "touch-id", protection: "biometry-current-set" }, win32: { provider: "windows-hello", protection: "convenience" }, linux: { provider: "fprintd", protection: "convenience" } });5
class PlatformAdapter {6
constructor({ platform = process.platform, resourcesPath, appPath, isPackaged = false, getMainWindow = () => null, runner } = {}) {7
this.platform = platform; this.info = PROVIDERS[platform] || { provider: "none", protection: "unavailable" }; this.getMainWindow = getMainWindow;8
const root = isPackaged ? path.join(resourcesPath, "biometrics") : path.join(appPath, "build", "biometrics");9
this.runner = runner || new NativeRunner(platform === "linux" ? { executable: "/usr/bin/python3", args: [isPackaged ? path.join(root, "linux.py") : path.join(appPath, "src/main/security/biometrics/native/linux.py")] } : { executable: path.join(root, platform === "win32" ? "chj-biometric.exe" : "chj-biometric") });10
}11
async call(op, entryId, reason, key, options) {12
if (!PROVIDERS[this.platform]) throw biometricError("BIOMETRIC_UNAVAILABLE");13
if (entryId && !/^[a-f0-9]{64}$/.test(entryId)) throw biometricError("BIOMETRIC_FAILED");14
const window = this.getMainWindow(); let hwnd = "0";15
if (this.platform === "win32" && op !== "status" && op !== "remove") {16
if (!window || window.isDestroyed()) throw biometricError("BIOMETRIC_CANCELLED");17
const buffer = window.getNativeWindowHandle(); hwnd = (buffer.length === 8 ? buffer.readBigUInt64LE() : BigInt(buffer.readUInt32LE())).toString();18
}19
return this.runner.run({ op, entryId, reason: String(reason || "CH-J Server Manager").slice(0, 200), key: key?.toString("base64"), hwnd, pid: process.pid }, options);20
}21
async getAvailability() {22
try {23
const value = await this.call("status");24
return { ...this.info, available: value.available === true, code: value.code || (value.available ? "BIOMETRIC_AVAILABLE" : "BIOMETRIC_UNAVAILABLE") };25
} catch (error) { return { ...this.info, available: false, code: error.code || "BIOMETRIC_UNAVAILABLE" }; }26
}27
enroll(entryId, reason, options) { return this.call("authenticate", entryId, reason, null, options); }28
authenticate(reason, options) { return this.call("authenticate", null, reason, null, options); }29
removeEnrollment(entryId, options) { return this.call("remove", entryId, null, null, options); }30
storeProtectedKey(entryId, key, options) { return this.call("store", entryId, null, key, options); }31
async retrieveProtectedKey(entryId, reason, options) {32
// Each native retrieve operation includes fresh OS authentication before releasing a key.33
const result = await this.call("retrieve", entryId, reason, null, options);34
if (!/^[A-Za-z0-9+/]{43}=$/.test(result.key || "")) throw biometricError("BIOMETRIC_INVALID_KEY");35
const key = Buffer.from(result.key, "base64"); result.key = null;36
if (key.length !== 32) { key.fill(0); throw biometricError("BIOMETRIC_INVALID_KEY"); }37
return key;38
}39
}40
module.exports = { PlatformAdapter, PROVIDERS };SHA-256: 89575011732b737bf96d68aa4f9740da394c13a83f38a740f1444c9acc15a04b
SHA-256 archivu: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0