From 9bf238e0014d7ed92ebd23dec0e1a56f5431505e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 23 Jul 2018 11:53:03 +0930 Subject: [PATCH] hsmd: provide message for master to get basepoints & funding pubkey for a channel This is only used by the master daemon, but it's not secret information. Signed-off-by: Rusty Russell --- gossipd/Makefile | 1 + hsmd/hsm.c | 28 ++++++++++++++++++++++++++++ hsmd/hsm_client_wire_csv | 9 +++++++++ 3 files changed, 38 insertions(+) diff --git a/gossipd/Makefile b/gossipd/Makefile index 0e02fc841..e93222e9d 100644 --- a/gossipd/Makefile +++ b/gossipd/Makefile @@ -49,6 +49,7 @@ GOSSIPD_COMMON_OBJS := \ common/daemon.o \ common/daemon_conn.o \ common/decode_short_channel_ids.o \ + common/derive_basepoints.o \ common/dev_disconnect.o \ common/features.o \ common/gen_status_wire.o \ diff --git a/hsmd/hsm.c b/hsmd/hsm.c index 02e6dc4ea..5bab06f32 100644 --- a/hsmd/hsm.c +++ b/hsmd/hsm.c @@ -278,6 +278,28 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn, return daemon_conn_read_next(conn, dc); } +static struct io_plan *handle_get_channel_basepoints(struct io_conn *conn, + struct daemon_conn *dc) +{ + struct pubkey peer_id; + u64 dbid; + struct secret seed; + struct basepoints basepoints; + struct pubkey funding_pubkey; + + if (!fromwire_hsm_get_channel_basepoints(dc->msg_in, &peer_id, &dbid)) + master_badmsg(WIRE_HSM_GET_CHANNEL_BASEPOINTS, dc->msg_in); + + get_channel_seed(&peer_id, dbid, &seed); + derive_basepoints(&seed, &funding_pubkey, &basepoints, NULL, NULL); + + daemon_conn_send(dc, + take(towire_hsm_get_channel_basepoints_reply(NULL, + &basepoints, + &funding_pubkey))); + return daemon_conn_read_next(conn, dc); +} + /* FIXME: Ensure HSM never does this twice for same dbid! */ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn, struct daemon_conn *dc) @@ -766,6 +788,7 @@ static bool check_client_capabilities(struct client *client, case WIRE_HSM_SIGN_WITHDRAWAL: case WIRE_HSM_SIGN_INVOICE: case WIRE_HSM_SIGN_COMMITMENT_TX: + case WIRE_HSM_GET_CHANNEL_BASEPOINTS: return (client->capabilities & HSM_CAP_MASTER) != 0; /* These are messages sent by the HSM so we should never receive them */ @@ -782,6 +805,7 @@ static bool check_client_capabilities(struct client *client, case WIRE_HSM_SIGN_COMMITMENT_TX_REPLY: case WIRE_HSM_SIGN_TX_REPLY: case WIRE_HSM_GET_PER_COMMITMENT_POINT_REPLY: + case WIRE_HSM_GET_CHANNEL_BASEPOINTS_REPLY: break; } return false; @@ -815,6 +839,9 @@ static struct io_plan *handle_client(struct io_conn *conn, pass_client_hsmfd(dc, dc->msg_in); return daemon_conn_read_next(conn, dc); + case WIRE_HSM_GET_CHANNEL_BASEPOINTS: + return handle_get_channel_basepoints(conn, dc); + case WIRE_HSM_ECDH_REQ: return handle_ecdh(conn, dc); @@ -880,6 +907,7 @@ static struct io_plan *handle_client(struct io_conn *conn, case WIRE_HSM_SIGN_COMMITMENT_TX_REPLY: case WIRE_HSM_SIGN_TX_REPLY: case WIRE_HSM_GET_PER_COMMITMENT_POINT_REPLY: + case WIRE_HSM_GET_CHANNEL_BASEPOINTS_REPLY: break; } diff --git a/hsmd/hsm_client_wire_csv b/hsmd/hsm_client_wire_csv index 1757caf9f..dcf71b92d 100644 --- a/hsmd/hsm_client_wire_csv +++ b/hsmd/hsm_client_wire_csv @@ -23,6 +23,15 @@ hsm_client_hsmfd,,capabilities,u64 # No content, just an fd. hsm_client_hsmfd_reply,109 +#include +# Get the basepoints and funding key for this specific channel. +hsm_get_channel_basepoints,10 +hsm_get_channel_basepoints,,peerid,struct pubkey +hsm_get_channel_basepoints,,dbid,u64 + +hsm_get_channel_basepoints_reply,110 +hsm_get_channel_basepoints_reply,,basepoints,struct basepoints +hsm_get_channel_basepoints_reply,,funding_pubkey,struct pubkey # Return signature for a funding tx. #include