Node module to enable HTTPS/SSL in a loopback application with simple configurations. The module in addition enables trusted peer authentication.
npm install loopback-sslNode module to enable HTTPS/SSL in a [loopback] application with simple configurations. The module also enables trusted peer authentication.
       
bashinstall loopback-cli
npm install -g loopback-clicreate project directory
mkdir
cd create loopback application
lb
? What's the name of your application?
? Which version of LoopBack would you like to use? 3.x (current)
? What kind of application do you have in mind? notes
`Install [loopback-ssl]:
`js
npm install loopback-ssl --save
`Setup Configuration:
Add the following lines of configuration in 'config.json' in location "\/server/config.json"
`js
"httpMode": false,
"certConfig": {
"path": "/certificate/path/",
"key": "local.pem",
"cert": "local.crt.pem",
"ca": [],
"requestCert": false,
"rejectUnauthorized": false
}
`Configure server.js
Edit the server.js located at "\/server/server.js". Replace the code in server.js with the code below (assuming no prior customizations to the file)$3
`js
var loopback = require('loopback');
var boot = require('loopback-boot');
var loopbackSSL = require('loopback-ssl');var app = module.exports = loopback();
boot(app, __dirname, function(err) {
if (err) throw err;
});
return loopbackSSL.startServer(app);
`
Configuration options
Option 1: HTTP (default loopback configuration)
The configuration entry "httpMode": true will enable http (disable https). In this mode the "certConfig": {..} configuration is not required and can be omitted.
`js
"httpMode": true
`Option 2: HTTPS: Loading certificates from files
The configuration entry "httpMode": false will enable https.
`js
"httpMode": false,
"certConfig": {
"path": "/certificate/path/",
"key": "serverkey.pem",
"cert": "server-certificate.pem",
"ca": [],
"requestCert": false,
"rejectUnauthorized": false
}
`
- "path" - folder location where the certificates files will be installed
- "key" - server key
- "cert" - server certificateOption 3: HTTPS: Loading certificates from files & Mutual SSL authentication
Will only work with pre-generated certificate files
`js
"httpMode": false,
"certConfig": {
"path": "/certificate/path/",
"key": "serverkey.pem",
"cert": "server-certificate.pem",
"ca": [
"client-certificate-to-validate.pem"
],
"requestCert": true,
"rejectUnauthorized": true
}
`
- The ca[] configuration contains the list of client certificates which the server will authenticate
- "requestCert": true enables mutual SSL authentication
- "rejectUnauthorized": true enables the authenticity and validity check of client keys
- For any reason, if the client certificate is a self signed certificate, "rejectUnauthorized": can be set to false`.- Want to contribute? Great! Please check this guide.
- Fork it ( https://github.com/yantrashala/loopback-ssl/fork )
- Create your feature branch (git checkout -b new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin new-feature)
- Create new Pull Request
MIT.
[loopback]: http://loopback.io
[loopback-ssl]: https://www.npmjs.com/package/loopback-ssl
[trusted_peer]: https://github.com/coolaj86/nodejs-ssl-trusted-peer-example
[self_signed]: https://github.com/coolaj86/nodejs-self-signed-certificate-example