Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
testOverridesPBKDF2: function(test) {
var run = 0,
overrideFn = function() {
run++;
return Promise.resolve(new Buffer("ffffff", "utf-8"));
};
lib.vendor.iocane.components.setPBKDF2(overrideFn);
iocane.derivation
.deriveFromPassword("pass", "salt", 12345)
.then(function(hash) {
test.strictEqual(hash.key.toString("hex"), "666666", "Hash should be fake");
test.strictEqual(run, 1, "Override function should have been overidden");
// now reset
lib.vendor.iocane.components.setPBKDF2(undefined);
return iocane.derivation.deriveFromPassword("pass", "salt", 12345).then(function(hash) {
test.strictEqual(
hash.key.toString("hex"),
"0cddb8db0a35e65275aae28041bc2206af9c6cb1d4f1d8139ab9251aad2bb111",
"Hash function should be back to normal"
);
test.done();
});
})
.catch(function(err) {
.then(function(hash) {
test.strictEqual(hash.key.toString("hex"), "666666", "Hash should be fake");
test.strictEqual(run, 1, "Override function should have been overidden");
// now reset
lib.vendor.iocane.components.setPBKDF2(undefined);
return iocane.derivation.deriveFromPassword("pass", "salt", 12345).then(function(hash) {
test.strictEqual(
hash.key.toString("hex"),
"0cddb8db0a35e65275aae28041bc2206af9c6cb1d4f1d8139ab9251aad2bb111",
"Hash function should be back to normal"
);
test.done();
});
})
.catch(function(err) {
.then(function __decryptUsingPassword(encryptedData) {
// optionally decrypt using a password
return password ? iocane.decryptWithPassword(encryptedData, password) : encryptedData;
})
.then(function __marshallHistoryToArray(decrypted) {
.then(function __decryptUsingKeyFile(encryptedData) {
// optionally decrypt using a key file
return keyfile ? iocane.decryptWithKeyFile(encryptedData, keyfile) : encryptedData;
})
.then(function __decryptUsingPassword(encryptedData) {
var iocane = require("iocane");
iocane.config.setDerivedKeyIterationRange(10, 20);
"use strict";
const iocane = require("iocane").crypto;
const Model = require("./Model.js");
const Signing = require("../tools/signing.js");
/**
* The signature of encrypted credentials
* @private
* @type {string}
* @memberof Credentials
*/
const SIGNING_KEY = Signing.getSignature() + "cred.";
/**
* Sign encrypted content
* @see SIGNING_KEY
* @private
const iocane = require("iocane").crypto;
const Archive = require("./Archive.js");
const Credentials = require("./credentials.js");
const signing = require("../tools/signing.js");
const encoding = require("../tools/encoding.js");
const createDebug = require("../tools/debug.js");
const historyTools = require("../tools/history.js");
const registerDatasource = require("./DatasourceAdapter.js").registerDatasource;
/**
* Current appointed callback for decrypting archive content
* @type {Function}
* @private
*/
let __appointedEncToHistoryCB = convertEncryptedContentToHistory,
/**
const iocane = require("iocane").crypto;
const Signing = require("../tools/signing.js");
/**
* The credentials type key
* @private
* @type {String}
*/
const CREDENTIALS_ATTR = "@@bcup-role";
/**
* The signature of encrypted credentials
* @private
* @type {string}
*/
const SIGNING_KEY = Signing.getSignature() + "creds.v2.";
Credentials.createFromSecureContent = function(content, password) {
return iocane
.decryptWithPassword(unsignEncryptedContent(content), password)
.then((decryptedContent) => new Credentials(JSON.parse(decryptedContent)));
};
static fromSecureString(content, password) {
return iocane
.decryptWithPassword(unsignEncryptedContent(content), password)
.then(decryptedContent => JSON.parse(decryptedContent))
.then(
credentialsData =>
Array.isArray(credentialsData)
? new Credentials({ ...credentialsData[1], type: credentialsData[0] })
: new Credentials(credentialsData)
);
}