-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssl_cert.js
37 lines (29 loc) · 1.04 KB
/
ssl_cert.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
var crypto = require('crypto');
var tls = require('tls');
var fs = require('fs');
var path = require('path');
var empty = require('is-empty');
module.exports = function(dirname) {
if (empty(dirname)) {
throw new Error("Please set dirname to folder containing appropriate certificates");
}
require('ssl-root-cas/latest')
.inject()
.addFile(dirname + '/NovaVizijaCA_Root.crt');
var folder = process.env.NODE_ENV || 'development';
var exp = {};
exp.privateKey = fs.readFileSync(path.join(dirname, folder + '/privatekey.pem')).toString();
exp.certificate = fs.readFileSync(path.join(dirname, folder + '/certificate.pem')).toString();
if (typeof tls.createSecureContext === 'function') {
exp.credentials = tls.createSecureContext({
key: exp.privateKey,
cert: exp.certificate
});
} else {
exp.credentials = crypto.createCredentials({
key: exp.privateKey,
cert: exp.certificate
});
}
return exp;
}