From 2d9cb67b1d8b27ac095fa7e7ac639cbc4393d489 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Mon, 19 Feb 2024 10:04:01 +0100 Subject: [PATCH 1/2] hsmd: increase the min version Increasing the min version of the hsmd due that we added new code that required the hsmd to sign an announcements. One of the solution is to increase the min version in this way a signer like VLS fails directly during the init phase. Link: https://github.com/ElementsProject/lightning/issues/7074 Changelog-None: hsmd: increase the min version Signed-off-by: Vincenzo Palazzo --- common/hsm_version.h | 2 +- hsmd/hsmd.c | 7 +++++-- hsmd/libhsmd.c | 4 ++-- hsmd/libhsmd.h | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/common/hsm_version.h b/common/hsm_version.h index 5a2c2deac84a..bb9d561f6ceb 100644 --- a/common/hsm_version.h +++ b/common/hsm_version.h @@ -23,6 +23,6 @@ * v5 with hsmd_revoke_commitment_tx: 5742538f87ef5d5bf55b66dc19e52c8683cfeb1b887d3e64ba530ba9a4d8e638 * v5 with sign_any_cannouncement: 5fdb9068c43a21887dc03f7dce410d2e3eeff6277f0d49b4fc56595a798fd4a4 */ -#define HSM_MIN_VERSION 3 +#define HSM_MIN_VERSION 5 #define HSM_MAX_VERSION 5 #endif /* LIGHTNING_COMMON_HSM_VERSION_H */ diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index 1aec53028500..e3195ffae467 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -436,7 +436,7 @@ static struct io_plan *init_hsm(struct io_conn *conn, struct secret *hsm_encryption_key; struct bip32_key_version bip32_key_version; u32 minversion, maxversion; - const u32 our_minversion = 2, our_maxversion = 3; + const u32 our_minversion = 4, our_maxversion = 5; /* This must be lightningd. */ assert(is_lightningd(c)); @@ -489,7 +489,10 @@ static struct io_plan *init_hsm(struct io_conn *conn, if (hsm_encryption_key) discard_key(take(hsm_encryption_key)); - return req_reply(conn, c, hsmd_init(hsm_secret, bip32_key_version)); + /* Define the minimum common max version for the hsmd one */ + u64 mutual_version = maxversion < our_maxversion ? maxversion : our_maxversion; + return req_reply(conn, c, hsmd_init(hsm_secret, mutual_version, + bip32_key_version)); } /*~ Since we process requests then service them in strict order, and because diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index a6cacdb90e38..0604cbb383d0 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -2151,7 +2151,7 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client, return hsmd_status_bad_request(client, msg, "Unknown request"); } -u8 *hsmd_init(struct secret hsm_secret, +u8 *hsmd_init(struct secret hsm_secret, const u64 hsmd_version, struct bip32_key_version bip32_key_version) { u8 bip32_seed[BIP32_ENTROPY_LEN_256]; @@ -2297,7 +2297,7 @@ u8 *hsmd_init(struct secret hsm_secret, * incompatibility detection) with alternate implementations. */ return take(towire_hsmd_init_reply_v4( - NULL, 4, + NULL, hsmd_version, /* Capabilities arg needs to be a tal array */ tal_dup_arr(tmpctx, u32, capabilities, ARRAY_SIZE(capabilities), 0), diff --git a/hsmd/libhsmd.h b/hsmd/libhsmd.h index 6388193912ac..756c6c2f526a 100644 --- a/hsmd/libhsmd.h +++ b/hsmd/libhsmd.h @@ -47,7 +47,7 @@ struct hsmd_client { * Returns the `hsmd_init_reply` with the information required by * `lightningd`. */ -u8 *hsmd_init(struct secret hsm_secret, +u8 *hsmd_init(struct secret hsm_secret, const u64 hsmd_version, struct bip32_key_version bip32_key_version); struct hsmd_client *hsmd_client_new_main(const tal_t *ctx, u64 capabilities, From e5673a8db64e99227dad2757549ffc380c8b0670 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Tue, 20 Feb 2024 09:44:52 +0100 Subject: [PATCH 2/2] hsmd: remove deprecated init v2 Signed-off-by: Vincenzo Palazzo --- common/hsm_version.h | 1 + hsmd/hsmd.c | 1 - hsmd/hsmd_wire.csv | 6 ------ hsmd/libhsmd.c | 2 -- lightningd/hsm_control.c | 6 ------ wallet/test/run-wallet.c | 3 --- 6 files changed, 1 insertion(+), 18 deletions(-) diff --git a/common/hsm_version.h b/common/hsm_version.h index bb9d561f6ceb..7d3f8fb80da2 100644 --- a/common/hsm_version.h +++ b/common/hsm_version.h @@ -22,6 +22,7 @@ * v4 with forget_channel: d87c6934ea188f92785d38d7cd0b13ed7f76aa7417f3200baf0c7b5aa832fe29 * v5 with hsmd_revoke_commitment_tx: 5742538f87ef5d5bf55b66dc19e52c8683cfeb1b887d3e64ba530ba9a4d8e638 * v5 with sign_any_cannouncement: 5fdb9068c43a21887dc03f7dce410d2e3eeff6277f0d49b4fc56595a798fd4a4 + * v5 drop init v2: 5024454532fe5a78bb7558000cb344190888b9915360d3d56ddca22eaba9b872 */ #define HSM_MIN_VERSION 5 #define HSM_MAX_VERSION 5 diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index e3195ffae467..41150da75984 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -704,7 +704,6 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c) case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY: case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY: case WIRE_HSMD_SIGN_INVOICE_REPLY: - case WIRE_HSMD_INIT_REPLY_V2: case WIRE_HSMD_INIT_REPLY_V4: case WIRE_HSMD_DERIVE_SECRET_REPLY: case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST: diff --git a/hsmd/hsmd_wire.csv b/hsmd/hsmd_wire.csv index 98e3bd021596..cd75835622c3 100644 --- a/hsmd/hsmd_wire.csv +++ b/hsmd/hsmd_wire.csv @@ -19,12 +19,6 @@ msgdata,hsmd_init,hsm_wire_min_version,u32, msgdata,hsmd_init,hsm_wire_max_version,u32, #include -# DEPRECATED after 23.05, remove in two versions! -msgtype,hsmd_init_reply_v2,113 -msgdata,hsmd_init_reply_v2,node_id,node_id, -msgdata,hsmd_init_reply_v2,bip32,ext_key, -msgdata,hsmd_init_reply_v2,bolt12,pubkey, - # Sorry: I should have put version in v2 :( msgtype,hsmd_init_reply_v4,114 # This gets upgraded when the wire protocol changes in incompatible diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index 0604cbb383d0..3dfcf183876a 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -157,7 +157,6 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client, case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY: case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY: case WIRE_HSMD_SIGN_INVOICE_REPLY: - case WIRE_HSMD_INIT_REPLY_V2: case WIRE_HSMD_INIT_REPLY_V4: case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST: case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY: @@ -2124,7 +2123,6 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client, case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY: case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY: case WIRE_HSMD_SIGN_INVOICE_REPLY: - case WIRE_HSMD_INIT_REPLY_V2: case WIRE_HSMD_INIT_REPLY_V4: case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST: case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY: diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c index 0765af142691..1b636bdb6c0d 100644 --- a/lightningd/hsm_control.c +++ b/lightningd/hsm_control.c @@ -130,12 +130,6 @@ struct ext_key *hsm_init(struct lightningd *ld) &ld->id, bip32_base, &ld->bolt12_base)) { /* nothing to do. */ - } else if (fromwire_hsmd_init_reply_v2(msg, - &ld->id, bip32_base, - &ld->bolt12_base)) { - /* implicit version */ - hsm_version = 3; - ld->hsm_capabilities = NULL; } else { if (ld->config.keypass) errx(EXITCODE_HSM_BAD_PASSWORD, "Wrong password for encrypted hsm_secret."); diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index d940d6caa8c8..73c51bd37988 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -306,9 +306,6 @@ bool fromwire_hsmd_forget_channel_reply(const void *p UNNEEDED) /* Generated stub for fromwire_hsmd_get_output_scriptpubkey_reply */ bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **script UNNEEDED) { fprintf(stderr, "fromwire_hsmd_get_output_scriptpubkey_reply called!\n"); abort(); } -/* Generated stub for fromwire_hsmd_init_reply_v2 */ -bool fromwire_hsmd_init_reply_v2(const void *p UNNEEDED, struct node_id *node_id UNNEEDED, struct ext_key *bip32 UNNEEDED, struct pubkey *bolt12 UNNEEDED) -{ fprintf(stderr, "fromwire_hsmd_init_reply_v2 called!\n"); abort(); } /* Generated stub for fromwire_hsmd_init_reply_v4 */ bool fromwire_hsmd_init_reply_v4(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u32 *hsm_version UNNEEDED, u32 **hsm_capabilities UNNEEDED, struct node_id *node_id UNNEEDED, struct ext_key *bip32 UNNEEDED, struct pubkey *bolt12 UNNEEDED) { fprintf(stderr, "fromwire_hsmd_init_reply_v4 called!\n"); abort(); }