node-http-server – Blame information for rev 10

Subversion Repositories:
Rev:
Rev Author Line No. Line
8 office 1 #!/usr/bin/env node
2  
9 office 3 /*************************************************************************/
4 /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
5 /*************************************************************************/
6  
8 office 7 const forge = require('node-forge');
8 const moment = require('moment');
9  
10 module.exports = {
11 // Generate certificates on the fly using incremental serials.
10 office 12 generate: (name, domain, keySize, callback) => {
8 office 13 process.nextTick(() => {
14 // Generate 1024-bit key-pair.
15 const keys = forge
16 .pki
17 .rsa
18 .generateKeyPair(keySize);
19 // Create self-signed certificate.
20 const cert = forge
21 .pki
22 .createCertificate();
23 cert.serialNumber = moment().format('x');
24 cert.publicKey = keys.publicKey;
25 cert
26 .validity
27 .notBefore = moment().toDate();
28 cert
29 .validity
30 .notAfter
31 .setFullYear(
32 cert
33 .validity
34 .notBefore
35 .getFullYear() + 1
36 );
37 cert.setSubject([{
38 name: 'commonName',
39 value: domain
40 }, {
41 name: 'organizationName',
42 value: name
43 }]);
44 cert.setIssuer([{
45 name: 'commonName',
46 value: domain
47 }, {
48 name: 'organizationName',
49 value: name
50 }]);
51  
52 // Self-sign certificate.
53 cert.sign(
54 keys.privateKey,
55 forge
56 .md
57 .sha256
58 .create()
59 );
60  
61 // Summon the callback with the certificate block.
62 callback({
63 privateKey: forge
64 .pki
65 .privateKeyToPem(
66 keys
67 .privateKey
68 ),
69 publicKey: forge
70 .pki
71 .publicKeyToPem(
72 keys
73 .publicKey
74 ),
75 certificate: forge
76 .pki
77 .certificateToPem(cert)
78 });
79 });
80 }
81 };