Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: keychain rotate passphrase #944

Merged
merged 23 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d04339e
changeKeychainPassword
testasdsdas May 13, 2021
f0220bb
Merge branch 'libp2p:master' into keychain-rotating-passphrase
zeim839 May 13, 2021
2591ca7
refactor: renamed changeKeychainPassword() to rotateKeychainPass()
zeim839 May 19, 2021
66eb066
refactor: renamed old/newPassword to old/newPass
testasdsdas May 19, 2021
c150749
fix: generates new options & operates on self key
testasdsdas May 19, 2021
b20e83b
doc: rotateKeychainPass
testasdsdas May 19, 2021
f8db3c9
test: rotate keychain passphrase
testasdsdas May 19, 2021
825d70c
test: rotate keychain passphrase
testasdsdas May 20, 2021
1744f8d
fix: throwDelayed error, export key with newDek
zeim839 May 21, 2021
9d591ff
lint: rotateKeychainPass
zeim839 May 21, 2021
28a2b4a
fix: rotateKeychainPass tests
zeim839 May 21, 2021
bc35ac3
fix: Uint8Array not assignable error
zeim839 May 21, 2021
87dcc5b
fix: typo
zeim839 May 22, 2021
1e06652
fix: lint
vasco-santos May 25, 2021
5e48dee
fix: lint in test
vasco-santos May 25, 2021
59e9871
fix: function returning before cycle finished
zeim839 May 26, 2021
59244c2
lint: removed parenthesis
zeim839 May 26, 2021
f855a2a
fix: await test to finish and expect to eventually be rejected
zeim839 May 26, 2021
dec59e2
fix: await test to finish and expect to eventually have property name
zeim839 May 26, 2021
0222ea7
fix: issue decrypting keys from previous tests
zeim839 May 26, 2021
ae68e1c
fix: rotateKeychainPass() test timing out
zeim839 May 26, 2021
00ed8ce
lint: fix typo
zeim839 May 26, 2021
7b66ea6
perf: removed redundant batch delete/commit
zeim839 May 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
changeKeychainPassword
  • Loading branch information
testasdsdas committed May 13, 2021
commit d04339ea37995b7d29f29030b66e7da592c26b2e
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class Libp2p extends EventEmitter {
}

// Create keychain
// TODO: Decide how to change these options when the keychain password is being changed
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
if (this._options.keychain && this._options.keychain.datastore) {
log('creating keychain')

Expand Down
30 changes: 30 additions & 0 deletions src/keychain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,36 @@ class Keychain {
return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), 'ERR_KEY_NOT_FOUND'))
}
}

zeim839 marked this conversation as resolved.
Show resolved Hide resolved
async changeKeychainPassword(oldPassword, newPassword){
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
if (typeof oldPassword !== 'string' || typeof newPassword !== 'string') {
throw new Error(`Invalid pass type '${typeof oldPassword}'`);
}
if (newPassword.length < 20) {
throw new Error('pass must be least 20 characters')
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
}
// TODO: Need to decide on how to import/generate opts
const newDek = newPassword
? crypto.pbkdf2(
newPassword,
this.opts.dek.salt,
this.opts.dek.iterationCount,
this.opts.dek.keyLength,
this.opts.dek.hash)
: ''
const oldDek = privates.get(this).dek
privates.set(this, { "dek":newDek })
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
var keys = await this.listKeys()
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
await keys.forEach(async key =>{
// TODO: Decide how to handle deleting and importing the "self" key.
// importKey and removeKey throw an error when handling "self"
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
if (key.name != "self"){
var keyAsPEM = await this._getPrivateKey(key.name)
await this.removeKey(key.name)
this.importKey(key.name, keyAsPEM, oldDek)
}
})
zeim839 marked this conversation as resolved.
Show resolved Hide resolved
}
}

module.exports = Keychain