Skip to content

Commit

Permalink
Merge pull request #162 from cozy/fix/computeMasterKey
Browse files Browse the repository at this point in the history
fix: call `cryptoService.makeKey` directly form `computeMasterKey`
  • Loading branch information
Ldoppea authored Sep 9, 2021
2 parents aa74532 + e54dfad commit 2dcdf5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/WebVaultClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,12 @@ class WebVaultClient {
* @return {string} hashed password for login
*/
async computeMasterKey(masterPassword, iterations, kdf) {
// clone the authService to avoid messing
// with the requested kdf and kdf iterations if provided
let authService = iterations
? this.authService
: Object.assign(Object.create(this.authService), this.authService, {
kdfIterations: iterations,
kdf: kdf || KdfType.PBKDF2_SHA256
})
return await authService.makePreloginKey(masterPassword, this.email)
return await this.cryptoService.makeKey(
masterPassword,
this.email,
kdf || KdfType.PBKDF2_SHA256,
iterations
)
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/WebVaultClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,25 @@ describe('WebVaultClient', () => {
})
})
})

describe('computeMasterKey', () => {
const client = new WebVaultClient('https://me.cozy.wtf')

jest.spyOn(client.cryptoService, 'makeKey').mockImplementation(() => {})

afterEach(() => {
client.cryptoService.makeKey.mockReset()
})

it('should call cryptoService.makeKey', async () => {
await client.computeMasterKey('SOME_PASSWORD', 123456, 0)

expect(client.cryptoService.makeKey).toHaveBeenCalledWith(
'SOME_PASSWORD',
'[email protected]',
0,
123456
)
})
})
})

0 comments on commit 2dcdf5c

Please sign in to comment.