-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change master password (#2007)
* feat(db): migration framework This introduces a framework for tracking a database's version and migrating from one version to the next when the database schema needs to be modified. The migrations consist of an array of methods that each are responsible for upgrading from a particular version, and they are run in sequence when we detect that the current database version is lower than the latest version. * feat(db): migration to db v1 * refactor: cryptoUtils * test: cryptoUtils * feat: change master password This adds the ability to change the master password of an existing xud node. Changing the password re-encrypts the node key on disk and queues password changes for all lnd wallets. Lnd does not currently offer the ability to change the password of an unlocked, running instance. Instead lnd can only change its password right after being started while it is still locked. Xud therefore saves the old password for each lnd wallet to the xud database and encrypts the old password using the new passwords. On subsequent unlocks of xud, when we go to unlock lnd wallets we first check whether we have any old passwords in the database corresponding to any lnd wallets. If we do, we decrypt the old password and change the password for lnd, which in turn will unlock lnd. Closes #1981.
- Loading branch information
Showing
32 changed files
with
1,375 additions
and
481 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import readline from 'readline'; | ||
import { Arguments } from 'yargs'; | ||
import { ChangePasswordRequest } from '../../proto/xudrpc_pb'; | ||
import { callback, loadXudClient } from '../command'; | ||
|
||
export const command = 'changepass'; | ||
|
||
export const describe = 'change the password for an existing xud instance'; | ||
|
||
export const builder = {}; | ||
|
||
const formatOutput = () => { | ||
console.log('The master xud password was succesfully changed.'); | ||
console.log('Passwords for lnd wallets will be changed the next time xud is restarted and unlocked.'); | ||
}; | ||
|
||
export const handler = (argv: Arguments<any>) => { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
terminal: true, | ||
}); | ||
|
||
console.log(`\ | ||
You are changing the master password for xud and underlying wallets.\ | ||
`); | ||
process.stdout.write('Enter old password: '); | ||
rl.question('', (oldPassword) => { | ||
process.stdout.write('\nEnter new password: '); | ||
rl.question('', (password1) => { | ||
process.stdout.write('\nRe-enter password: '); | ||
rl.question('', async (password2) => { | ||
process.stdout.write('\n\n'); | ||
rl.close(); | ||
if (password1 === password2) { | ||
const request = new ChangePasswordRequest(); | ||
request.setNewPassword(password1); | ||
request.setOldPassword(oldPassword); | ||
|
||
const client = await loadXudClient(argv); | ||
// wait up to 3 seconds for rpc server to listen before call in case xud was just started | ||
client.waitForReady(Date.now() + 3000, () => { | ||
client.changePassword(request, callback(argv, formatOutput)); | ||
}); | ||
} else { | ||
process.exitCode = 1; | ||
console.error('Passwords do not match, please try again'); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Sequelize, { DataTypes } from 'sequelize'; | ||
|
||
/** | ||
* An ordered array of functions that will migrate the database from one | ||
* version to the next. The 1st element (index 0) will migrate from version | ||
* 0 to 1, the 2nd element will migrate from version 1 to 2, and so on... | ||
* Each migration must be called in order and allowed to complete before | ||
* calling the next. | ||
*/ | ||
const migrations: ((sequelize: Sequelize.Sequelize) => Promise<void>)[] = []; | ||
|
||
migrations[0] = async (sequelize: Sequelize.Sequelize) => { | ||
await sequelize.getQueryInterface().createTable('passwords', { | ||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, | ||
encryptedPassword: { type: DataTypes.STRING, allowNull: false }, | ||
currency: { type: DataTypes.STRING(5), allowNull: true }, | ||
swapClient: { type: DataTypes.TINYINT, allowNull: false }, | ||
createdAt: { type: DataTypes.BIGINT, allowNull: false }, | ||
}); | ||
}; | ||
|
||
export default migrations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DataTypes, ModelAttributes, ModelOptions, Sequelize } from 'sequelize'; | ||
import { PasswordInstance } from '../types'; | ||
|
||
export default function Password(sequelize: Sequelize) { | ||
const attributes: ModelAttributes<PasswordInstance> = { | ||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, | ||
encryptedPassword: { type: DataTypes.STRING, allowNull: false }, | ||
currency: { type: DataTypes.STRING(5), allowNull: true }, | ||
swapClient: { type: DataTypes.TINYINT, allowNull: false }, | ||
createdAt: { type: DataTypes.BIGINT, allowNull: false }, | ||
}; | ||
|
||
const options: ModelOptions = { | ||
tableName: 'passwords', | ||
timestamps: true, | ||
updatedAt: false, | ||
}; | ||
|
||
const Password = sequelize.define<PasswordInstance>('Password', attributes, options); | ||
return Password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.