mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
hsm: remove unique_id.
It was only for error messages, so replace it with pubkey. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
c3bed51b2d
commit
ffaa15c7da
@@ -34,6 +34,7 @@ HSMD_COMMON_OBJS := \
|
|||||||
common/msg_queue.o \
|
common/msg_queue.o \
|
||||||
common/permute_tx.o \
|
common/permute_tx.o \
|
||||||
common/status.o \
|
common/status.o \
|
||||||
|
common/type_to_string.o \
|
||||||
common/utils.o \
|
common/utils.o \
|
||||||
common/utxo.o \
|
common/utxo.o \
|
||||||
common/version.o \
|
common/version.o \
|
||||||
|
|||||||
28
hsmd/hsm.c
28
hsmd/hsm.c
@@ -18,6 +18,7 @@
|
|||||||
#include <common/funding_tx.h>
|
#include <common/funding_tx.h>
|
||||||
#include <common/io_debug.h>
|
#include <common/io_debug.h>
|
||||||
#include <common/status.h>
|
#include <common/status.h>
|
||||||
|
#include <common/type_to_string.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <common/version.h>
|
#include <common/version.h>
|
||||||
#include <common/withdraw_tx.h>
|
#include <common/withdraw_tx.h>
|
||||||
@@ -47,7 +48,7 @@ struct client {
|
|||||||
struct daemon_conn dc;
|
struct daemon_conn dc;
|
||||||
struct daemon_conn *master;
|
struct daemon_conn *master;
|
||||||
|
|
||||||
u64 id;
|
struct pubkey id;
|
||||||
struct io_plan *(*handle)(struct io_conn *, struct daemon_conn *);
|
struct io_plan *(*handle)(struct io_conn *, struct daemon_conn *);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,13 +75,13 @@ static void node_key(struct privkey *node_privkey, struct pubkey *node_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct client *new_client(struct daemon_conn *master,
|
static struct client *new_client(struct daemon_conn *master,
|
||||||
u64 id,
|
const struct pubkey *id,
|
||||||
struct io_plan *(*handle)(struct io_conn *,
|
struct io_plan *(*handle)(struct io_conn *,
|
||||||
struct daemon_conn *),
|
struct daemon_conn *),
|
||||||
int fd)
|
int fd)
|
||||||
{
|
{
|
||||||
struct client *c = tal(master, struct client);
|
struct client *c = tal(master, struct client);
|
||||||
c->id = id;
|
c->id = *id;
|
||||||
c->handle = handle;
|
c->handle = handle;
|
||||||
c->master = master;
|
c->master = master;
|
||||||
daemon_conn_init(c, &c->dc, fd, handle, NULL);
|
daemon_conn_init(c, &c->dc, fd, handle, NULL);
|
||||||
@@ -102,7 +103,7 @@ static struct io_plan *handle_ecdh(struct io_conn *conn, struct daemon_conn *dc)
|
|||||||
if (!fromwire_hsm_ecdh_req(dc->msg_in, NULL, &point)) {
|
if (!fromwire_hsm_ecdh_req(dc->msg_in, NULL, &point)) {
|
||||||
daemon_conn_send(c->master,
|
daemon_conn_send(c->master,
|
||||||
take(towire_hsmstatus_client_bad_request(c,
|
take(towire_hsmstatus_client_bad_request(c,
|
||||||
c->id,
|
&c->id,
|
||||||
dc->msg_in)));
|
dc->msg_in)));
|
||||||
return io_close(conn);
|
return io_close(conn);
|
||||||
}
|
}
|
||||||
@@ -110,10 +111,11 @@ static struct io_plan *handle_ecdh(struct io_conn *conn, struct daemon_conn *dc)
|
|||||||
node_key(&privkey, NULL);
|
node_key(&privkey, NULL);
|
||||||
if (secp256k1_ecdh(secp256k1_ctx, ss.data, &point.pubkey,
|
if (secp256k1_ecdh(secp256k1_ctx, ss.data, &point.pubkey,
|
||||||
privkey.secret.data) != 1) {
|
privkey.secret.data) != 1) {
|
||||||
status_trace("secp256k1_ecdh fail for client %"PRIu64, c->id);
|
status_trace("secp256k1_ecdh fail for client %s",
|
||||||
|
type_to_string(trc, struct pubkey, &c->id));
|
||||||
daemon_conn_send(c->master,
|
daemon_conn_send(c->master,
|
||||||
take(towire_hsmstatus_client_bad_request(c,
|
take(towire_hsmstatus_client_bad_request(c,
|
||||||
c->id,
|
&c->id,
|
||||||
dc->msg_in)));
|
dc->msg_in)));
|
||||||
return io_close(conn);
|
return io_close(conn);
|
||||||
}
|
}
|
||||||
@@ -235,7 +237,7 @@ static struct io_plan *handle_channeld(struct io_conn *conn,
|
|||||||
|
|
||||||
daemon_conn_send(c->master,
|
daemon_conn_send(c->master,
|
||||||
take(towire_hsmstatus_client_bad_request(c,
|
take(towire_hsmstatus_client_bad_request(c,
|
||||||
c->id,
|
&c->id,
|
||||||
dc->msg_in)));
|
dc->msg_in)));
|
||||||
return io_close(conn);
|
return io_close(conn);
|
||||||
}
|
}
|
||||||
@@ -415,16 +417,18 @@ static void init_hsm(struct daemon_conn *master, const u8 *msg)
|
|||||||
static void pass_hsmfd_ecdh(struct daemon_conn *master, const u8 *msg)
|
static void pass_hsmfd_ecdh(struct daemon_conn *master, const u8 *msg)
|
||||||
{
|
{
|
||||||
int fds[2];
|
int fds[2];
|
||||||
u64 id;
|
struct pubkey id;
|
||||||
|
|
||||||
if (!fromwire_hsmctl_hsmfd_ecdh(msg, NULL, &id))
|
if (!fromwire_hsmctl_hsmfd_ecdh(msg, NULL))
|
||||||
master_badmsg(WIRE_HSMCTL_HSMFD_ECDH, msg);
|
master_badmsg(WIRE_HSMCTL_HSMFD_ECDH, msg);
|
||||||
|
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0)
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0)
|
||||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
"creating fds: %s", strerror(errno));
|
"creating fds: %s", strerror(errno));
|
||||||
|
|
||||||
new_client(master, id, handle_ecdh, fds[0]);
|
/* This is gossipd, so we use our own id */
|
||||||
|
node_key(NULL, &id);
|
||||||
|
new_client(master, &id, handle_ecdh, fds[0]);
|
||||||
daemon_conn_send(master,
|
daemon_conn_send(master,
|
||||||
take(towire_hsmctl_hsmfd_ecdh_fd_reply(master)));
|
take(towire_hsmctl_hsmfd_ecdh_fd_reply(master)));
|
||||||
daemon_conn_send_fd(master, fds[1]);
|
daemon_conn_send_fd(master, fds[1]);
|
||||||
@@ -434,7 +438,7 @@ static void pass_hsmfd_ecdh(struct daemon_conn *master, const u8 *msg)
|
|||||||
static void pass_hsmfd_channeld(struct daemon_conn *master, const u8 *msg)
|
static void pass_hsmfd_channeld(struct daemon_conn *master, const u8 *msg)
|
||||||
{
|
{
|
||||||
int fds[2];
|
int fds[2];
|
||||||
u64 id;
|
struct pubkey id;
|
||||||
|
|
||||||
if (!fromwire_hsmctl_hsmfd_channeld(msg, NULL, &id))
|
if (!fromwire_hsmctl_hsmfd_channeld(msg, NULL, &id))
|
||||||
master_badmsg(WIRE_HSMCTL_HSMFD_CHANNELD, msg);
|
master_badmsg(WIRE_HSMCTL_HSMFD_CHANNELD, msg);
|
||||||
@@ -443,7 +447,7 @@ static void pass_hsmfd_channeld(struct daemon_conn *master, const u8 *msg)
|
|||||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
"creating fds: %s", strerror(errno));
|
"creating fds: %s", strerror(errno));
|
||||||
|
|
||||||
new_client(master, id, handle_channeld, fds[0]);
|
new_client(master, &id, handle_channeld, fds[0]);
|
||||||
daemon_conn_send(master,
|
daemon_conn_send(master,
|
||||||
take(towire_hsmctl_hsmfd_channeld_reply(master)));
|
take(towire_hsmctl_hsmfd_channeld_reply(master)));
|
||||||
daemon_conn_send_fd(master, fds[1]);
|
daemon_conn_send_fd(master, fds[1]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Clients should not give a bad request but not the HSM's decision to crash.
|
# Clients should not give a bad request but not the HSM's decision to crash.
|
||||||
hsmstatus_client_bad_request,1000
|
hsmstatus_client_bad_request,1000
|
||||||
hsmstatus_client_bad_request,,unique_id,u64
|
hsmstatus_client_bad_request,,id,struct pubkey
|
||||||
hsmstatus_client_bad_request,,len,u16
|
hsmstatus_client_bad_request,,len,u16
|
||||||
hsmstatus_client_bad_request,,msg,len*u8
|
hsmstatus_client_bad_request,,msg,len*u8
|
||||||
|
|
||||||
@@ -14,9 +14,8 @@ hsmctl_init_reply,,node_id,struct pubkey
|
|||||||
hsmctl_init_reply,,peer_seed,struct secret
|
hsmctl_init_reply,,peer_seed,struct secret
|
||||||
hsmctl_init_reply,,bip32,struct ext_key
|
hsmctl_init_reply,,bip32,struct ext_key
|
||||||
|
|
||||||
# ECDH returns an fd.
|
# ECDH returns an fd (for gossipd to do handshake)
|
||||||
hsmctl_hsmfd_ecdh,3
|
hsmctl_hsmfd_ecdh,3
|
||||||
hsmctl_hsmfd_ecdh,,unique_id,u64
|
|
||||||
|
|
||||||
# No contents, just an fd.
|
# No contents, just an fd.
|
||||||
hsmctl_hsmfd_ecdh_fd_reply,103
|
hsmctl_hsmfd_ecdh_fd_reply,103
|
||||||
@@ -39,7 +38,7 @@ hsmctl_sign_funding_reply,,sig,num_sigs*secp256k1_ecdsa_signature
|
|||||||
|
|
||||||
# Request a client socket for a `channeld`, allows signing announcements
|
# Request a client socket for a `channeld`, allows signing announcements
|
||||||
hsmctl_hsmfd_channeld,5
|
hsmctl_hsmfd_channeld,5
|
||||||
hsmctl_hsmfd_channeld,,unique_id,u64
|
hsmctl_hsmfd_channeld,,id,struct pubkey
|
||||||
|
|
||||||
# Empty reply, just an fd
|
# Empty reply, just an fd
|
||||||
hsmctl_hsmfd_channeld_reply,105
|
hsmctl_hsmfd_channeld_reply,105
|
||||||
|
|||||||
|
@@ -97,7 +97,7 @@ void gossip_init(struct lightningd *ld)
|
|||||||
u8 *msg;
|
u8 *msg;
|
||||||
int hsmfd;
|
int hsmfd;
|
||||||
|
|
||||||
msg = towire_hsmctl_hsmfd_ecdh(tmpctx, 0);
|
msg = towire_hsmctl_hsmfd_ecdh(tmpctx);
|
||||||
if (!wire_sync_write(ld->hsm_fd, msg))
|
if (!wire_sync_write(ld->hsm_fd, msg))
|
||||||
fatal("Could not write to HSM: %s", strerror(errno));
|
fatal("Could not write to HSM: %s", strerror(errno));
|
||||||
|
|
||||||
|
|||||||
@@ -2021,7 +2021,7 @@ static bool peer_start_channeld(struct peer *peer,
|
|||||||
} else
|
} else
|
||||||
assert(peer->our_msatoshi);
|
assert(peer->our_msatoshi);
|
||||||
|
|
||||||
msg = towire_hsmctl_hsmfd_channeld(tmpctx, peer->unique_id);
|
msg = towire_hsmctl_hsmfd_channeld(tmpctx, &peer->id);
|
||||||
if (!wire_sync_write(peer->ld->hsm_fd, take(msg)))
|
if (!wire_sync_write(peer->ld->hsm_fd, take(msg)))
|
||||||
fatal("Could not write to HSM: %s", strerror(errno));
|
fatal("Could not write to HSM: %s", strerror(errno));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user