Przeglądaj źródła

keep API as v1 for now

pull/342/head
Guillaume Vincent 8 lat temu
rodzic
commit
24c339e806
8 zmienionych plików z 63 dodań i 63 usunięć
  1. +7
    -7
      dist/lesspass.js
  2. +3
    -3
      index.js
  3. +4
    -4
      src/v2.js
  4. +24
    -24
      tests/v1/api.tests.js
  5. +8
    -8
      tests/v2/api.tests.js
  6. +6
    -6
      tests/v2/entropy.tests.js
  7. +6
    -6
      tests/v2/renderPassword.tests.js
  8. +5
    -5
      tests/v2/setOfCharacters.tests.js

+ 7
- 7
dist/lesspass.js Wyświetl plik

@@ -31,7 +31,7 @@ module.exports = {
var defaultPasswordProfile = {
version: 2,
lowercase: true,
digits: true,
numbers: true,
uppercase: true,
symbols: true,
keylen: 32,
@@ -45,11 +45,11 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
if (_passwordProfile.version === 1) {
var options = {
counter: _passwordProfile.index,
counter: _passwordProfile.counter,
length: _passwordProfile.length,
lowercase: _passwordProfile.lowercase,
uppercase: _passwordProfile.uppercase,
numbers: _passwordProfile.digits,
numbers: _passwordProfile.numbers,
symbols: _passwordProfile.symbols
};
return v1.encryptLogin(login, masterPassword)
@@ -8496,20 +8496,20 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
}

function calcEntropy(site, login, masterPassword, passwordProfile) {
var salt = site + login + passwordProfile.index.toString(16);
var salt = site + login + passwordProfile.counter.toString(16);
return pbkdf2(masterPassword, salt, passwordProfile.iterations, passwordProfile.keylen, passwordProfile.digest);
}

var characterSubsets = {
lowercase: 'abcdefghijklmnopqrstuvwxyz',
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
digits: '0123456789',
numbers: '0123456789',
symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
};

function getSetOfCharacters(rules) {
if (typeof rules === 'undefined') {
return characterSubsets.lowercase + characterSubsets.uppercase + characterSubsets.digits + characterSubsets.symbols;
return characterSubsets.lowercase + characterSubsets.uppercase + characterSubsets.numbers + characterSubsets.symbols;
}
var setOfChars = '';
rules.forEach(function (rule) {
@@ -8547,7 +8547,7 @@ function getOneCharPerRule(entropy, rules) {
}

function getConfiguredRules(passwordProfile) {
return ['lowercase', 'uppercase', 'digits', 'symbols'].filter(function (rule) {
return ['lowercase', 'uppercase', 'numbers', 'symbols'].filter(function (rule) {
return passwordProfile[rule];
});
}


+ 3
- 3
index.js Wyświetl plik

@@ -30,7 +30,7 @@ module.exports = {
var defaultPasswordProfile = {
version: 2,
lowercase: true,
digits: true,
numbers: true,
uppercase: true,
symbols: true,
keylen: 32,
@@ -44,11 +44,11 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
if (_passwordProfile.version === 1) {
var options = {
counter: _passwordProfile.index,
counter: _passwordProfile.counter,
length: _passwordProfile.length,
lowercase: _passwordProfile.lowercase,
uppercase: _passwordProfile.uppercase,
numbers: _passwordProfile.digits,
numbers: _passwordProfile.numbers,
symbols: _passwordProfile.symbols
};
return v1.encryptLogin(login, masterPassword)


+ 4
- 4
src/v2.js Wyświetl plik

@@ -19,20 +19,20 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
}

function calcEntropy(site, login, masterPassword, passwordProfile) {
var salt = site + login + passwordProfile.index.toString(16);
var salt = site + login + passwordProfile.counter.toString(16);
return pbkdf2(masterPassword, salt, passwordProfile.iterations, passwordProfile.keylen, passwordProfile.digest);
}

var characterSubsets = {
lowercase: 'abcdefghijklmnopqrstuvwxyz',
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
digits: '0123456789',
numbers: '0123456789',
symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
};

function getSetOfCharacters(rules) {
if (typeof rules === 'undefined') {
return characterSubsets.lowercase + characterSubsets.uppercase + characterSubsets.digits + characterSubsets.symbols;
return characterSubsets.lowercase + characterSubsets.uppercase + characterSubsets.numbers + characterSubsets.symbols;
}
var setOfChars = '';
rules.forEach(function (rule) {
@@ -70,7 +70,7 @@ function getOneCharPerRule(entropy, rules) {
}

function getConfiguredRules(passwordProfile) {
return ['lowercase', 'uppercase', 'digits', 'symbols'].filter(function (rule) {
return ['lowercase', 'uppercase', 'numbers', 'symbols'].filter(function (rule) {
return passwordProfile[rule];
});
}


+ 24
- 24
tests/v1/api.tests.js Wyświetl plik

@@ -372,10 +372,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -389,10 +389,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -407,10 +407,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 14,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -425,10 +425,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: false,
digits: false,
numbers: false,
symbols: false,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -443,10 +443,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: false,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -461,10 +461,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: false,
uppercase: false,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -479,10 +479,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: false,
uppercase: false,
digits: false,
numbers: false,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -497,10 +497,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: false,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -515,10 +515,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: false,
numbers: false,
symbols: false,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -533,10 +533,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 2,
counter: 2,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -551,10 +551,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -569,10 +569,10 @@ describe('LessPass v1', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 12,
index: 1,
counter: 1,
version: 1,
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {


+ 8
- 8
tests/v2/api.tests.js Wyświetl plik

@@ -10,10 +10,10 @@ describe('LessPass v2', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
length: 16,
index: 1,
counter: 1,
version: 2
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -28,10 +28,10 @@ describe('LessPass v2', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: false,
length: 14,
index: 2,
counter: 2,
version: 2
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -46,10 +46,10 @@ describe('LessPass v2', function () {
var passwordProfile = {
lowercase: false,
uppercase: false,
digits: true,
numbers: true,
symbols: false,
length: 6,
index: 3,
counter: 3,
version: 2
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
@@ -64,10 +64,10 @@ describe('LessPass v2', function () {
var passwordProfile = {
lowercase: true,
uppercase: true,
digits: false,
numbers: false,
symbols: true,
length: 14,
index: 1,
counter: 1,
version: 2
};
return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {


+ 6
- 6
tests/v2/entropy.tests.js Wyświetl plik

@@ -11,7 +11,7 @@ describe('LessPass v2', function () {
iterations: 100000,
keylen: 32,
digest: 'sha256',
index: 1
counter: 1
};
return LessPass._calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
assert.equal('dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e', entropy);
@@ -25,26 +25,26 @@ describe('LessPass v2', function () {
iterations: 8192,
keylen: 16,
digest: 'sha512',
index: 1
counter: 1
};
return LessPass._calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
assert.equal('fff211c16a4e776b3574c6a5c91fd252', entropy);
});
});
it('calc entropy different if index different 1', function () {
it('calc entropy different if counter different 1', function () {
var site = 'example.org';
var login = 'contact@example.org';
var masterPassword = 'password';
var passwordProfile1 = {iterations: 1, keylen: 16, digest: 'sha256', index: 1};
var passwordProfile1 = {iterations: 1, keylen: 16, digest: 'sha256', counter: 1};
return LessPass._calcEntropy(site, login, masterPassword, passwordProfile1).then(function (entropy) {
assert.equal('d3ec1e988dd0b3640c7491cd2c2a88b5', entropy)
});
});
it('calc entropy different if index different 2', function () {
it('calc entropy different if counter different 2', function () {
var site = 'example.org';
var login = 'contact@example.org';
var masterPassword = 'password';
var passwordProfile2 = {iterations: 1, keylen: 16, digest: 'sha256', index: 2};
var passwordProfile2 = {iterations: 1, keylen: 16, digest: 'sha256', counter: 2};
return LessPass._calcEntropy(site, login, masterPassword, passwordProfile2).then(function (entropy) {
assert.equal('ddfb1136260f930c21f6d72f6eddbd40', entropy)
});


+ 6
- 6
tests/v2/renderPassword.tests.js Wyświetl plik

@@ -5,7 +5,7 @@ describe('LessPass v2', function () {
length: 16,
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true
};
it('render password use remainder of long division beetween entropy and set of chars length as an index', function () {
@@ -26,7 +26,7 @@ describe('LessPass v2', function () {
length: 20,
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true
};
assert.equal(20, LessPass._renderPassword(entropy, passwordProfile).length);
@@ -41,14 +41,14 @@ describe('LessPass v2', function () {
length: 6,
lowercase: true,
uppercase: true,
digits: true,
numbers: true,
symbols: true,
};
var generatedPassword = LessPass._renderPassword(entropy, passwordProfile);
var passwordLength = generatedPassword.length;
var lowercaseOk = false;
var uppercaseOk = false;
var digitsOk = false;
var numbersOk = false;
var symbolsOk = false;
while (passwordLength--) {
if ('abcdefghijklmnopqrstuvwxyz'.indexOf(generatedPassword[passwordLength]) !== -1) {
@@ -58,13 +58,13 @@ describe('LessPass v2', function () {
uppercaseOk = true;
}
if ('0123456789'.indexOf(generatedPassword[passwordLength]) !== -1) {
digitsOk = true;
numbersOk = true;
}
if ('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.indexOf(generatedPassword[passwordLength]) !== -1) {
symbolsOk = true;
}
}
assert.equal(6, generatedPassword.length);
assert(lowercaseOk && uppercaseOk && digitsOk && symbolsOk, 'there is no at least one char in every characters set');
assert(lowercaseOk && uppercaseOk && numbersOk && symbolsOk, 'there is no at least one char in every characters set');
});
});

+ 5
- 5
tests/v2/setOfCharacters.tests.js Wyświetl plik

@@ -11,7 +11,7 @@ describe('LessPass v2', function () {
assert.equal(26 * 2 + 10 + 32, setOfCharacters.length);
});
it('get default set of characters concat rules in order', function () {
var setOfCharacters = LessPass._getSetOfCharacters(['lowercase', 'uppercase', 'digits']);
var setOfCharacters = LessPass._getSetOfCharacters(['lowercase', 'uppercase', 'numbers']);
assert.equal('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', setOfCharacters);
assert.equal(26 * 2 + 10, setOfCharacters.length);
});
@@ -25,8 +25,8 @@ describe('LessPass v2', function () {
assert.equal('ABCDEFGHIJKLMNOPQRSTUVWXYZ', setOfCharacters);
assert.equal(26, setOfCharacters.length);
});
it('get set of characters only digits', function () {
var setOfCharacters = LessPass._getSetOfCharacters(['digits']);
it('get set of characters only numbers', function () {
var setOfCharacters = LessPass._getSetOfCharacters(['numbers']);
assert.equal('0123456789', setOfCharacters);
assert.equal(10, setOfCharacters.length);
});
@@ -48,11 +48,11 @@ describe('LessPass v2', function () {
assert.deepEqual(['uppercase'], LessPass._getConfiguredRules({uppercase: true}));
assert.deepEqual(['lowercase', 'uppercase'], LessPass._getConfiguredRules({uppercase: true, lowercase: true}));
assert.deepEqual(['lowercase'], LessPass._getConfiguredRules({lowercase: true, symbols: false}));
assert.deepEqual(['lowercase', 'uppercase', 'digits', 'symbols'], LessPass._getConfiguredRules({
assert.deepEqual(['lowercase', 'uppercase', 'numbers', 'symbols'], LessPass._getConfiguredRules({
lowercase: true,
uppercase: true,
symbols: true,
digits: true
numbers: true
}));
});
});


Ładowanie…
Anuluj
Zapisz