mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Changed implementation of __parsePEM; Now it does not return anymore an object but the value;
Moved __parsePEM outside of Pass class as parsePEM function;
This commit is contained in:
40
index.js
40
index.js
@@ -583,8 +583,9 @@ class Pass {
|
|||||||
|
|
||||||
Object.assign(this.props, this._filterOptions(options.overrides));
|
Object.assign(this.props, this._filterOptions(options.overrides));
|
||||||
|
|
||||||
let certPaths = Object.keys(options.certificates)
|
let optCertsNames = Object.keys(options.certificates);
|
||||||
.map((val) => {
|
|
||||||
|
let certPaths = optCertsNames.map((val) => {
|
||||||
const cert = options.certificates[val];
|
const cert = options.certificates[val];
|
||||||
const filePath = !(cert instanceof Object) ? cert : cert["keyFile"];
|
const filePath = !(cert instanceof Object) ? cert : cert["keyFile"];
|
||||||
const resolvedPath = path.resolve(filePath);
|
const resolvedPath = path.resolve(filePath);
|
||||||
@@ -593,41 +594,38 @@ class Pass {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(certPaths).then(contents => {
|
return Promise.all(certPaths).then(contents => {
|
||||||
contents.forEach(file => {
|
contents.forEach((file, index) => {
|
||||||
let pem = this.__parsePEM(file, options.certificates.signerKey.passphrase);
|
let certName = optCertsNames[index];
|
||||||
|
let pem = parsePEM(file, options.certificates[certName].passphrase);
|
||||||
|
|
||||||
if (!pem) {
|
if (!pem) {
|
||||||
return reject(errors.INVALID_CERTS)
|
return reject(errors.INVALID_CERTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Certificates[pem.key] = pem.value;
|
this.Certificates[certName] = pem;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* Parses the PEM-formatted passed text (certificates)
|
* Parses the PEM-formatted passed text (certificates)
|
||||||
*
|
*
|
||||||
* @method __parsePEM
|
* @function parsePEM
|
||||||
* @params {String} element - Text content of .pem files
|
* @params {String} element - Text content of .pem files
|
||||||
* @params {String} passphrase - passphrase for the key
|
* @params {String=} passphrase - passphrase for the key
|
||||||
* @returns {Object} - Object containing name of the certificate and its parsed content
|
* @returns {Object} The parsed certificate or key in node forge format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
__parsePEM(element, passphrase) {
|
function parsePEM(element, passphrase) {
|
||||||
if (element.includes("PRIVATE KEY") && !!passphrase) {
|
if (element.includes("PRIVATE KEY") && passphrase) {
|
||||||
return {
|
return forge.pki.decryptRsaPrivateKey(element, String(passphrase));
|
||||||
key: "signerKey",
|
|
||||||
value: forge.pki.decryptRsaPrivateKey(element, String(passphrase))
|
|
||||||
};
|
|
||||||
} else if (element.includes("CERTIFICATE")) {
|
} else if (element.includes("CERTIFICATE")) {
|
||||||
// PEM-exported certificates with keys are in PKCS#12 format, hence they are composed of bags.
|
// PEM-exported certificates with keys are in PKCS#12 format, hence they are composed of bags.
|
||||||
return {
|
return forge.pki.certificateFromPem(element);
|
||||||
key: element.includes("Bag Attributes") ? "signerCert" : "wwdr",
|
|
||||||
value: forge.pki.certificateFromPem(element)
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user