Переглянути джерело

update encryptLogin API

allow user to customize iterations and key length for encryptLogin method.
encryptLogin use pbkdf2 with a default 8192 iterations and 32 key length.

make pbkdf2 rounds a per-site password profile option
lesspass/lesspass#38
pull/342/head
Guillaume Vincent 8 роки тому
джерело
коміт
70bebd5e5b
2 змінених файлів з 28 додано та 3 видалено
  1. +1
    -3
      index.js
  2. +27
    -0
      tests/api.tests.js

+ 1
- 3
index.js Переглянути файл

@@ -13,13 +13,11 @@ module.exports = {
_createHmac
};

function _encryptLogin(login, masterPassword) {
function _encryptLogin(login, masterPassword, {iterations = 8192, keylen = 32}={}) {
return new Promise((resolve, reject) => {
if (!login || !masterPassword) {
reject('login and master password parameters could not be empty');
}
const iterations = 8192;
const keylen = 32;
crypto.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', (error, key) => {
if (error) {
reject('error in pbkdf2');


+ 27
- 0
tests/api.tests.js Переглянути файл

@@ -9,12 +9,37 @@ describe('LessPass', function () {
});
});

it('should allow to customize number of iterations', function (done) {
LessPass.encryptLogin('test@example.org', 'password', {iterations: 4096}).then(function (encryptedLogin) {
assert.equal('0a91208545e3aa4935d3a22984ca097a7669259a04d261ac16361bdc1a2e960f', encryptedLogin);
done();
});
});

it('should allow to customize key length', function (done) {
LessPass.encryptLogin('test@example.org', 'password', {keylen: 16}).then(function (encryptedLogin) {
assert.equal('d8af5f918db6b65b1db3d3984e5a400e', encryptedLogin);
done();
});
});

it('should allow to customize iterations and key length', function (done) {
LessPass.encryptLogin('test@example.org', 'password', {
iterations: 4096,
keylen: 16
}).then(function (encryptedLogin) {
assert.equal('0a91208545e3aa4935d3a22984ca097a', encryptedLogin);
done();
});
});

it('should allow utf8 parameter', function (done) {
LessPass.encryptLogin('test@example.org', '♥ LessPass ♥').then(function (encryptedLogin) {
assert.equal('997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651', encryptedLogin);
done();
});
});

it('auto generated encrypt login tests', function () {
var promises = [];
var passwords = [
@@ -105,6 +130,8 @@ describe('LessPass', function () {
assert.equal('azYS7,olOL2]', generatedPassword);
})
});


it('auto generated render password tests', function () {
var promises = [];
var passwords = [


Завантаження…
Відмінити
Зберегти