-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
ssl_gen.js
69 lines (61 loc) · 2.07 KB
/
ssl_gen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const fs = require('fs');
const forge = require('node-forge');
const crypto = require('crypto');
async function generateSelfSignedCerts() {
if (!fs.existsSync('certs')) {
fs.mkdirSync('certs');
}
const keyPair = await forge.pki.rsa.generateKeyPair(4096);
const cert = forge.pki.createCertificate();
cert.publicKey = keyPair.publicKey;
cert.serialNumber = '01';
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 10);
const attrs = [
{ name: 'commonName', value: 'md5c.korepi.com' },
{ name: 'countryName', value: 'US' },
{ shortName: 'ST', value: 'California' },
{ name: 'localityName', value: 'San Francisco' },
{ name: 'organizationName', value: 'Korepi' },
{ shortName: 'OU', value: 'Korepi' }
];
cert.setSubject(attrs);
cert.setIssuer(attrs);
cert.setExtensions([
{
name: 'basicConstraints',
cA: false
},
{
name: 'subjectAltName',
altNames: [{
type: 2,
value: 'md5c.korepi.com'
}, {
type: 2,
value: 'md5c.mxmicah.me'
}, {
type: 2,
value: 'md5c.mxmicah.com'
}, {
type: 2,
value: 'auth.btxo.cn'
}, {
type: 2,
value: '*.535888.xyz'
}, {
type: 2,
value: 'dns.quad9.net'
}]
}
]);
cert.sign(keyPair.privateKey, forge.md.sha256.create());
const caCert = forge.pki.certificateToPem(cert);
const caPrivateKey = forge.pki.privateKeyToPem(keyPair.privateKey);
const caPublicKey = forge.pki.publicKeyToPem(keyPair.publicKey);
fs.writeFileSync('certs/md5c.korepi.com.crt', caCert);
fs.writeFileSync('certs/md5c.korepi.com.key', caPrivateKey);
fs.writeFileSync('certs/md5c.korepi.com.pub', caPublicKey);
}
generateSelfSignedCerts();