diff --git a/channeld/Makefile b/channeld/Makefile index 1c15d2ef8040..d68f6a18fa6e 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -72,6 +72,7 @@ CHANNELD_COMMON_OBJS := \ common/wire_error.o \ common/wireaddr.o \ gossipd/gen_gossip_wire.o \ + hsmd/gen_hsm_client_wire.o \ lightningd/gossip_msg.o \ wire/fromwire.o \ wire/towire.o diff --git a/closingd/Makefile b/closingd/Makefile index 0eedf7af8ade..32279bbd46cb 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -72,6 +72,7 @@ CLOSINGD_COMMON_OBJS := \ common/wire_error.o \ common/wireaddr.o \ gossipd/gen_gossip_wire.o \ + hsmd/gen_hsm_client_wire.o \ lightningd/gossip_msg.o closingd/gen_closing_wire.h: $(WIRE_GEN) closingd/closing_wire.csv diff --git a/connectd/Makefile b/connectd/Makefile index f32dc7bce597..d3eacb9bb80e 100644 --- a/connectd/Makefile +++ b/connectd/Makefile @@ -61,7 +61,6 @@ CONNECTD_COMMON_OBJS := \ common/wireaddr.o \ common/wire_error.o \ gossipd/gen_gossip_wire.o \ - hsmd/client.o \ hsmd/gen_hsm_client_wire.o \ lightningd/gossip_msg.o \ wire/gen_onion_wire.o diff --git a/connectd/connectd.c b/connectd/connectd.c index 192dae73a17a..fc97bab8b85a 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -1286,6 +1285,21 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master t, tal_hex(tmpctx, master->msg_in)); } +/* Helper for handshake.c */ +bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point) +{ + u8 *req = towire_hsm_ecdh_req(tmpctx, point), *resp; + + if (!wire_sync_write(HSM_FD, req)) + return false; + resp = wire_sync_read(req, HSM_FD); + if (!resp) + return false; + if (!fromwire_hsm_ecdh_resp(resp, ss)) + return false; + return true; +} + #ifndef TESTING static void master_gone(struct io_conn *unused UNUSED, struct daemon_conn *dc UNUSED) { @@ -1312,7 +1326,6 @@ int main(int argc, char *argv[]) daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req, master_gone); status_setup_async(&daemon->master); - hsm_setup(HSM_FD); /* When conn closes, everything is freed. */ tal_steal(daemon->master.conn, daemon); diff --git a/connectd/handshake.c b/connectd/handshake.c index 296e0a4faf08..d861e2424c05 100644 --- a/connectd/handshake.c +++ b/connectd/handshake.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/connectd/handshake.h b/connectd/handshake.h index 2e501dd8f381..20c51ecb9b44 100644 --- a/connectd/handshake.h +++ b/connectd/handshake.h @@ -51,4 +51,6 @@ struct io_plan *responder_handshake_(struct io_conn *conn, void *cbarg), void *cbarg); +/* helper which is defined in connect.c */ +bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point); #endif /* LIGHTNING_CONNECTD_HANDSHAKE_H */ diff --git a/gossipd/Makefile b/gossipd/Makefile index 264fe33aee93..cdb1e122cedb 100644 --- a/gossipd/Makefile +++ b/gossipd/Makefile @@ -61,7 +61,6 @@ GOSSIPD_COMMON_OBJS := \ common/wireaddr.o \ common/wire_error.o \ connectd/gen_connect_gossip_wire.o \ - hsmd/client.o \ hsmd/gen_hsm_client_wire.o \ lightningd/gossip_msg.o \ wire/gen_onion_wire.o diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 45c00be6a4c9..a05025303a44 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -2258,7 +2257,6 @@ int main(int argc, char *argv[]) daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req, master_gone); status_setup_async(&daemon->master); - hsm_setup(HSM_FD); daemon_conn_init(daemon, &daemon->connectd, CONNECTD_FD, connectd_req, NULL); diff --git a/hsmd/Makefile b/hsmd/Makefile index 5147f21f3dc4..dbc5a17c95aa 100644 --- a/hsmd/Makefile +++ b/hsmd/Makefile @@ -6,16 +6,9 @@ hsmd-wrongdir: default: hsmd-all -# Clients use this: -LIGHTNINGD_HSM_CLIENT_HEADERS := hsmd/client.h -LIGHTNINGD_HSM_CLIENT_SRC := hsmd/client.c hsmd/gen_hsm_client_wire.c -LIGHTNINGD_HSM_CLIENT_OBJS := $(LIGHTNINGD_HSM_CLIENT_SRC:.c=.o) - -# lightningd/hsm needs these: -LIGHTNINGD_HSM_HEADERS := hsmd/gen_hsm_client_wire.h - LIGHTNINGD_HSM_SRC := hsmd/hsmd.c \ - $(LIGHTNINGD_HSM_HEADERS:.h=.c) + hsmd/gen_hsm_client_wire.c +LIGHTNINGD_HSM_HEADERS := hsmd/gen_hsm_client_wire.h LIGHTNINGD_HSM_OBJS := $(LIGHTNINGD_HSM_SRC:.c=.o) # Common source we use. @@ -40,20 +33,17 @@ HSMD_COMMON_OBJS := \ common/withdraw_tx.o # For checking -LIGHTNINGD_HSM_ALLSRC_NOGEN := $(filter-out hsmd/gen_%, $(LIGHTNINGD_HSM_CLIENT_SRC) $(LIGHTNINGD_HSM_SRC)) -LIGHTNINGD_HSM_ALLHEADERS_NOGEN := $(filter-out hsmd/gen_%, $(LIGHTNINGD_HSM_CLIENT_HEADERS) $(LIGHTNINGD_HSM_HEADERS)) - -# Add to headers which any object might need. -LIGHTNINGD_HEADERS_GEN += $(LIGHTNINGD_HSM_HEADERS) $(LIGHTNINGD_HSM_CLIENT_HEADERS) +LIGHTNINGD_HSM_ALLSRC_NOGEN := $(filter-out hsmd/gen_%, $(LIGHTNINGD_HSM_SRC) $(LIGHTNINGD_HSM_SRC)) +LIGHTNINGD_HSM_ALLHEADERS_NOGEN := $(filter-out hsmd/gen_%, $(LIGHTNINGD_HSM_HEADERS)) -$(LIGHTNINGD_HSM_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS): $(LIGHTNINGD_HEADERS) +$(LIGHTNINGD_HSM_OBJS): $(LIGHTNINGD_HEADERS) # Make sure these depend on everything. -ALL_OBJS += $(LIGHTNINGD_HSM_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS) +ALL_OBJS += $(LIGHTNINGD_HSM_OBJS) ALL_PROGRAMS += lightningd/lightning_hsmd -ALL_GEN_HEADERS += $(LIGHTNINGD_HSM_HEADERS) +ALL_GEN_HEADERS += hsmd/gen_hsm_client_wire.h -hsmd-all: lightningd/lightning_hsmd $(LIGHTNINGD_HSM_CLIENT_OBJS) +hsmd-all: lightningd/lightning_hsmd lightningd/lightning_hsmd: $(LIGHTNINGD_HSM_OBJS) $(LIGHTNINGD_LIB_OBJS) $(HSMD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) @@ -70,7 +60,7 @@ hsmd/gen_hsm_wire.c: $(WIRE_GEN) hsmd/hsm_wire.csv $(WIRE_GEN) ${@:.c=.h} hsm_wire_type < hsmd/hsm_wire.csv > $@ check-source: $(LIGHTNINGD_HSM_ALLSRC_NOGEN:%=check-src-include-order/%) $(LIGHTNINGD_HSM_ALLHEADERS_NOGEN:%=check-hdr-include-order/%) -check-source-bolt: $(LIGHTNINGD_HSM_SRC:%=bolt-check/%) $(LIGHTNINGD_HSM_HEADERS:%=bolt-check/%) +check-source-bolt: $(LIGHTNINGD_HSM_SRC:%=bolt-check/%) check-whitespace: $(LIGHTNINGD_HSM_ALLSRC_NOGEN:%=check-whitespace/%) $(LIGHTNINGD_HSM_ALLHEADERS_NOGEN:%=check-whitespace/%) diff --git a/hsmd/client.c b/hsmd/client.c deleted file mode 100644 index c631f826fe73..000000000000 --- a/hsmd/client.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -static int hsm_fd = -1; - -void hsm_setup(int fd) -{ - hsm_fd = fd; -} - -bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point) -{ - u8 *req = towire_hsm_ecdh_req(NULL, point), *resp; - - if (!wire_sync_write(hsm_fd, req)) - goto fail; - resp = wire_sync_read(req, hsm_fd); - if (!resp) - goto fail; - if (!fromwire_hsm_ecdh_resp(resp, ss)) - goto fail; - tal_free(req); - return true; - -fail: - tal_free(req); - return false; -} diff --git a/hsmd/client.h b/hsmd/client.h deleted file mode 100644 index 9adfb28fbf49..000000000000 --- a/hsmd/client.h +++ /dev/null @@ -1,17 +0,0 @@ -/* API to ask the HSM for things. */ -#ifndef LIGHTNING_HSMD_CLIENT_H -#define LIGHTNING_HSMD_CLIENT_H -#include "config.h" -#include -#include -#include - -struct pubkey; -struct secret; - -/* Setup communication to the HSM */ -void hsm_setup(int fd); - -/* Do ECDH using this node id secret. */ -bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point); -#endif /* LIGHTNING_HSMD_CLIENT_H */ diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index 9acb0edb521c..3b187536da3f 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/lightningd/Makefile b/lightningd/Makefile index 682fe33a724f..9508dfe62ce2 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -48,7 +48,8 @@ LIGHTNINGD_COMMON_OBJS := \ common/wallet_tx.o \ common/wire_error.o \ common/wireaddr.o \ - common/withdraw_tx.o + common/withdraw_tx.o \ + hsmd/gen_hsm_client_wire.o LIGHTNINGD_SRC := \ lightningd/bitcoind.c \ @@ -120,7 +121,7 @@ check-makefile: check-lightningd-makefile check-lightningd-makefile: @for f in lightningd/*.h lightningd/*/*.h; do if ! echo $(LIGHTNINGD_HEADERS_NOGEN) $(LIGHTNINGD_HEADERS_GEN) "" | grep -q "$$f "; then echo $$f not mentioned in LIGHTNINGD_HEADERS_NOGEN or LIGHTNINGD_HEADERS_GEN >&2; exit 1; fi; done -lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) $(LIGHTNINGD_CONNECT_CONTROL_OBJS) +lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) $(LIGHTNINGD_CONNECT_CONTROL_OBJS) clean: lightningd-clean diff --git a/onchaind/Makefile b/onchaind/Makefile index 1ea8b7bbcaf5..e2d76695be33 100644 --- a/onchaind/Makefile +++ b/onchaind/Makefile @@ -68,7 +68,8 @@ ONCHAIND_COMMON_OBJS := \ common/type_to_string.o \ common/utils.o \ common/utxo.o \ - common/version.o + common/version.o \ + hsmd/gen_hsm_client_wire.o onchaind/gen_onchain_wire.h: $(WIRE_GEN) onchaind/onchain_wire.csv $(WIRE_GEN) --header $@ onchain_wire_type < onchaind/onchain_wire.csv > $@ diff --git a/openingd/Makefile b/openingd/Makefile index 92fb90a0ac67..33cbea1c040a 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -70,6 +70,7 @@ OPENINGD_COMMON_OBJS := \ common/wire_error.o \ common/wireaddr.o \ gossipd/gen_gossip_wire.o \ + hsmd/gen_hsm_client_wire.o \ lightningd/gossip_msg.o $(LIGHTNINGD_OPENING_OBJS): $(LIGHTNINGD_HEADERS)