node-http-server – Rev 35
?pathlinks?
#!/usr/bin/env node
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
const forge = require('node-forge');
const tz = require('moment-timezone');
module.exports = {
// Generate certificates on the fly using incremental serials.
generate: (name, domain, keySize, callback) => {
process.nextTick(() => {
// Generate 1024-bit key-pair.
const keys = forge
.pki
.rsa
.generateKeyPair(keySize);
// Create self-signed certificate.
const cert = forge
.pki
.createCertificate();
cert.serialNumber = tz().tz('UTC').format('x');
cert.publicKey = keys.publicKey;
cert
.validity
.notBefore = tz().tz('UTC').toDate();
cert
.validity
.notAfter
.setFullYear(
cert
.validity
.notBefore
.getFullYear() + 1
);
cert.setSubject([{
name: 'commonName',
value: domain
}, {
name: 'organizationName',
value: name
}]);
cert.setIssuer([{
name: 'commonName',
value: domain
}, {
name: 'organizationName',
value: name
}]);
// Self-sign certificate.
cert.sign(
keys.privateKey,
forge
.md
.sha256
.create()
);
// Summon the callback with the certificate block.
callback({
privateKey: forge
.pki
.privateKeyToPem(
keys
.privateKey
),
publicKey: forge
.pki
.publicKeyToPem(
keys
.publicKey
),
certificate: forge
.pki
.certificateToPem(cert)
});
});
}
};
Generated by GNU Enscript 1.6.5.90.