@@ -3,18 +3,66 @@ name: test | |||
on: [push, pull_request] | |||
jobs: | |||
test-packages: | |||
test-lesspass-crypto: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/setup-node@v1 | |||
with: | |||
node-version: "12" | |||
- name: test packages | |||
run: | | |||
- run: | | |||
cd packages/lesspass-crypto | |||
yarn install | |||
yarn test | |||
test-lesspass-entropy: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/setup-node@v1 | |||
with: | |||
node-version: "12" | |||
- run: | | |||
cd packages/lesspass-entropy | |||
yarn install | |||
yarn test | |||
test-lesspass-fingerprint: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/setup-node@v1 | |||
with: | |||
node-version: "12" | |||
- run: | | |||
cd packages/lesspass-fingerprint | |||
yarn install | |||
yarn test | |||
test-lesspass-render-password: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/setup-node@v1 | |||
with: | |||
node-version: "12" | |||
- run: | | |||
cd packages/lesspass-render-password | |||
yarn install | |||
yarn test | |||
test-lesspass-site: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/setup-node@v1 | |||
with: | |||
node-version: "12" | |||
- run: | | |||
cd packages/lesspass-site | |||
yarn install | |||
yarn build | |||
test-mobile: | |||
runs-on: ubuntu-18.04 | |||
steps: | |||
@@ -17,20 +17,20 @@ function arrayBufferToHex(arrayBuffer) { | |||
return str; | |||
} | |||
function getAlgorithm(algorithm){ | |||
function getAlgorithm(algorithm) { | |||
const algorithms = { | |||
sha1: "SHA-1", | |||
"sha-1": "SHA-1", | |||
sha256: "SHA-256", | |||
"sha-256": "SHA-256", | |||
sha512: "SHA-512", | |||
"sha-512": "SHA-512" | |||
"sha-512": "SHA-512", | |||
}; | |||
return algorithms[algorithm.toLowerCase()] | |||
return algorithms[algorithm.toLowerCase()]; | |||
} | |||
module.exports = { | |||
stringToArrayBuffer, | |||
arrayBufferToHex, | |||
getAlgorithm | |||
getAlgorithm, | |||
}; |
@@ -1,7 +1,7 @@ | |||
const { | |||
stringToArrayBuffer, | |||
arrayBufferToHex, | |||
getAlgorithm | |||
getAlgorithm, | |||
} = require("./index"); | |||
test("stringToArrayBuffer", () => { | |||
@@ -20,11 +20,11 @@ | |||
"lesspass-crypto": "9.1.9" | |||
}, | |||
"devDependencies": { | |||
"karma": "^4.4.1", | |||
"browserify": "^17.0.0", | |||
"karma": "^6.1.2", | |||
"karma-browserify": "^8.0.0", | |||
"karma-chrome-launcher": "^3.1.0", | |||
"karma-mocha": "^1.3.0", | |||
"karma-webpack": "^4.0.2", | |||
"mocha": "^8.2.1", | |||
"webpack": "^4.44.2" | |||
"karma-mocha": "^2.0.1", | |||
"mocha": "^8.3.1" | |||
} | |||
} |
@@ -22,17 +22,17 @@ function isSupported() { | |||
digits: true, | |||
symbols: true, | |||
length: 16, | |||
counter: 1 | |||
counter: 1, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 1, | |||
keylen: 32, | |||
digest: "sha256" | |||
} | |||
digest: "sha256", | |||
}, | |||
}, | |||
"tHis is a g00d! password" | |||
).then(entropy => { | |||
).then((entropy) => { | |||
if ( | |||
entropy === | |||
"e99e20abab609cc4564ef137acb540de20d9b92dcc5cda58f78ba431444ef2da" | |||
@@ -48,5 +48,5 @@ function isSupported() { | |||
module.exports = { | |||
isSupported, | |||
calcEntropy | |||
calcEntropy, | |||
}; |
@@ -1,35 +1,35 @@ | |||
const { | |||
stringToArrayBuffer, | |||
arrayBufferToHex, | |||
getAlgorithm | |||
getAlgorithm, | |||
} = require("lesspass-crypto"); | |||
module.exports = function pbkdf2(password, salt, iterations, keylen, digest) { | |||
return window.crypto.subtle | |||
.importKey("raw", stringToArrayBuffer(password), "PBKDF2", false, [ | |||
"deriveKey" | |||
"deriveKey", | |||
]) | |||
.then(key => { | |||
.then((key) => { | |||
const algo = { | |||
name: "PBKDF2", | |||
salt: stringToArrayBuffer(salt), | |||
iterations, | |||
hash: getAlgorithm(digest) | |||
hash: getAlgorithm(digest), | |||
}; | |||
return window.crypto.subtle.deriveKey( | |||
algo, | |||
key, | |||
{ | |||
name: "AES-CTR", | |||
length: keylen * 8 | |||
length: keylen * 8, | |||
}, | |||
true, | |||
["encrypt", "decrypt"] | |||
); | |||
}) | |||
.then(derivedKey => | |||
.then((derivedKey) => | |||
window.crypto.subtle | |||
.exportKey("raw", derivedKey) | |||
.then(keyArray => arrayBufferToHex(keyArray)) | |||
.then((keyArray) => arrayBufferToHex(keyArray)) | |||
); | |||
}; |
@@ -19,5 +19,5 @@ function arrayBufferToHex(arrayBuffer) { | |||
module.exports = { | |||
stringToArrayBuffer, | |||
arrayBufferToHex | |||
arrayBufferToHex, | |||
}; |
@@ -5,10 +5,10 @@ describe("entropy", () => { | |||
it("calc entropy without crypto use default options and crypto", () => { | |||
const profile = { | |||
site: "example.org", | |||
login: "contact@example.org" | |||
login: "contact@example.org", | |||
}; | |||
const masterPassword = "password"; | |||
return calcEntropy(profile, masterPassword).then(entropy => { | |||
return calcEntropy(profile, masterPassword).then((entropy) => { | |||
assert.equal( | |||
"dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e", | |||
entropy | |||
@@ -20,17 +20,17 @@ describe("entropy", () => { | |||
site: "example.org", | |||
login: "contact@example.org", | |||
options: { | |||
counter: 1 | |||
counter: 1, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 100000, | |||
keylen: 32, | |||
digest: "sha256" | |||
} | |||
digest: "sha256", | |||
}, | |||
}; | |||
const masterPassword = "password"; | |||
return calcEntropy(profile, masterPassword).then(entropy => { | |||
return calcEntropy(profile, masterPassword).then((entropy) => { | |||
assert.equal( | |||
"dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e", | |||
entropy | |||
@@ -42,17 +42,17 @@ describe("entropy", () => { | |||
site: "example.org", | |||
login: "❤", | |||
options: { | |||
counter: 1 | |||
counter: 1, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 100000, | |||
keylen: 32, | |||
digest: "sha256" | |||
} | |||
digest: "sha256", | |||
}, | |||
}; | |||
const masterPassword = "I ❤ LessPass"; | |||
return calcEntropy(profile, masterPassword).then(entropy => { | |||
return calcEntropy(profile, masterPassword).then((entropy) => { | |||
assert.equal( | |||
"4e66cab40690c01af55efd595f5963cc953d7e10273c01827881ebf8990c627f", | |||
entropy | |||
@@ -64,17 +64,17 @@ describe("entropy", () => { | |||
site: "example.org", | |||
login: "contact@example.org", | |||
options: { | |||
counter: 1 | |||
counter: 1, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 8192, | |||
keylen: 16, | |||
digest: "sha512" | |||
} | |||
digest: "sha512", | |||
}, | |||
}; | |||
const masterPassword = "password"; | |||
return calcEntropy(profile, masterPassword).then(entropy => { | |||
return calcEntropy(profile, masterPassword).then((entropy) => { | |||
assert.equal("fff211c16a4e776b3574c6a5c91fd252", entropy); | |||
}); | |||
}); | |||
@@ -83,33 +83,33 @@ describe("entropy", () => { | |||
site: "example.org", | |||
login: "contact@example.org", | |||
options: { | |||
counter: 1 | |||
counter: 1, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 100000, | |||
keylen: 32, | |||
digest: "sha256" | |||
} | |||
digest: "sha256", | |||
}, | |||
}; | |||
const profile2 = { | |||
site: "example.org", | |||
login: "contact@example.org", | |||
options: { | |||
counter: 2 | |||
counter: 2, | |||
}, | |||
crypto: { | |||
method: "pbkdf2", | |||
iterations: 100000, | |||
keylen: 32, | |||
digest: "sha256" | |||
} | |||
digest: "sha256", | |||
}, | |||
}; | |||
const promises = [ | |||
calcEntropy(profile, "password"), | |||
calcEntropy(profile2, "password") | |||
calcEntropy(profile2, "password"), | |||
]; | |||
Promise.all(promises).then(values => { | |||
Promise.all(promises).then((values) => { | |||
assert.notEqual(values[0], values[1]); | |||
}); | |||
}); | |||
@@ -117,7 +117,7 @@ describe("entropy", () => { | |||
describe("isSupported", () => { | |||
it("isSupported", () => | |||
isSupported().then(supported => { | |||
isSupported().then((supported) => { | |||
assert(supported); | |||
})); | |||
}); |
@@ -1,15 +1,12 @@ | |||
module.exports = (config) => { | |||
config.set({ | |||
basePath: "..", | |||
frameworks: ["mocha"], | |||
frameworks: ["mocha", "browserify"], | |||
plugins: ["karma-mocha", "karma-browserify", "karma-chrome-launcher"], | |||
files: ["src/index.js", "test/**/*.js"], | |||
preprocessors: { | |||
"src/index.js": ["webpack"], | |||
"test/**/*.js": ["webpack"], | |||
}, | |||
webpack: {}, | |||
webpackMiddleware: { | |||
stats: "errors-only", | |||
"src/index.js": ["browserify"], | |||
"test/**/*.js": ["browserify"], | |||
}, | |||
browsers: ["ChromeHeadless"], | |||
singleRun: true, | |||
@@ -2,192 +2,139 @@ const assert = require("assert"); | |||
const pbkdf2 = require("../src/pbkdf2"); | |||
describe("pbkdf2", () => { | |||
it("secret, salt, 2 iterations, 32 keylen, sha256 hash", () => pbkdf2("secret", "salt", 2, 32, "sha256").then((key) => { | |||
it("secret, salt, 2 iterations, 32 keylen, sha256 hash", () => | |||
pbkdf2("secret", "salt", 2, 32, "sha256").then((key) => { | |||
assert.equal( | |||
"f92f45f9df4c2aeabae1ed3c16f7b64660c1f8e377fa9b4699b23c2c3a29f569", | |||
key | |||
); | |||
})); | |||
it("use pbkdf2 with 8192 iterations and sha256", () => pbkdf2( | |||
"password", | |||
"test@example.org", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
it("use pbkdf2 with 8192 iterations and sha256", () => | |||
pbkdf2("password", "test@example.org", 8192, 32, "sha256").then((key) => { | |||
assert.equal( | |||
"d8af5f918db6b65b1db3d3984e5a400e39e1dbb19462220e4431de283809f472", | |||
key | |||
); | |||
})); | |||
it("customize number of iterations", () => pbkdf2( | |||
"password", | |||
"test@example.org", | |||
4096, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
it("customize number of iterations", () => | |||
pbkdf2("password", "test@example.org", 4096, 32, "sha256").then((key) => { | |||
assert.equal( | |||
"0a91208545e3aa4935d3a22984ca097a7669259a04d261ac16361bdc1a2e960f", | |||
key | |||
); | |||
})); | |||
it("customize key length", () => pbkdf2( | |||
"password", | |||
"test@example.org", | |||
8192, | |||
16, | |||
"sha256" | |||
).then((key) => { | |||
it("customize key length", () => | |||
pbkdf2("password", "test@example.org", 8192, 16, "sha256").then((key) => { | |||
assert.equal("d8af5f918db6b65b1db3d3984e5a400e", key); | |||
})); | |||
it("customize iterations and key length", () => pbkdf2( | |||
"password", | |||
"test@example.org", | |||
4096, | |||
16, | |||
"sha256" | |||
).then((key) => { | |||
it("customize iterations and key length", () => | |||
pbkdf2("password", "test@example.org", 4096, 16, "sha256").then((key) => { | |||
assert.equal("0a91208545e3aa4935d3a22984ca097a", key); | |||
})); | |||
it("utf8 parameter", () => pbkdf2( | |||
"♥ LessPass ♥", | |||
"test@example.org", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651", | |||
key | |||
); | |||
})); | |||
it("auto generated test 0", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 1", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 2", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 3", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 4", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 5", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 6", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 7", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 8", () => pbkdf2( | |||
"password", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
})); | |||
it("auto generated test 9", () => pbkdf2("password", "lesspass", 8192, 32, "sha256").then(( | |||
key | |||
) => { | |||
it("utf8 parameter", () => | |||
pbkdf2("♥ LessPass ♥", "test@example.org", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 0", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 1", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 2", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 3", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 4", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 5", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 6", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 7", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 8", () => | |||
pbkdf2("password", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0", | |||
key | |||
); | |||
} | |||
)); | |||
it("auto generated test 9", () => | |||
pbkdf2("password", "lesspass", 8192, 32, "sha256").then((key) => { | |||
assert.equal( | |||
"7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116", | |||
key | |||
); | |||
})); | |||
it("auto generated test 10", () => pbkdf2( | |||
"password2", | |||
"contact@lesspass.com", | |||
8192, | |||
32, | |||
"sha256" | |||
).then((key) => { | |||
assert.equal( | |||
"ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4", | |||
key | |||
); | |||
})); | |||
it("auto generated test 10", () => | |||
pbkdf2("password2", "contact@lesspass.com", 8192, 32, "sha256").then( | |||
(key) => { | |||
assert.equal( | |||
"ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4", | |||
key | |||
); | |||
} | |||
)); | |||
}); |
@@ -1,7 +1,7 @@ | |||
const assert = require("assert"); | |||
const { | |||
stringToArrayBuffer, | |||
arrayBufferToHex | |||
arrayBufferToHex, | |||
} = require("../src/stringEncoding"); | |||
describe("stringEncoding", () => { | |||
@@ -20,11 +20,11 @@ | |||
"lesspass-crypto": "9.1.9" | |||
}, | |||
"devDependencies": { | |||
"karma": "^4.4.1", | |||
"browserify": "^17.0.0", | |||
"karma": "^6.1.2", | |||
"karma-browserify": "^8.0.0", | |||
"karma-chrome-launcher": "^3.1.0", | |||
"karma-mocha": "^1.3.0", | |||
"karma-webpack": "^4.0.2", | |||
"mocha": "^8.2.1", | |||
"webpack": "^4.44.2" | |||
"karma-mocha": "^2.0.1", | |||
"mocha": "^8.3.1" | |||
} | |||
} |
@@ -13,7 +13,7 @@ function getColor(color) { | |||
"#920000", | |||
"#924900", | |||
"#DB6D00", | |||
"#24FE23" | |||
"#24FE23", | |||
]; | |||
const index = parseInt(color, 16) % colors.length; | |||
return colors[index]; | |||
@@ -66,30 +66,30 @@ function getIcon(hash) { | |||
"fa-flask", | |||
"fa-futbol-o", | |||
"fa-gamepad", | |||
"fa-graduation-cap" | |||
"fa-graduation-cap", | |||
]; | |||
const index = parseInt(hash, 16) % icons.length; | |||
return icons[index]; | |||
} | |||
module.exports = function(hmacSHA256) { | |||
module.exports = function (hmacSHA256) { | |||
const fingerprint = []; | |||
const hash1 = hmacSHA256.substring(0, 6); | |||
fingerprint.push({ | |||
color: getColor(hash1), | |||
icon: getIcon(hash1) | |||
icon: getIcon(hash1), | |||
}); | |||
const hash2 = hmacSHA256.substring(6, 12); | |||
fingerprint.push({ | |||
color: getColor(hash2), | |||
icon: getIcon(hash2) | |||
icon: getIcon(hash2), | |||
}); | |||
const hash3 = hmacSHA256.substring(12, 18); | |||
fingerprint.push({ | |||
color: getColor(hash3), | |||
icon: getIcon(hash3) | |||
icon: getIcon(hash3), | |||
}); | |||
return fingerprint; | |||
@@ -1,4 +1,8 @@ | |||
const { stringToArrayBuffer, arrayBufferToHex, getAlgorithm } = require("lesspass-crypto"); | |||
const { | |||
stringToArrayBuffer, | |||
arrayBufferToHex, | |||
getAlgorithm, | |||
} = require("lesspass-crypto"); | |||
module.exports = function hmac(digest, string, salt) { | |||
return window.crypto.subtle | |||
@@ -7,14 +11,14 @@ module.exports = function hmac(digest, string, salt) { | |||
stringToArrayBuffer(string), | |||
{ | |||
name: "HMAC", | |||
hash: { name: getAlgorithm(digest) } | |||
hash: { name: getAlgorithm(digest) }, | |||
}, | |||
true, | |||
["sign", "verify"] | |||
) | |||
.then(key => | |||
.then((key) => | |||
window.crypto.subtle | |||
.sign({ name: "HMAC" }, key, stringToArrayBuffer(salt || "")) | |||
.then(signature => arrayBufferToHex(signature)) | |||
.then((signature) => arrayBufferToHex(signature)) | |||
); | |||
}; |
@@ -1,7 +1,7 @@ | |||
const crypto = require("crypto"); | |||
module.exports = function(digest, string, salt) { | |||
return new Promise(resolve => { | |||
module.exports = function (digest, string, salt) { | |||
return new Promise((resolve) => { | |||
resolve( | |||
crypto | |||
.createHmac(digest, string) | |||
@@ -3,5 +3,5 @@ const createHmac = require("./hmac"); | |||
module.exports = { | |||
createFingerprint, | |||
createHmac | |||
createHmac, | |||
}; |
@@ -3,14 +3,14 @@ const { createFingerprint, createHmac } = require("../src"); | |||
describe("api", () => { | |||
it("createHmac", () => | |||
createHmac("sha256", "password").then(fingerprint => { | |||
createHmac("sha256", "password").then((fingerprint) => { | |||
assert.equal( | |||
"e56a207acd1e6714735487c199c6f095844b7cc8e5971d86c003a7b6f36ef51e", | |||
fingerprint | |||
); | |||
})); | |||
it("createHmac and update", () => | |||
createHmac("sha256", "password", "salt").then(fingerprint => { | |||
createHmac("sha256", "password", "salt").then((fingerprint) => { | |||
assert.equal( | |||
"fc328232993ff34ca56631e4a101d60393cad12171997ee0b562bf7852b2fed0", | |||
fingerprint | |||
@@ -28,16 +28,16 @@ describe("api", () => { | |||
const expectedFingerprint = [ | |||
{ | |||
color: "#FFB5DA", | |||
icon: "fa-flask" | |||
icon: "fa-flask", | |||
}, | |||
{ | |||
color: "#009191", | |||
icon: "fa-archive" | |||
icon: "fa-archive", | |||
}, | |||
{ | |||
color: "#B5DAFE", | |||
icon: "fa-beer" | |||
} | |||
icon: "fa-beer", | |||
}, | |||
]; | |||
assert.deepEqual( | |||
createFingerprint( | |||
@@ -1,17 +1,14 @@ | |||
module.exports = config => { | |||
module.exports = (config) => { | |||
config.set({ | |||
basePath: "..", | |||
frameworks: ["mocha"], | |||
frameworks: ["mocha", "browserify"], | |||
plugins: ["karma-mocha", "karma-browserify", "karma-chrome-launcher"], | |||
files: ["src/index.js", "test/**/*.js"], | |||
preprocessors: { | |||
"src/index.js": ["webpack"], | |||
"test/**/*.js": ["webpack"] | |||
}, | |||
webpack: {}, | |||
webpackMiddleware: { | |||
stats: "errors-only" | |||
"src/index.js": ["browserify"], | |||
"test/**/*.js": ["browserify"], | |||
}, | |||
browsers: ["ChromeHeadless"], | |||
singleRun: true | |||
singleRun: true, | |||
}); | |||
}; |
@@ -2339,7 +2339,7 @@ lesspass-fingerprint@9.1.9: | |||
dependencies: | |||
lesspass-crypto "9.1.9" | |||
lesspass-pure@9.2.0: | |||
lesspass-pure@latest: | |||
version "9.2.0" | |||
resolved "https://registry.yarnpkg.com/lesspass-pure/-/lesspass-pure-9.2.0.tgz#80b4fdf401b3218b9c1f1b252c66c5e3d96941ec" | |||
integrity sha512-4PsmTSOxG5F2z9tP6u5CxHAps/9yHCkkZ2MAEjE0qaEYUePrD+YJtjrzPspks92pSpahjLGAmBtffDCzV11iVQ== | |||