$
This commit is contained in:
39
node_modules/selfsigned/.jshintrc
generated
vendored
Normal file
39
node_modules/selfsigned/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"camelcase": false,
|
||||
"curly": false,
|
||||
|
||||
"node": true,
|
||||
"esnext": true,
|
||||
"bitwise": true,
|
||||
"eqeqeq": true,
|
||||
"immed": true,
|
||||
"indent": 2,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"regexp": true,
|
||||
"undef": true,
|
||||
"strict": false,
|
||||
"smarttabs": true,
|
||||
"expr": true,
|
||||
|
||||
"evil": true,
|
||||
"browser": true,
|
||||
"regexdash": true,
|
||||
"wsh": true,
|
||||
"trailing": true,
|
||||
"sub": true,
|
||||
"unused": true,
|
||||
"laxcomma": true,
|
||||
|
||||
"globals": {
|
||||
"after": false,
|
||||
"before": false,
|
||||
"afterEach": false,
|
||||
"beforeEach": false,
|
||||
"describe": false,
|
||||
"it": false,
|
||||
"DOMParser": true,
|
||||
"XMLSerializer": true
|
||||
}
|
||||
}
|
22
node_modules/selfsigned/LICENSE
generated
vendored
Normal file
22
node_modules/selfsigned/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013 José F. Romaniello
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
83
node_modules/selfsigned/README.md
generated
vendored
Normal file
83
node_modules/selfsigned/README.md
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
205
node_modules/selfsigned/index.js
generated
vendored
Normal file
205
node_modules/selfsigned/index.js
generated
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
var forge = require('node-forge');
|
||||
|
||||
// a hexString is considered negative if it's most significant bit is 1
|
||||
// because serial numbers use ones' complement notation
|
||||
// this RFC in section 4.1.2.2 requires serial numbers to be positive
|
||||
// http://www.ietf.org/rfc/rfc5280.txt
|
||||
function toPositiveHex(hexString){
|
||||
var mostSiginficativeHexAsInt = parseInt(hexString[0], 16);
|
||||
if (mostSiginficativeHexAsInt < 8){
|
||||
return hexString;
|
||||
}
|
||||
|
||||
mostSiginficativeHexAsInt -= 8;
|
||||
return mostSiginficativeHexAsInt.toString() + hexString.substring(1);
|
||||
}
|
||||
|
||||
function getAlgorithm(key) {
|
||||
switch (key) {
|
||||
case 'sha256':
|
||||
return forge.md.sha256.create();
|
||||
default:
|
||||
return forge.md.sha1.create();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {forge.pki.CertificateField[]} attrs Attributes used for subject and issuer.
|
||||
* @param {object} options
|
||||
* @param {number} [options.days=365] the number of days before expiration
|
||||
* @param {number} [options.keySize=1024] the size for the private key in bits
|
||||
* @param {object} [options.extensions] additional extensions for the certificate
|
||||
* @param {string} [options.algorithm="sha1"] The signature algorithm sha256 or sha1
|
||||
* @param {boolean} [options.pkcs7=false] include PKCS#7 as part of the output
|
||||
* @param {boolean} [options.clientCertificate=false] generate client cert signed by the original key
|
||||
* @param {string} [options.clientCertificateCN="John Doe jdoe123"] client certificate's common name
|
||||
* @param {function} [done] Optional callback, if not provided the generation is synchronous
|
||||
* @returns
|
||||
*/
|
||||
exports.generate = function generate(attrs, options, done) {
|
||||
if (typeof attrs === 'function') {
|
||||
done = attrs;
|
||||
attrs = undefined;
|
||||
} else if (typeof options === 'function') {
|
||||
done = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
var generatePem = function (keyPair) {
|
||||
var cert = forge.pki.createCertificate();
|
||||
|
||||
cert.serialNumber = toPositiveHex(forge.util.bytesToHex(forge.random.getBytesSync(9))); // the serial number can be decimal or hex (if preceded by 0x)
|
||||
|
||||
cert.validity.notBefore = new Date();
|
||||
cert.validity.notAfter = new Date();
|
||||
cert.validity.notAfter.setDate(cert.validity.notBefore.getDate() + (options.days || 365));
|
||||
|
||||
attrs = attrs || [{
|
||||
name: 'commonName',
|
||||
value: 'example.org'
|
||||
}, {
|
||||
name: 'countryName',
|
||||
value: 'US'
|
||||
}, {
|
||||
shortName: 'ST',
|
||||
value: 'Virginia'
|
||||
}, {
|
||||
name: 'localityName',
|
||||
value: 'Blacksburg'
|
||||
}, {
|
||||
name: 'organizationName',
|
||||
value: 'Test'
|
||||
}, {
|
||||
shortName: 'OU',
|
||||
value: 'Test'
|
||||
}];
|
||||
|
||||
cert.setSubject(attrs);
|
||||
cert.setIssuer(attrs);
|
||||
|
||||
cert.publicKey = keyPair.publicKey;
|
||||
|
||||
cert.setExtensions(options.extensions || [{
|
||||
name: 'basicConstraints',
|
||||
cA: true
|
||||
}, {
|
||||
name: 'keyUsage',
|
||||
keyCertSign: true,
|
||||
digitalSignature: true,
|
||||
nonRepudiation: true,
|
||||
keyEncipherment: true,
|
||||
dataEncipherment: true
|
||||
}, {
|
||||
name: 'subjectAltName',
|
||||
altNames: [{
|
||||
type: 6, // URI
|
||||
value: 'http://example.org/webid#me'
|
||||
}]
|
||||
}]);
|
||||
|
||||
cert.sign(keyPair.privateKey, getAlgorithm(options && options.algorithm));
|
||||
|
||||
const fingerprint = forge.md.sha1
|
||||
.create()
|
||||
.update(forge.asn1.toDer(forge.pki.certificateToAsn1(cert)).getBytes())
|
||||
.digest()
|
||||
.toHex()
|
||||
.match(/.{2}/g)
|
||||
.join(':');
|
||||
|
||||
var pem = {
|
||||
private: forge.pki.privateKeyToPem(keyPair.privateKey),
|
||||
public: forge.pki.publicKeyToPem(keyPair.publicKey),
|
||||
cert: forge.pki.certificateToPem(cert),
|
||||
fingerprint: fingerprint,
|
||||
};
|
||||
|
||||
if (options && options.pkcs7) {
|
||||
var p7 = forge.pkcs7.createSignedData();
|
||||
p7.addCertificate(cert);
|
||||
pem.pkcs7 = forge.pkcs7.messageToPem(p7);
|
||||
}
|
||||
|
||||
if (options && options.clientCertificate) {
|
||||
var clientkeys = forge.pki.rsa.generateKeyPair(1024);
|
||||
var clientcert = forge.pki.createCertificate();
|
||||
clientcert.serialNumber = toPositiveHex(forge.util.bytesToHex(forge.random.getBytesSync(9)));
|
||||
clientcert.validity.notBefore = new Date();
|
||||
clientcert.validity.notAfter = new Date();
|
||||
clientcert.validity.notAfter.setFullYear(clientcert.validity.notBefore.getFullYear() + 1);
|
||||
|
||||
var clientAttrs = JSON.parse(JSON.stringify(attrs));
|
||||
|
||||
for(var i = 0; i < clientAttrs.length; i++) {
|
||||
if(clientAttrs[i].name === 'commonName') {
|
||||
if( options.clientCertificateCN )
|
||||
clientAttrs[i] = { name: 'commonName', value: options.clientCertificateCN };
|
||||
else
|
||||
clientAttrs[i] = { name: 'commonName', value: 'John Doe jdoe123' };
|
||||
}
|
||||
}
|
||||
|
||||
clientcert.setSubject(clientAttrs);
|
||||
|
||||
// Set the issuer to the parent key
|
||||
clientcert.setIssuer(attrs);
|
||||
|
||||
clientcert.publicKey = clientkeys.publicKey;
|
||||
|
||||
// Sign client cert with root cert
|
||||
clientcert.sign(keyPair.privateKey);
|
||||
|
||||
pem.clientprivate = forge.pki.privateKeyToPem(clientkeys.privateKey);
|
||||
pem.clientpublic = forge.pki.publicKeyToPem(clientkeys.publicKey);
|
||||
pem.clientcert = forge.pki.certificateToPem(clientcert);
|
||||
|
||||
if (options.pkcs7) {
|
||||
var clientp7 = forge.pkcs7.createSignedData();
|
||||
clientp7.addCertificate(clientcert);
|
||||
pem.clientpkcs7 = forge.pkcs7.messageToPem(clientp7);
|
||||
}
|
||||
}
|
||||
|
||||
var caStore = forge.pki.createCaStore();
|
||||
caStore.addCertificate(cert);
|
||||
|
||||
try {
|
||||
forge.pki.verifyCertificateChain(caStore, [cert],
|
||||
function (vfd, depth, chain) {
|
||||
if (vfd !== true) {
|
||||
throw new Error('Certificate could not be verified.');
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
catch(ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
|
||||
return pem;
|
||||
};
|
||||
|
||||
var keySize = options.keySize || 1024;
|
||||
|
||||
if (done) { // async scenario
|
||||
return forge.pki.rsa.generateKeyPair({ bits: keySize }, function (err, keyPair) {
|
||||
if (err) { return done(err); }
|
||||
|
||||
try {
|
||||
return done(null, generatePem(keyPair));
|
||||
} catch (ex) {
|
||||
return done(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var keyPair = options.keyPair ? {
|
||||
privateKey: forge.pki.privateKeyFromPem(options.keyPair.privateKey),
|
||||
publicKey: forge.pki.publicKeyFromPem(options.keyPair.publicKey)
|
||||
} : forge.pki.rsa.generateKeyPair(keySize);
|
||||
|
||||
return generatePem(keyPair);
|
||||
};
|
43
node_modules/selfsigned/package.json
generated
vendored
Normal file
43
node_modules/selfsigned/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "selfsigned",
|
||||
"version": "2.0.1",
|
||||
"description": "Generate self signed certificates private and public keys",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha -t 5000"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jfromaniello/selfsigned.git"
|
||||
},
|
||||
"keywords": [
|
||||
"openssl",
|
||||
"self",
|
||||
"signed",
|
||||
"certificates"
|
||||
],
|
||||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Paolo Fragomeni",
|
||||
"email": "paolo@async.ly",
|
||||
"url": "http://async.ly"
|
||||
},
|
||||
{
|
||||
"name": "Charles Bushong",
|
||||
"email": "bushong1@gmail.com",
|
||||
"url": "http://github.com/bushong1"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-forge": "^1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.3.4",
|
||||
"mocha": "^9.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
}
|
156
node_modules/selfsigned/test/tests.js
generated
vendored
Normal file
156
node_modules/selfsigned/test/tests.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
var { assert } = require('chai');
|
||||
var forge = require('node-forge');
|
||||
var fs = require('fs');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
describe('generate', function () {
|
||||
|
||||
var generate = require('../index').generate;
|
||||
|
||||
it('should work without attrs/options', function (done) {
|
||||
var pems = generate();
|
||||
assert.ok(!!pems.private, 'has a private key');
|
||||
assert.ok(!!pems.fingerprint, 'has fingerprint');
|
||||
assert.ok(!!pems.public, 'has a public key');
|
||||
assert.ok(!!pems.cert, 'has a certificate');
|
||||
assert.ok(!pems.pkcs7, 'should not include a pkcs7 by default');
|
||||
assert.ok(!pems.clientcert, 'should not include a client cert by default');
|
||||
assert.ok(!pems.clientprivate, 'should not include a client private key by default');
|
||||
assert.ok(!pems.clientpublic, 'should not include a client public key by default');
|
||||
|
||||
var caStore = forge.pki.createCaStore();
|
||||
caStore.addCertificate(pems.cert);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should generate client cert', function (done) {
|
||||
var pems = generate(null, {clientCertificate: true});
|
||||
|
||||
assert.ok(!!pems.clientcert, 'should include a client cert when requested');
|
||||
assert.ok(!!pems.clientprivate, 'should include a client private key when requested');
|
||||
assert.ok(!!pems.clientpublic, 'should include a client public key when requested');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should include pkcs7', function (done) {
|
||||
var pems = generate([{ name: 'commonName', value: 'contoso.com' }], {pkcs7: true});
|
||||
|
||||
assert.ok(!!pems.pkcs7, 'has a pkcs7');
|
||||
|
||||
try {
|
||||
fs.unlinkSync('/tmp/tmp.pkcs7');
|
||||
} catch (er) {}
|
||||
|
||||
fs.writeFileSync('/tmp/tmp.pkcs7', pems.pkcs7);
|
||||
exec('openssl pkcs7 -print_certs -in /tmp/tmp.pkcs7', function (err, stdout, stderr) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
const errorMessage = stderr.toString();
|
||||
if (errorMessage.length) {
|
||||
return done(new Error(errorMessage));
|
||||
}
|
||||
|
||||
const expected = stdout.toString();
|
||||
let [ subjectLine,issuerLine, ...cert ] = expected.split(/\r?\n/).filter(c => c);
|
||||
cert = cert.filter(c => c);
|
||||
assert.match(subjectLine, /subject=\/?CN\s?=\s?contoso.com/i);
|
||||
assert.match(issuerLine, /issuer=\/?CN\s?=\s?contoso.com/i);
|
||||
assert.strictEqual(
|
||||
pems.cert,
|
||||
cert.join('\r\n') + '\r\n'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support sha1 algorithm', function (done) {
|
||||
var pems_sha1 = generate(null, { algorithm: 'sha1' });
|
||||
assert.ok(forge.pki.certificateFromPem(pems_sha1.cert).siginfo.algorithmOid === forge.pki.oids['sha1WithRSAEncryption'], 'can generate sha1 certs');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should support sha256 algorithm', function (done) {
|
||||
var pems_sha256 = generate(null, { algorithm: 'sha256' });
|
||||
assert.ok(forge.pki.certificateFromPem(pems_sha256.cert).siginfo.algorithmOid === forge.pki.oids['sha256WithRSAEncryption'], 'can generate sha256 certs');
|
||||
done();
|
||||
});
|
||||
|
||||
describe('with callback', function () {
|
||||
it('should work without attrs/options', function (done) {
|
||||
generate(function (err, pems) {
|
||||
if (err) done(err);
|
||||
assert.ok(!!pems.private, 'has a private key');
|
||||
assert.ok(!!pems.public, 'has a public key');
|
||||
assert.ok(!!pems.cert, 'has a certificate');
|
||||
assert.ok(!pems.pkcs7, 'should not include a pkcs7 by default');
|
||||
assert.ok(!pems.clientcert, 'should not include a client cert by default');
|
||||
assert.ok(!pems.clientprivate, 'should not include a client private key by default');
|
||||
assert.ok(!pems.clientpublic, 'should not include a client public key by default');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate client cert', function (done) {
|
||||
generate(null, {clientCertificate: true}, function (err, pems) {
|
||||
if (err) done(err);
|
||||
assert.ok(!!pems.clientcert, 'should include a client cert when requested');
|
||||
assert.ok(!!pems.clientprivate, 'should include a client private key when requested');
|
||||
assert.ok(!!pems.clientpublic, 'should include a client public key when requested');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should include pkcs7', function (done) {
|
||||
generate([{ name: 'commonName', value: 'contoso.com' }], {pkcs7: true}, function (err, pems) {
|
||||
if (err) done(err);
|
||||
assert.ok(!!pems.pkcs7, 'has a pkcs7');
|
||||
|
||||
try {
|
||||
fs.unlinkSync('/tmp/tmp.pkcs7');
|
||||
} catch (er) {}
|
||||
|
||||
fs.writeFileSync('/tmp/tmp.pkcs7', pems.pkcs7);
|
||||
exec('openssl pkcs7 -print_certs -in /tmp/tmp.pkcs7', function (err, stdout, stderr) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
const errorMessage = stderr.toString();
|
||||
if (errorMessage.length) {
|
||||
return done(new Error(errorMessage));
|
||||
}
|
||||
|
||||
const expected = stdout.toString();
|
||||
let [ subjectLine,issuerLine, ...cert ] = expected.split(/\r?\n/).filter(c => c);
|
||||
assert.match(subjectLine, /subject=\/?CN\s?=\s?contoso.com/i);
|
||||
assert.match(issuerLine, /issuer=\/?CN\s?=\s?contoso.com/i);
|
||||
assert.strictEqual(
|
||||
pems.cert,
|
||||
cert.join('\r\n') + '\r\n'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support sha1 algorithm', function (done) {
|
||||
generate(null, { algorithm: 'sha1' }, function (err, pems_sha1) {
|
||||
if (err) done(err);
|
||||
assert.ok(forge.pki.certificateFromPem(pems_sha1.cert).siginfo.algorithmOid === forge.pki.oids['sha1WithRSAEncryption'], 'can generate sha1 certs');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support sha256 algorithm', function (done) {
|
||||
generate(null, { algorithm: 'sha256' }, function (err, pems_sha256) {
|
||||
if (err) done(err);
|
||||
assert.ok(forge.pki.certificateFromPem(pems_sha256.cert).siginfo.algorithmOid === forge.pki.oids['sha256WithRSAEncryption'], 'can generate sha256 certs');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user