Browse Source

Merge pull request #83 from Samourai-Wallet/feat_node_https

removed unused support of https by nodejs apps
umbrel
kenshin samourai 5 years ago
committed by GitHub
parent
commit
b557995565
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      accounts/index.js
  2. 39
      docker/my-dojo/node/keys.index.js
  3. 55
      keys/index-example.js
  4. 35
      lib/http-server/http-server.js
  5. 3
      pushtx/index.js

3
accounts/index.js

@ -53,8 +53,7 @@
// Initialize the http server // Initialize the http server
const port = keys.ports.account const port = keys.ports.account
const httpsOptions = keys.https.account const httpServer = new HttpServer(port)
const httpServer = new HttpServer(port, httpsOptions)
// Initialize the rest api endpoints // Initialize the rest api endpoints
const authRestApi = new AuthRestApi(httpServer) const authRestApi = new AuthRestApi(httpServer)

39
docker/my-dojo/node/keys.index.js

@ -81,45 +81,6 @@ module.exports = {
// Port used by the pushtx orchestrator for its notifications // Port used by the pushtx orchestrator for its notifications
orchestrator: 5557 orchestrator: 5557
}, },
/*
* HTTPS
* Activate only if node js is used as frontend web server
* (no nginx proxy server)
*/
https: {
// HTTPS for the API
account: {
// Activate https
active: false,
// Filepath of server private key
// (shoud be stored in keys/sslcert)
keypath: '',
// Passphrase of the private key
passphrase: '',
// Filepath of server certificate
// (shoud be stored in keys/sslcert)
certpath: '',
// Filepath of CA certificate
// (shoud be stored in keys/sslcert)
capath: ''
},
// HTTPS for pushtx
pushtx: {
// Activate https
active: false,
// Filepath of server private key
// (shoud be stored in keys/sslcert)
keypath: '',
// Passphrase of the private key
passphrase: '',
// Filepath of server certificate
// (shoud be stored in keys/sslcert)
certpath: '',
// Filepath of CA certificate
// (shoud be stored in keys/sslcert)
capath: ''
}
},
/* /*
* Authenticated access to the APIs (account & pushtx) * Authenticated access to the APIs (account & pushtx)
*/ */

55
keys/index-example.js

@ -78,45 +78,6 @@ module.exports = {
// Port used by the pushtx orchestrator for its notifications // Port used by the pushtx orchestrator for its notifications
orchestrator: 5557 orchestrator: 5557
}, },
/*
* HTTPS
* Activate only if node js is used as frontend web server
* (no nginx proxy server)
*/
https: {
// HTTPS for the API
account: {
// Activate https
active: false,
// Filepath of server private key
// (shoud be stored in keys/sslcert)
keypath: '',
// Passphrase of the private key
passphrase: '',
// Filepath of server certificate
// (shoud be stored in keys/sslcert)
certpath: '',
// Filepath of CA certificate
// (shoud be stored in keys/sslcert)
capath: ''
},
// HTTPS for pushtx
pushtx: {
// Activate https
active: false,
// Filepath of server private key
// (shoud be stored in keys/sslcert)
keypath: '',
// Passphrase of the private key
passphrase: '',
// Filepath of server certificate
// (shoud be stored in keys/sslcert)
certpath: '',
// Filepath of CA certificate
// (shoud be stored in keys/sslcert)
capath: ''
}
},
/* /*
* Authenticated access to the APIs (account & pushtx) * Authenticated access to the APIs (account & pushtx)
*/ */
@ -277,22 +238,6 @@ module.exports = {
notifpushtx: 15556, notifpushtx: 15556,
orchestrator: 15557 orchestrator: 15557
}, },
https: {
account: {
active: false,
keypath: '',
passphrase: '',
certpath: '',
capath: ''
},
pushtx: {
active: false,
keypath: '',
passphrase: '',
certpath: '',
capath: ''
}
},
auth: { auth: {
activeStrategy: null, activeStrategy: null,
mandatory: false, mandatory: false,

35
lib/http-server/http-server.js

@ -5,7 +5,6 @@
'use strict' 'use strict'
const fs = require('fs') const fs = require('fs')
const https = require('https')
const express = require('express') const express = require('express')
const helmet = require('helmet') const helmet = require('helmet')
const Logger = require('../logger') const Logger = require('../logger')
@ -19,15 +18,11 @@ class HttpServer {
/** /**
* Constructor * Constructor
* @param {int} port - port used by the http server * @param {int} port - port used by the http server
* @param {object} httpsOptions - https options
*/ */
constructor(port, httpsOptions) { constructor(port) {
// Initialize server port // Initialize server port
this.port = port this.port = port
// Store https options
this.httpsOptions = httpsOptions
// Listening server instance // Listening server instance
this.server = null this.server = null
@ -58,30 +53,10 @@ class HttpServer {
HttpServer.sendError(res, ret, 500) HttpServer.sendError(res, ret, 500)
}) })
if (this.httpsOptions == null || !this.httpsOptions.active) { // Start a http server
// Start a http server this.server = this.app.listen(this.port, () => {
this.server = this.app.listen(this.port, () => { Logger.info('HTTP server listening on port ' + this.port)
Logger.info('HTTP server listening on port ' + this.port) })
})
} else {
// Start a https server
const options = {
key: fs.readFileSync(this.httpsOptions.keypath),
cert: fs.readFileSync(this.httpsOptions.certpath),
requestCert: false,
rejectUnauthorized: false
}
if (this.httpsOptions.capath)
options.ca = fs.readFileSync(this.httpsOptions.capath)
if (this.httpsOptions.passphrase)
options.passphrase = this.httpsOptions.passphrase
this.server = https.createServer(options, this.app).listen(this.port, () => {
Logger.info('HTTPS server listening on port ' + this.port)
})
}
this.server.timeout = 600 * 1000 this.server.timeout = 600 * 1000
// @see https://github.com/nodejs/node/issues/13391 // @see https://github.com/nodejs/node/issues/13391

3
pushtx/index.js

@ -45,8 +45,7 @@
// Initialize the http server // Initialize the http server
const port = keys.ports.pushtx const port = keys.ports.pushtx
const httpsOptions = keys.https.pushtx const httpServer = new HttpServer(port)
const httpServer = new HttpServer(port, httpsOptions)
// Initialize the PushTx rest api // Initialize the PushTx rest api
const pushtxRestApi = new PushTxRestApi(httpServer) const pushtxRestApi = new PushTxRestApi(httpServer)

Loading…
Cancel
Save