Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Temporary solution until Argon2 support is added to Java lib
const rnBridge = require('rn-bridge'); // eslint-disable-line import/no-unresolved
const argon2 = require('argon2');
const kdbxweb = require('kdbxweb');
/**
* Bind kdbxweb and argon2
*/
kdbxweb.CryptoEngine.argon2 = (password, salt, memory, iterations, length, parallelism, type, version) => {
return argon2.hash(password, {
hashLength: length,
timeCost: iterations,
memoryCost: memory,
parallelism,
type,
version,
salt: Buffer.from(salt),
raw: true,
});
};
/**
* Encrypt seed to .kdbx database format
* @method createSeedVault
*
return bufferPromise.then(function (buf) {
var h = keepassHeader.readHeader(buf);
if (!h) throw new Error('Failed to read file header');
if (h.kdbx) { // KDBX - use kdbxweb library
kdbxweb.CryptoEngine.argon2 = argon2;
var kdbxCreds = jsonCredentialsToKdbx(masterKey);
return kdbxweb.Kdbx.load(buf, kdbxCreds).then(db => {
var psk = new Uint8Array(db.header.protectedStreamKey, 0, db.header.protectedStreamKey.length);
var entries = parseKdbxDb(db.groups);
majorVersion = db.header.versionMajor;
return processReferences(entries, majorVersion);
});
} else { // KDB - we don't support this anymore
throw "Unsupported Database Version";
}
}).then(function (entries) {
return {
return passwordFileStoreRegistry.getChosenDatabaseFile(settings).then(function(buf) {
var h = keepassHeader.readHeader(buf);
if (!h) throw new Error('Failed to read file header');
if (h.kdbx) { // KDBX - use kdbxweb library
kdbxweb.CryptoEngine.argon2 = argon2;
var kdbxCreds = jsonCredentialsToKdbx(masterKey);
return kdbxweb.Kdbx.load(buf, kdbxCreds).then(db => {
var psk = new Uint8Array(db.header.protectedStreamKey, 0, db.header.protectedStreamKey.length);
var entries = parseKdbxDb(db.groups);
majorVersion = db.header.versionMajor;
return processReferences(entries, majorVersion);
});
} else { // KDB - we don't support this anymore
throw "Unsupported Database Version";
}
}).then(function(entries) {
return {
.then(res => {
if (kdbxweb.ByteUtils.bytesToHex(res) !== exp) {
throw 'AES is not working properly';
}
if (kdbxweb.CryptoEngine.random(1).length !== 1) {
throw 'Random is not working';
}
});
})
return Promise.resolve().then(() => {
const aesCbc = kdbxweb.CryptoEngine.createAesCbc();
const key = '6b2796fa863a6552986c428528d053b76de7ba8e12f8c0e74edb5ed44da3f601';
const data = 'e567554429098a38d5f819115edffd39';
const iv = '4db46dff4add42cb813b98de98e627c4';
const exp = '46ab4c37d9ec594e5742971f76f7c1620bc29f2e0736b27832d6bcc5c1c39dc1';
return aesCbc
.importKey(kdbxweb.ByteUtils.hexToBytes(key))
.then(() => {
return aesCbc
.encrypt(
kdbxweb.ByteUtils.hexToBytes(data),
kdbxweb.ByteUtils.hexToBytes(iv)
)
.then(res => {
if (kdbxweb.ByteUtils.bytesToHex(res) !== exp) {
throw 'AES is not working properly';
}
init() {
kdbxweb.CryptoEngine.argon2 = (...args) => this.argon2(...args);
},
import argon2 from 'argon2';
import kdbxweb from 'kdbxweb';
import { byteToChar, charToByte } from 'libs/iota/converter';
/**
* Bind kdbxweb and argon2
*/
kdbxweb.CryptoEngine.argon2 = (password, salt, memory, iterations, length, parallelism, type, version) => {
return argon2.hash(password, {
hashLength: length,
timeCost: iterations,
memoryCost: memory,
parallelism,
type,
version,
salt: Buffer.from(salt),
raw: true,
});
};
/**
* Encrypt seed to KDBX database format
* @param {array} Seeds - Array of byte array seeds an their titles
* @param {string} Password - Plain text password for encryption