u
This commit is contained in:
@@ -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, '-'),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user