Kaynağa Gözat

clean test and refactor

pull/342/head
Guillaume Vincent 8 yıl önce
ebeveyn
işleme
1bee7bb80b
6 değiştirilmiş dosya ile 31 ekleme ve 61 silme
  1. +16
    -22
      dist/lesspass.js
  2. +11
    -2
      index.js
  3. +0
    -1
      package.json
  4. +4
    -19
      src/v2.js
  5. +0
    -1
      tests/karma.config.js
  6. +0
    -16
      tests/v2/debug.py

+ 16
- 22
dist/lesspass.js Dosyayı Görüntüle

@@ -29,7 +29,16 @@ module.exports = {
};

var defaultPasswordProfile = {
version: 1
version: 2,
lowercase: true,
digits: true,
uppercase: true,
symbols: true,
keylen: 32,
digest: 'sha256',
length: 16,
index: 1,
iterations: 100000
};

function generatePassword(site, login, masterPassword, passwordProfile) {
@@ -51,7 +60,7 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
});
}
if (_passwordProfile.version === 2) {
return v2.generatePassword(site, login, masterPassword, passwordProfile);
return v2.generatePassword(site, login, masterPassword, _passwordProfile);
}
}
},{"./src/pbkdf2":48,"./src/v1":49,"./src/v2":50,"object-assign":18}],2:[function(require,module,exports){
@@ -8468,7 +8477,6 @@ function createFingerprint(str) {
},{"./pbkdf2":48,"buffer":6,"create-hmac":12,"pinkie-promise":21}],50:[function(require,module,exports){
var pbkdf2 = require('./pbkdf2');
var bigInt = require("big-integer");
var objectAssign = require('object-assign');

module.exports = {
generatePassword: generatePassword,
@@ -8482,24 +8490,11 @@ module.exports = {
};

function generatePassword(site, login, masterPassword, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
return calcEntropy(site, login, masterPassword, _passwordProfile).then(function (entropy) {
return renderPassword(entropy, _passwordProfile);
return calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
return renderPassword(entropy, passwordProfile);
});
}

var defaultPasswordProfile = {
lowercase: true,
uppercase: true,
digits: true,
symbols: true,
length: 16,
index: 1,
iterations: 100000,
keylen: 32,
digest: 'sha256'
};

function calcEntropy(site, login, masterPassword, passwordProfile) {
var salt = site + login + passwordProfile.index.toString(16);
return pbkdf2(masterPassword, salt, passwordProfile.iterations, passwordProfile.keylen, passwordProfile.digest);
@@ -8558,13 +8553,12 @@ function getConfiguredRules(passwordProfile) {
}

function renderPassword(entropy, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
var rules = getConfiguredRules(_passwordProfile);
var rules = getConfiguredRules(passwordProfile);
var setOfCharacters = getSetOfCharacters(rules);
var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, _passwordProfile.length - rules.length);
var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, passwordProfile.length - rules.length);
var charactersToAdd = getOneCharPerRule(password.entropy, rules);
return insertStringPseudoRandomly(password.value, charactersToAdd.entropy, charactersToAdd.value);
}

},{"./pbkdf2":48,"big-integer":3,"object-assign":18}]},{},[1])(1)
},{"./pbkdf2":48,"big-integer":3}]},{},[1])(1)
});

+ 11
- 2
index.js Dosyayı Görüntüle

@@ -28,7 +28,16 @@ module.exports = {
};

var defaultPasswordProfile = {
version: 1
version: 2,
lowercase: true,
digits: true,
uppercase: true,
symbols: true,
keylen: 32,
digest: 'sha256',
length: 16,
index: 1,
iterations: 100000
};

function generatePassword(site, login, masterPassword, passwordProfile) {
@@ -50,6 +59,6 @@ function generatePassword(site, login, masterPassword, passwordProfile) {
});
}
if (_passwordProfile.version === 2) {
return v2.generatePassword(site, login, masterPassword, passwordProfile);
return v2.generatePassword(site, login, masterPassword, _passwordProfile);
}
}

+ 0
- 1
package.json Dosyayı Görüntüle

@@ -32,7 +32,6 @@
"unibabel": "^2.1.3"
},
"devDependencies": {
"bluebird": "^3.4.6",
"browserify": "^13.1.1",
"chai": "^3.5.0",
"karma": "^1.3.0",


+ 4
- 19
src/v2.js Dosyayı Görüntüle

@@ -1,6 +1,5 @@
var pbkdf2 = require('./pbkdf2');
var bigInt = require("big-integer");
var objectAssign = require('object-assign');

module.exports = {
generatePassword: generatePassword,
@@ -14,24 +13,11 @@ module.exports = {
};

function generatePassword(site, login, masterPassword, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
return calcEntropy(site, login, masterPassword, _passwordProfile).then(function (entropy) {
return renderPassword(entropy, _passwordProfile);
return calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
return renderPassword(entropy, passwordProfile);
});
}

var defaultPasswordProfile = {
lowercase: true,
uppercase: true,
digits: true,
symbols: true,
length: 16,
index: 1,
iterations: 100000,
keylen: 32,
digest: 'sha256'
};

function calcEntropy(site, login, masterPassword, passwordProfile) {
var salt = site + login + passwordProfile.index.toString(16);
return pbkdf2(masterPassword, salt, passwordProfile.iterations, passwordProfile.keylen, passwordProfile.digest);
@@ -90,10 +76,9 @@ function getConfiguredRules(passwordProfile) {
}

function renderPassword(entropy, passwordProfile) {
var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
var rules = getConfiguredRules(_passwordProfile);
var rules = getConfiguredRules(passwordProfile);
var setOfCharacters = getSetOfCharacters(rules);
var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, _passwordProfile.length - rules.length);
var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, passwordProfile.length - rules.length);
var charactersToAdd = getOneCharPerRule(password.entropy, rules);
return insertStringPseudoRandomly(password.value, charactersToAdd.entropy, charactersToAdd.value);
}

+ 0
- 1
tests/karma.config.js Dosyayı Görüntüle

@@ -3,7 +3,6 @@ module.exports = function (config) {
basePath: '..',
frameworks: ['mocha', 'chai'],
files: [
'node_modules/bluebird/js/browser/bluebird.core.min.js',
'node_modules/big-integer/BigInteger.min.js',
'dist/lesspass.js',
'tests/**/*.js'


+ 0
- 16
tests/v2/debug.py Dosyayı Görüntüle

@@ -1,16 +0,0 @@
import math


def renderPassword(mdp, quotient, alphabet):
if len(mdp) > 14:
return mdp
quotient, remainder = divmod(quotient, len(alphabet))
mdp += alphabet[remainder]
return renderPassword(mdp, quotient, alphabet)


alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
print(renderPassword('', int('dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e', 16), alphabet))

max_length = math.floor(math.log(int('dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e', 16))/math.log(26 + 26 + 10 + 32)) - 4
print('max number of char for password with 32 bytes entropy: %d' % max_length)

Yükleniyor…
İptal
Kaydet