This commit is contained in:
seb
2026-09-29 11:21:55 +02:00
parent 3089cc7252
commit cf4af1480b
7 changed files with 173 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import { X509Certificate } from 'node:crypto';
import selfsigned from 'selfsigned';
import env from '../config/env.js';
@@ -69,3 +70,18 @@ export async function getOrCreateCert() {
cert: pems.cert,
};
}
/**
* Derives pairing metadata (fingerprints and serial number) from the TLS certificate.
* @returns {Promise<{ certificateFingerprint: string, certificateSerialNumber: string, serverFingerprint: string }>}
*/
export async function getCertMetadata() {
const { cert } = await getOrCreateCert();
const x509 = new X509Certificate(cert);
const sha1 = x509.fingerprint;
return {
certificateFingerprint: sha1.replace(/:/g, ''),
certificateSerialNumber: x509.serialNumber,
serverFingerprint: sha1.replace(/:/g, '-'),
};
}