node-forge
Advanced tools
Comparing version 0.1.11 to 0.1.12
118
js/pkcs12.js
@@ -268,7 +268,8 @@ /** | ||
* | ||
* @param safeContents The SafeContents structure to search in. | ||
* @param attrName The name of the attribute to compare against. | ||
* @param attrValue The attribute value to search for. | ||
* @param bagType Optional bag type to narrow search by. | ||
* @return Array of matching bags | ||
* @param safeContents the SafeContents structure to search in. | ||
* @param attrName the name of the attribute to compare against. | ||
* @param attrValue the attribute value to search for. | ||
* @param [bagType] bag type to narrow search by. | ||
* | ||
* @return an array of matching bags. | ||
*/ | ||
@@ -286,3 +287,3 @@ function _getBagsByAttribute(safeContents, attrName, attrValue, bagType) { | ||
if(bag.attributes[attrName] !== undefined && | ||
bag.attributes[attrName].indexOf(attrValue) >= 0) { | ||
bag.attributes[attrName].indexOf(attrValue) >= 0) { | ||
result.push(bag); | ||
@@ -331,23 +332,65 @@ } | ||
/** | ||
* Get bags with matching friendlyName attribute | ||
* Gets bags with matching attributes. | ||
* | ||
* @param friendlyName The friendly name to search for | ||
* @param bagType Optional bag type to narrow search by | ||
* @return Array of bags with matching friendlyName attribute | ||
* @param filter the attributes to filter by: | ||
* [localKeyId] the localKeyId to search for. | ||
* [localKeyIdHex] the localKeyId in hex to search for. | ||
* [friendlyName] the friendly name to search for. | ||
* [bagType] bag type to narrow each attribute search by. | ||
* | ||
* @return a map of attribute type to an array of matching bags. | ||
*/ | ||
getBags: function(filter) { | ||
var rval = {}; | ||
var localKeyId; | ||
if('localKeyId' in filter) { | ||
localKeyId = filter.localKeyId; | ||
} | ||
else if('localKeyIdHex' in filter) { | ||
localKeyId = forge.util.hexToBytes(filter.localKeyIdHex); | ||
} | ||
if(localKeyId !== undefined) { | ||
rval.localKeyId = _getBagsByAttribute( | ||
pfx.safeContents, 'localKeyId', | ||
localKeyId, filter.bagType); | ||
} | ||
if('friendlyName' in filter) { | ||
rval.friendlyName = _getBagsByAttribute( | ||
pfx.safeContents, 'friendlyName', | ||
filter.friendlyName, filter.bagType); | ||
} | ||
return rval; | ||
}, | ||
/** | ||
* DEPRECATED: use getBags() instead. | ||
* | ||
* Get bags with matching friendlyName attribute. | ||
* | ||
* @param friendlyName the friendly name to search for. | ||
* @param [bagType] bag type to narrow search by. | ||
* | ||
* @return an array of bags with matching friendlyName attribute. | ||
*/ | ||
getBagsByFriendlyName: function(friendlyName, bagType) { | ||
return _getBagsByAttribute(pfx.safeContents, 'friendlyName', | ||
friendlyName, bagType); | ||
return _getBagsByAttribute( | ||
pfx.safeContents, 'friendlyName', friendlyName, bagType); | ||
}, | ||
/** | ||
* Get bags with matching localKeyId attribute | ||
* DEPRECATED: use getBags() instead. | ||
* | ||
* @param localKeyId The localKeyId name to search for | ||
* @param bagType Optional bag type to narrow search by | ||
* @return Array of bags with matching localKeyId attribute | ||
* Get bags with matching localKeyId attribute. | ||
* | ||
* @param localKeyId the localKeyId to search for. | ||
* @param [bagType] bag type to narrow search by. | ||
* | ||
* @return an array of bags with matching localKeyId attribute. | ||
*/ | ||
getBagsByLocalKeyId: function(localKeyId, bagType) { | ||
return _getBagsByAttribute(pfx.safeContents, 'localKeyId', | ||
localKeyId, bagType); | ||
return _getBagsByAttribute( | ||
pfx.safeContents, 'localKeyId', localKeyId, bagType); | ||
} | ||
@@ -664,6 +707,7 @@ }; | ||
/** | ||
* Decode PKCS#12 SET OF PKCS12Attribute into JavaScript object | ||
* Decode PKCS#12 SET OF PKCS12Attribute into JavaScript object. | ||
* | ||
* @param attributes SET OF PKCS12Attribute (ASN.1 object) | ||
* @return the decoded attributes | ||
* @param attributes SET OF PKCS12Attribute (ASN.1 object). | ||
* | ||
* @return the decoded attributes. | ||
*/ | ||
@@ -674,3 +718,3 @@ function _decodeBagAttributes(attributes) { | ||
if(attributes !== undefined) { | ||
for(var i = 0; i < attributes.length; i ++) { | ||
for(var i = 0; i < attributes.length; ++i) { | ||
var capture = {}; | ||
@@ -690,5 +734,5 @@ var errors = []; | ||
} | ||
decodedAttrs[pki.oids[oid]] = []; | ||
for(var j = 0; j < capture.values.length; j ++) { | ||
for(var j = 0; j < capture.values.length; ++j) { | ||
decodedAttrs[pki.oids[oid]].push(capture.values[j].value); | ||
@@ -725,2 +769,3 @@ } | ||
* localKeyId the local key ID to use, in hex. | ||
* friendlyName the friendly name to use. | ||
* generateLocalKeyId true to generate a random local key ID, | ||
@@ -753,4 +798,2 @@ * false not to, defaults to true. | ||
else if(options.generateLocalKeyId) { | ||
// set localKeyId and friendlyName (if specified) | ||
// use SHA-1 of paired cert, if available | ||
@@ -774,4 +817,5 @@ if(cert) { | ||
var attrs = []; | ||
if(localKeyId !== null) { | ||
var attrs = [ | ||
attrs.push( | ||
// localKeyID | ||
@@ -787,4 +831,20 @@ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | ||
]) | ||
]) | ||
]; | ||
])); | ||
} | ||
if('friendlyName' in options) { | ||
attrs.push( | ||
// friendlyName | ||
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | ||
// attrId | ||
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, | ||
asn1.oidToDer(pki.oids['friendlyName']).getBytes()), | ||
// attrValues | ||
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [ | ||
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BMPSTRING, false, | ||
options.friendlyName) | ||
]) | ||
])); | ||
} | ||
if(attrs.length > 0) { | ||
bagAttrs = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, attrs); | ||
@@ -791,0 +851,0 @@ } |
{ | ||
"name": "node-forge", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilties.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/digitalbazaar/forge", |
@@ -767,2 +767,11 @@ # Forge | ||
// get bags by friendlyName | ||
var bags = pkcs12.getBags({friendlyName: 'test'}); | ||
// get bags by localKeyId | ||
var bags = pkcs12.getBags({localKeyId: buffer}); | ||
// get bags by localKeyId (input in hex) | ||
var bags = pkcs12.getBags({localKeyIdHex: '7b59377ff142d0be4565e9ac3d396c01401cd879'}); | ||
// generate p12, base64 encode | ||
@@ -769,0 +778,0 @@ var p12Asn1 = forge.pkcs12.toPkcs12Asn1( |
@@ -12,2 +12,3 @@ var forge = require('../js/forge'); | ||
var cert = forge.pki.createCertificate(); | ||
cert.publicKey = keys.publicKey; | ||
cert.serialNumber = '01'; | ||
@@ -55,3 +56,2 @@ cert.validity.notBefore = new Date(); | ||
}]); | ||
cert.publicKey = keys.publicKey; | ||
@@ -67,3 +67,3 @@ // self-sign certificate | ||
keys.privateKey, [cert], password, | ||
{generateLocalKeyId: true}); | ||
{generateLocalKeyId: true, friendlyName: 'test'}); | ||
var newPkcs12Der = forge.asn1.toDer(newPkcs12Asn1).getBytes(); | ||
@@ -70,0 +70,0 @@ |
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
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
1683468
32252
1187