Skip to content

Commit

Permalink
lightningd/hsm_control: Pass mnemonic and passphrase to HSMD
Browse files Browse the repository at this point in the history
Previous changes added options in lightningd and arguments in `hsm_init`
to spefify BIP39 mnemonic and passphrase. This change passes those
values from lightningd config to `hsm_init`.

Fixes: ElementsProject#3717
Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
  • Loading branch information
Michal Rostecki committed May 14, 2020
1 parent 8039739 commit f94f873
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lightningd/hsm_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ static unsigned int hsm_msg(struct subd *hsmd,

void hsm_init(struct lightningd *ld)
{
u8 *passphrase;
u8 *mnemonic;
u8 *msg;
int fds[2];

Expand All @@ -109,6 +111,13 @@ void hsm_init(struct lightningd *ld)
"--encrypted-hsm startup option.");
}

passphrase = tal_dup_arr(tmpctx, u8, (u8 *)ld->config.passphrase,
tal_count(ld->config.passphrase), 1);
passphrase[tal_count(ld->config.passphrase)] = '\0';
mnemonic = tal_dup_arr(tmpctx, u8, (u8 *)ld->config.mnemonic,
tal_count(ld->config.mnemonic), 1);
mnemonic[tal_count(ld->config.mnemonic)] = '\0';

ld->hsm_fd = fds[0];
if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx,
&chainparams->bip32_key_version,
Expand All @@ -117,7 +126,9 @@ void hsm_init(struct lightningd *ld)
IFDEV(ld->dev_force_privkey, NULL),
IFDEV(ld->dev_force_bip32_seed, NULL),
IFDEV(ld->dev_force_channel_secrets, NULL),
IFDEV(ld->dev_force_channel_secrets_shaseed, NULL))))
IFDEV(ld->dev_force_channel_secrets_shaseed, NULL),
mnemonic,
passphrase)))
err(1, "Writing init msg to hsm");

ld->wallet->bip32_base = tal(ld->wallet, struct ext_key);
Expand Down

0 comments on commit f94f873

Please sign in to comment.