39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import { execSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { logger } from './src/logger.js';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const certsDir = path.join(__dirname, 'certs');
|
|
const keyPath = path.join(certsDir, 'key.pem');
|
|
const certPath = path.join(certsDir, 'cert.pem');
|
|
|
|
fs.mkdirSync(certsDir, { recursive: true });
|
|
|
|
// ECDSA P-256 keeps pairing QR codes much smaller than RSA-2048
|
|
const subject = '/CN=localhost/O=JTL POS Sync/C=DE';
|
|
const san = 'subjectAltName=DNS:localhost,IP:127.0.0.1,IP:0.0.0.0';
|
|
|
|
execSync(
|
|
`openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -keyout "${keyPath}" -out "${certPath}" -days 3650 -subj "${subject}" -addext "${san}"`,
|
|
{ stdio: 'inherit' }
|
|
);
|
|
|
|
const sha1 = execSync(`openssl x509 -in "${certPath}" -noout -fingerprint -sha1`, {
|
|
encoding: 'utf8',
|
|
})
|
|
.trim()
|
|
.split('=')[1];
|
|
const serial = execSync(`openssl x509 -in "${certPath}" -noout -serial`, {
|
|
encoding: 'utf8',
|
|
})
|
|
.trim()
|
|
.split('=')[1];
|
|
|
|
logger.success(`Wrote ${keyPath}`);
|
|
logger.success(`Wrote ${certPath}`);
|
|
logger.info(`Fingerprint: ${sha1.replace(/:/g, '')}`);
|
|
logger.info(`Serial: ${serial}`);
|