Skip to content

Commit

Permalink
lightningd: prevent hsmd from interpretating an encrypted hsm_secret …
Browse files Browse the repository at this point in the history
…as not encrypted
  • Loading branch information
darosior committed Oct 3, 2019
1 parent 54491e6 commit f9731da
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lightningd/hsm_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <lightningd/log_status.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <wally_bip32.h>
#include <wire/wire_sync.h>
Expand Down Expand Up @@ -94,6 +95,16 @@ void hsm_init(struct lightningd *ld)
if (!ld->hsm)
err(1, "Could not subd hsm");

/* If hsm_secret is encrypted and the --encrypted-hsm startup option is
* not passed, don't let hsmd use the first 32 bytes of the cypher as the
* actual secret. */
if (!ld->config.keypass) {
struct stat st;
if (stat("hsm_secret", &st) == 0 && st.st_size > 32)
errx(1, "hsm_secret is encrypted, you need to pass the "
"--encrypted-hsm startup option.");
}

ld->hsm_fd = fds[0];
if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx,
&ld->topology->bitcoind->chainparams->bip32_key_version,
Expand Down

0 comments on commit f9731da

Please sign in to comment.