Skip to content

Commit ad728a4

Browse files
authored
Merge pull request #40 from suhas14345/feature/postman_usable_library_updates
Added support to allow certificate content to be passed directly
2 parents 8263e71 + 0845a3e commit ad728a4

File tree

7 files changed

+6343
-72
lines changed

7 files changed

+6343
-72
lines changed

dist/mc_encrypt.js

Lines changed: 3046 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/mcapi/crypto/field-level-crypto.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ const c = require("../utils/constants");
1313
function FieldLevelCrypto(config) {
1414
isValidConfig.call(this, config);
1515

16+
//Load public/private keys from text
17+
if(config.useCertificateContent){
18+
this.encryptionCertificate = utils.readPublicCertificateContent(config);
19+
this.privateKey = utils.getPrivateKeyFromContent(config);
20+
}
1621
// Load public certificate (for encryption)
17-
this.encryptionCertificate = utils.readPublicCertificate(
18-
config.encryptionCertificate
19-
);
20-
21-
// Load private key (for decryption)
22-
this.privateKey = utils.getPrivateKey(config);
22+
else{
23+
this.encryptionCertificate = utils.readPublicCertificate(
24+
config.encryptionCertificate
25+
);
2326

27+
// Load private key (for decryption)
28+
this.privateKey = utils.getPrivateKey(config);
29+
}
2430
this.encoding = config.dataEncoding;
2531

2632
this.publicKeyFingerprint =

lib/mcapi/utils/utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,5 +415,16 @@ function hasEncryptionParam(encParams, bodyMap) {
415415
return encParams && encParams.length === 1 && bodyMap && bodyMap[0];
416416
}
417417

418+
module.exports.readPublicCertificateContent = function (config) {
419+
if (!config.encryptionCertificate || config.encryptionCertificate.length <= 1) {
420+
throw new Error("Public certificate content is not valid");
421+
}
422+
return forge.pki.certificateFromPem(config.encryptionCertificate);
423+
}
418424

419-
425+
module.exports.getPrivateKeyFromContent = function(config) {
426+
if (config.privateKey) {
427+
return forge.pki.privateKeyFromPem(config.privateKey);
428+
}
429+
return null;
430+
}

0 commit comments

Comments
 (0)