node-http-server – Diff between revs 1 and 6

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 6
Line 1... Line 1...
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 /////////////////////////////////////////////////////////////////////////// 2 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 // 3 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
4 /////////////////////////////////////////////////////////////////////////// 4 ///////////////////////////////////////////////////////////////////////////
Line 5... Line 5...
5   5  
6 // Import packages. 6 // Import packages.
Line 11... Line 11...
11 const mime = require('mime'); 11 const mime = require('mime');
12 const url = require('url'); 12 const url = require('url');
13 const moment = require('moment'); 13 const moment = require('moment');
14 const winston = require('winston'); 14 const winston = require('winston');
15 const yargs = require('yargs'); 15 const yargs = require('yargs');
-   16 const forge = require('node-forge');
Line 16... Line 17...
16   17  
17 // Get command-line arguments. 18 // Get command-line arguments.
18 const argv = yargs 19 const argv = yargs
19 .version() 20 .version()
Line 34... Line 35...
34 rootPath = rootPath.split(separator).filter(Boolean); 35 rootPath = rootPath.split(separator).filter(Boolean);
35 return userPath.length >= rootPath.length && 36 return userPath.length >= rootPath.length &&
36 rootPath.every((e, i) => e === userPath[i]); 37 rootPath.every((e, i) => e === userPath[i]);
37 } 38 }
Line -... Line 39...
-   39  
-   40 function generateCertificates(name, domain) {
-   41 // Generate 1024-bit key-pair.
-   42 var keys = forge.pki.rsa.generateKeyPair(1024);
-   43 // Create self-signed certificate.
-   44 var cert = forge.pki.createCertificate();
-   45 cert.publicKey = keys.publicKey;
-   46 cert.validity.notBefore = new Date();
-   47 cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
-   48 cert.setSubject([
-   49 {
-   50 name: 'commonName',
-   51 value: domain
-   52 },
-   53 {
-   54 name: 'organizationName',
-   55 value: name
-   56 }
-   57 ]);
-   58 cert.setIssuer([
-   59 {
-   60 name: 'commonName',
-   61 value: name
-   62 },
-   63 {
-   64 name: 'organizationName',
-   65 value: name
-   66 }
-   67 ]);
-   68  
-   69 // Self-sign certificate.
-   70 cert.sign(keys.privateKey);
-   71  
-   72 // Return PEM-format keys and certificates.
-   73 return {
-   74 privateKey: forge.pki.privateKeyToPem(keys.privateKey),
-   75 publicKey: forge.pki.publicKeyToPem(keys.publicKey),
-   76 certificate: forge.pki.certificateToPem(cert)
-   77 };
-   78 }
38   79  
39 // Create various logging mechanisms. 80 // Create various logging mechanisms.
40 const log = new winston.Logger({ 81 const log = new winston.Logger({
41 transports: [ 82 transports: [
42 new winston.transports.File({ 83 new winston.transports.File({
Line 68... Line 109...
68   109  
69 var authentication = auth.digest({ 110 var authentication = auth.digest({
70 realm: "was", 111 realm: "was",
71 file: path.resolve(__dirname, config.password_file) 112 file: path.resolve(__dirname, config.password_file)
-   113 });
-   114
Line 72... Line 115...
72 }); 115 const certs = generateCertificates("was", 'localhost');
73   116  
74 // HTTPs server using digest authentication. 117 // HTTPs server using digest authentication.
75 https.createServer(authentication, { 118 https.createServer(authentication, {
76 key: fs.readFileSync(path.resolve(__dirname, config.key)), -  
77 cert: fs.readFileSync(path.resolve(__dirname, config.certificate)), 119 key: certs.privateKey,
78 ca: fs.readFileSync(path.resolve(__dirname, config.ca)), 120 cert: certs.certificate,
79 }, (request, response) => { 121 }, (request, response) => {
Line 80... Line 122...
80 const requestAddress = request.socket.address(); 122 const requestAddress = request.socket.address();