|
|
@ -72,6 +72,11 @@ static struct { |
|
|
|
* so set it static.*/ |
|
|
|
static struct bip32_key_version bip32_key_version; |
|
|
|
|
|
|
|
#if DEVELOPER |
|
|
|
/* If they specify --dev-force-privkey it ends up in here. */ |
|
|
|
static struct privkey *dev_force_privkey; |
|
|
|
#endif |
|
|
|
|
|
|
|
/*~ We keep track of clients, but there's not much to keep. */ |
|
|
|
struct client { |
|
|
|
/* The ccan/io async io connection for this client: it closes, we die. */ |
|
|
@ -314,6 +319,17 @@ static void node_key(struct privkey *node_privkey, struct pubkey *node_id) |
|
|
|
salt++; |
|
|
|
} while (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id->pubkey, |
|
|
|
node_privkey->secret.data)); |
|
|
|
|
|
|
|
#if DEVELOPER |
|
|
|
/* In DEVELOPER mode, we can override with --dev-force-privkey */ |
|
|
|
if (dev_force_privkey) { |
|
|
|
*node_privkey = *dev_force_privkey; |
|
|
|
if (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id->pubkey, |
|
|
|
node_privkey->secret.data)) |
|
|
|
status_failed(STATUS_FAIL_INTERNAL_ERROR, |
|
|
|
"Failed to derive pubkey for dev_force_privkey"); |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/*~ This secret is the basis for all per-channel secrets: the per-channel seeds
|
|
|
@ -540,6 +556,7 @@ static struct io_plan *init_hsm(struct io_conn *conn, |
|
|
|
{ |
|
|
|
struct node_id node_id; |
|
|
|
struct pubkey key; |
|
|
|
struct privkey *privkey; |
|
|
|
|
|
|
|
/* This must be lightningd. */ |
|
|
|
assert(is_lightningd(c)); |
|
|
@ -548,9 +565,12 @@ static struct io_plan *init_hsm(struct io_conn *conn, |
|
|
|
* definitions in hsm_client_wire.csv. The format of those files is |
|
|
|
* an extension of the simple comma-separated format output by the |
|
|
|
* BOLT tools/extract-formats.py tool. */ |
|
|
|
if (!fromwire_hsm_init(msg_in, &bip32_key_version)) |
|
|
|
if (!fromwire_hsm_init(NULL, msg_in, &bip32_key_version, &privkey)) |
|
|
|
return bad_req(conn, c, msg_in); |
|
|
|
|
|
|
|
#if DEVELOPER |
|
|
|
dev_force_privkey = privkey; |
|
|
|
#endif |
|
|
|
maybe_create_new_hsm(); |
|
|
|
load_hsm(); |
|
|
|
|
|
|
@ -1601,6 +1621,8 @@ static struct io_plan *handle_memleak(struct io_conn *conn, |
|
|
|
memleak_remove_uintmap(memtable, &clients); |
|
|
|
memleak_scan_region(memtable, status_conn, tal_bytelen(status_conn)); |
|
|
|
|
|
|
|
memleak_scan_region(memtable, dev_force_privkey, 0); |
|
|
|
|
|
|
|
found_leak = dump_memleak(memtable); |
|
|
|
reply = towire_hsm_dev_memleak_reply(NULL, found_leak); |
|
|
|
return req_reply(conn, c, take(reply)); |
|
|
|