Skip to content

Commit 1afa9ea

Browse files
committed
Merge branch 'main' into feature/improving-public-key-fingerprint
# Conflicts: # lib/mcapi/utils/utils.js
2 parents fcad028 + 0f874cb commit 1afa9ea

File tree

7 files changed

+3307
-73
lines changed

7 files changed

+3307
-73
lines changed

dist/client-encryption-nodejs.min.js

Lines changed: 12 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,16 @@ module.exports.addEncryptedDataToBody = function(encryptedData, path, encryptedV
426426
return body;
427427
};
428428

429+
module.exports.readPublicCertificateContent = function (config) {
430+
if (!config.encryptionCertificate || config.encryptionCertificate.length <= 1) {
431+
throw new Error("Public certificate content is not valid");
432+
}
433+
return forge.pki.certificateFromPem(config.encryptionCertificate);
434+
}
429435

430-
431-
436+
module.exports.getPrivateKeyFromContent = function(config) {
437+
if (config.privateKey) {
438+
return forge.pki.privateKeyFromPem(config.privateKey);
439+
}
440+
return null;
441+
}

0 commit comments

Comments
 (0)