Skip to content

Commit 01161aa

Browse files
committed
hsmd: derive an onion_reply secret.
We put this in reply paths, so we can tell if they are used. This lets us avoid responding unless the correct reply path is used. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 3a96619 commit 01161aa

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

hsmd/hsmd_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ msgtype,hsmd_init_reply,111
2121
msgdata,hsmd_init_reply,node_id,node_id,
2222
msgdata,hsmd_init_reply,bip32,ext_key,
2323
msgdata,hsmd_init_reply,bolt12,pubkey32,
24+
msgdata,hsmd_init_reply,onion_reply_secret,secret,
2425

2526
# Get a new HSM FD, with the specified capabilities
2627
msgtype,hsmd_client_hsmfd,9

hsmd/hsmd_wiregen.c

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hsmd/hsmd_wiregen.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hsmd/libhsmd.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ u8 *hsmd_init(struct secret hsm_secret,
14691469
u32 salt = 0;
14701470
struct ext_key master_extkey, child_extkey;
14711471
struct node_id node_id;
1472+
struct secret onion_reply_secret;
14721473

14731474
/*~ Don't swap this. */
14741475
sodium_mlock(secretstuff.hsm_secret.data,
@@ -1588,10 +1589,18 @@ u8 *hsmd_init(struct secret hsm_secret,
15881589
hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
15891590
"Could derive bolt12 public key.");
15901591

1592+
/*~ We derive a secret for onion_message's self_id so we can tell
1593+
* if it used a path we created (i.e. do not leak our public id!) */
1594+
hkdf_sha256(&onion_reply_secret, sizeof(onion_reply_secret),
1595+
NULL, 0,
1596+
&secretstuff.hsm_secret,
1597+
sizeof(secretstuff.hsm_secret),
1598+
"onion reply secret", strlen("onion reply secret"));
1599+
15911600
/*~ Note: marshalling a bip32 tree only marshals the public side,
15921601
* not the secrets! So we're not actually handing them out here!
15931602
*/
15941603
return take(towire_hsmd_init_reply(
15951604
NULL, &node_id, &secretstuff.bip32,
1596-
&bolt12));
1605+
&bolt12, &onion_reply_secret));
15971606
}

lightningd/hsm_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ struct ext_key *hsm_init(struct lightningd *ld)
116116
msg = wire_sync_read(tmpctx, ld->hsm_fd);
117117
if (!fromwire_hsmd_init_reply(msg,
118118
&ld->id, bip32_base,
119-
&ld->bolt12_base)) {
119+
&ld->bolt12_base,
120+
&ld->onion_reply_secret)) {
120121
if (ld->config.keypass)
121122
errx(1, "Wrong password for encrypted hsm_secret.");
122123
errx(1, "HSM did not give init reply");

lightningd/lightningd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ struct lightningd {
109109
/* The public base for our payer_id keys */
110110
struct pubkey32 bolt12_base;
111111

112+
/* The secret we put in onion message paths to know it's ours. */
113+
struct secret onion_reply_secret;
114+
112115
/* Feature set we offer. */
113116
struct feature_set *our_features;
114117

0 commit comments

Comments
 (0)