Comparing version 0.0.2 to 0.0.3
119
index.js
@@ -1,5 +0,4 @@ | ||
var forge = require('node-forge'); | ||
var nconf = require('nconf'); | ||
var fs = require('fs'); | ||
var uuid = require('node-uuid'); | ||
var KeyCred = require('./keycred'); | ||
var prompt = require('prompt'); | ||
@@ -17,26 +16,11 @@ nconf.argv(); | ||
*/ | ||
var generateKeyCred = function(privateKey, cert) { | ||
var printKeyCred = function(keycred) { | ||
// Convert the Certificate to DER format. | ||
var certDER = forge.asn1.toDer(forge.pki.certificateToAsn1(cert)); | ||
// Convert the keycred to JSON. | ||
keycred = keycred.toJSON(); | ||
// Convert the certificate to hexidecimal. | ||
var certHEX = certDER.toHex(); | ||
// Create a digest of the cert to get the fingerprint. | ||
var md = forge.md.sha1.create(); | ||
md.start(); | ||
md.update(certDER.getBytes()); | ||
var digest = md.digest(); | ||
// Get the key credentials. | ||
console.log(''); | ||
console.log('Key Credentials:'); | ||
console.log(JSON.stringify({ | ||
customKeyIdentifier: (new Buffer(digest.toHex(), 'hex')).toString('base64'), | ||
value: (new Buffer(certHEX, 'hex')).toString('base64'), | ||
keyId: uuid.v4(), | ||
usage: 'Verify', | ||
type: 'AsymmetricX509Cert' | ||
}, null, 4).green); | ||
console.log(JSON.stringify(keycred.keycred, null, 4).green); | ||
@@ -46,3 +30,3 @@ // Print out the private key. | ||
console.log('Private Key:'); | ||
console.log(forge.pki.privateKeyToPem(privateKey).green); | ||
console.log(keycred.privateKey.green); | ||
@@ -52,3 +36,3 @@ // Print out the certificate. | ||
console.log('Certificate:'); | ||
console.log(forge.pki.certificateToPem(cert).green); | ||
console.log(keycred.cert.green); | ||
@@ -58,3 +42,3 @@ // Print out the certificate fingerprint | ||
console.log('Certificate Fingerprint:'); | ||
console.log(digest.toHex().green); | ||
console.log(keycred.fingerprint.green); | ||
}; | ||
@@ -65,6 +49,6 @@ | ||
if (privateKey && cert) { | ||
generateKeyCred( | ||
forge.pki.privateKeyFromPem(fs.readFileSync(privateKey).toString()), | ||
forge.pki.certificateFromPem(fs.readFileSync(cert).toString(), true) | ||
); | ||
printKeyCred(new KeyCred.fromPem( | ||
fs.readFileSync(privateKey).toString(), | ||
fs.readFileSync(cert).toString() | ||
)); | ||
} | ||
@@ -107,70 +91,3 @@ else { | ||
}, function(err, certparams) { | ||
// Generate a key pair. | ||
console.log('Generating key pairs'); | ||
var keys = forge.pki.rsa.generateKeyPair(2048); | ||
console.log('Creating a certificate.'); | ||
var cert = forge.pki.createCertificate(); | ||
cert.publicKey = keys.publicKey; | ||
cert.serialNumber = '01'; | ||
cert.validity.notBefore = new Date(); | ||
cert.validity.notAfter = new Date(); | ||
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1); | ||
var attrs = [{ | ||
name: 'commonName', | ||
value: certparams.commonName | ||
}, { | ||
name: 'countryName', | ||
value: certparams.countryName | ||
}, { | ||
shortName: 'ST', | ||
value: certparams.province | ||
}, { | ||
name: 'localityName', | ||
value: certparams.localityName | ||
}, { | ||
name: 'organizationName', | ||
value: certparams.organizationName | ||
}, { | ||
shortName: 'OU', | ||
value: certparams.ou | ||
}]; | ||
cert.setSubject(attrs); | ||
cert.setIssuer(attrs); | ||
cert.setExtensions([{ | ||
name: 'basicConstraints', | ||
cA: true | ||
}, { | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, { | ||
name: 'extKeyUsage', | ||
serverAuth: true, | ||
clientAuth: true, | ||
codeSigning: true, | ||
emailProtection: true, | ||
timeStamping: true | ||
}, { | ||
name: 'nsCertType', | ||
client: true, | ||
server: true, | ||
email: true, | ||
objsign: true, | ||
sslCA: true, | ||
emailCA: true, | ||
objCA: true | ||
}, { | ||
name: 'subjectKeyIdentifier' | ||
}]); | ||
// self-sign certificate | ||
console.log('Signing the certificate.'); | ||
cert.sign(keys.privateKey); | ||
// Generate the key credentials. | ||
generateKeyCred(keys.privateKey, cert); | ||
printKeyCred(new KeyCred(certparams)); | ||
}); | ||
@@ -191,6 +108,8 @@ } | ||
}, function(err, fileparams) { | ||
generateKeyCred( | ||
forge.pki.privateKeyFromPem(fs.readFileSync(fileparams.privateKey).toString()), | ||
forge.pki.certificateFromPem(fs.readFileSync(fileparams.cert).toString(), true) | ||
); | ||
// Print the keycred from the provided PEM files. | ||
printKeyCred(new KeyCred.fromPem( | ||
fs.readFileSync(fileparams.privateKey).toString(), | ||
fs.readFileSync(fileparams.cert).toString() | ||
)); | ||
}); | ||
@@ -197,0 +116,0 @@ } |
{ | ||
"name": "keycred", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A Key Credential generator for Office 365 Applications.", | ||
"main": "index.js", | ||
"main": "keycred.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16396
7
229
1