Skip to content

Commit a2e31af

Browse files
committed
Implemented sign-node-announcement.
1 parent 1affe42 commit a2e31af

File tree

3 files changed

+48
-71
lines changed

3 files changed

+48
-71
lines changed

contrib/remote_hsmd/TODO.md

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,33 @@ API Coverage
55
## Failing Tests
66

77
# intermittent
8-
tests/test_connection.py::test_restart_many_payments
9-
10-
11-
#### proxy and server done
12-
13-
1 hsm_ecdh_req ECDH
14-
7 hsm_sign_withdrawal SignWithdrawalTx
15-
9 hsm_client_hsmfd PassClientHSMFd
16-
11 hsm_init InitHSM
17-
19 hsm_sign_remote_commitment_tx SignRemoteCommitmentTx
18-
19-
#### proxy done, but server not complete
20-
21-
3 hsm_cupdate_sig_req ChannelUpdateSig
22-
8 hsm_sign_invoice SignInvoice
23-
10 hsm_get_channel_basepoints GetChannelBasepoints
24-
18 hsm_get_per_commitment_point GetPerCommitmentPoint
25-
20 hsm_sign_remote_htlc_tx SignRemoteHTLCTx
26-
HSM_SIGN_MUTUAL_CLOSE_TX SignMutualCloseTx
27-
HSM_SIGN_COMMITMENT_TX SignCommitmentTx
28-
WIRE_HSM_CANNOUNCEMENT_SIG_REQ
29-
WIRE_HSM_NODE_ANNOUNCEMENT_SIG_REQ
30-
WIRE_HSM_SIGN_PENALTY_TO_US
31-
WIRE_HSM_SIGN_DELAYED_PAYMENT_TO_US
32-
WIRE_HSM_SIGN_LOCAL_HTLC_TX
33-
WIRE_HSM_SIGN_REMOTE_HTLC_TO_US
34-
handle_check_future_secret
35-
handle_sign_message
36-
37-
#### need proxy and server
38-
39-
handle_sign_funding_tx
8+
tests/test_connection.py::test_funding_cancel_race
9+
10+
## Proxy Scoreboard
11+
12+
COMPLETE proxy_stat proxy_handle_ecdh
13+
COMPLETE proxy_stat proxy_handle_pass_client_hsmfd
14+
COMPLETE proxy_stat proxy_handle_sign_remote_commitment_tx
15+
COMPLETE proxy_stat proxy_handle_channel_update_sig
16+
COMPLETE proxy_stat proxy_handle_sign_node_announcement
17+
18+
PARTIAL (-P2SH) proxy_stat proxy_handle_sign_withdrawal_tx
19+
20+
MARSHALED proxy_stat proxy_init_hsm
21+
MARSHALED proxy_stat proxy_handle_get_per_commitment_point
22+
MARSHALED proxy_stat proxy_handle_sign_invoice
23+
MARSHALED proxy_stat proxy_handle_sign_message
24+
MARSHALED proxy_stat proxy_handle_get_channel_basepoints
25+
MARSHALED proxy_stat proxy_handle_sign_mutual_close_tx
26+
MARSHALED proxy_stat proxy_handle_sign_commitment_tx
27+
MARSHALED proxy_stat proxy_handle_cannouncement_sig
28+
MARSHALED proxy_stat proxy_handle_sign_local_htlc_tx
29+
MARSHALED proxy_stat proxy_handle_sign_remote_htlc_tx
30+
MARSHALED proxy_stat proxy_handle_sign_delayed_payment_to_us
31+
MARSHALED proxy_stat proxy_handle_sign_remote_htlc_to_us
32+
MARSHALED proxy_stat proxy_handle_sign_penalty_to_us
33+
MARSHALED proxy_stat proxy_handle_check_future_secret
34+
4035

4136
Improvements
4237
----------------------------------------------------------------

contrib/remote_hsmd/hsmd.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ enum proxy_impl {
9090
static int g_proxy_impl;
9191
static enum hsm_wire_type g_proxy_last;
9292

93+
/* FIXME - REMOVE THIS WHEN NO LONGER NEEDED */
94+
#if 0
95+
static void print_hex(char const *tag, void const *vptr, size_t sz)
96+
{
97+
fprintf(stderr, "%s: ", tag);
98+
uint8_t const *ptr = (uint8_t const *) vptr;
99+
for (size_t ii = 0; ii < sz; ++ii) {
100+
fprintf(stderr, "%02x", (int) ptr[ii]);
101+
}
102+
fprintf(stderr, "\n");
103+
}
104+
#endif
105+
93106
/*~ We keep track of clients, but there's not much to keep. */
94107
struct client {
95108
/* The ccan/io async io connection for this client: it closes, we die. */
@@ -1076,12 +1089,10 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
10761089
struct client *c,
10771090
const u8 *msg_in)
10781091
{
1079-
struct pubkey remote_funding_pubkey, local_funding_pubkey;
1092+
struct pubkey remote_funding_pubkey;
10801093
struct amount_sat funding;
1081-
struct secret channel_seed;
10821094
struct bitcoin_tx *tx;
10831095
struct bitcoin_signature sig;
1084-
struct secrets secrets;
10851096
struct witscript **output_witscripts;
10861097
struct pubkey remote_per_commit;
10871098
bool option_static_remotekey;
@@ -1104,24 +1115,9 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
11041115
if (tal_count(output_witscripts) != tx->wtx->num_outputs)
11051116
return bad_req_fmt(conn, c, msg_in, "tx must have matching witscripts");
11061117

1107-
/* FIXME - WE DON'T NEED THESE ANYMORE, RIGHT? */
1108-
get_channel_seed(&c->id, c->dbid, &channel_seed);
1109-
derive_basepoints(&channel_seed,
1110-
&local_funding_pubkey, NULL, &secrets, NULL);
1111-
11121118
/* Need input amount for signing */
11131119
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
11141120

1115-
/*
1116-
funding_wscript = bitcoin_redeem_2of2(tmpctx,
1117-
&local_funding_pubkey,
1118-
&remote_funding_pubkey);
1119-
sign_tx_input(tx, 0, NULL, funding_wscript,
1120-
&secrets.funding_privkey,
1121-
&local_funding_pubkey,
1122-
SIGHASH_ALL,
1123-
&sig);
1124-
*/
11251121
proxy_stat rv = proxy_handle_sign_remote_commitment_tx(
11261122
tx, &remote_funding_pubkey, &funding,
11271123
&c->id, c->dbid,
@@ -1628,7 +1624,7 @@ static struct io_plan *handle_check_future_secret(struct io_conn *conn,
16281624
return bad_req_fmt(conn, c, msg_in,
16291625
"proxy_%s error: %s", __FUNCTION__,
16301626
proxy_last_message());
1631-
g_proxy_impl = PROXY_IMPL_COMPLETE;
1627+
g_proxy_impl = PROXY_IMPL_MARSHALED;
16321628

16331629
/* FIXME - REPLACE BELOW W/ REMOTE RETURN */
16341630

@@ -2095,8 +2091,6 @@ static struct io_plan *handle_sign_node_announcement(struct io_conn *conn,
20952091
*/
20962092
/* 2 bytes msg type + 64 bytes signature */
20972093
size_t offset = 66;
2098-
struct sha256_double hash;
2099-
struct privkey node_pkey;
21002094
secp256k1_ecdsa_signature sig;
21012095
u8 *reply;
21022096
u8 *ann;
@@ -2121,14 +2115,7 @@ static struct io_plan *handle_sign_node_announcement(struct io_conn *conn,
21212115
return bad_req_fmt(conn, c, msg_in,
21222116
"proxy_%s error: %s", __FUNCTION__,
21232117
proxy_last_message());
2124-
g_proxy_impl = PROXY_IMPL_MARSHALED;
2125-
2126-
/* FIXME - REPLACE BELOW W/ REMOTE RETURN */
2127-
2128-
node_key(&node_pkey, NULL);
2129-
sha256_double(&hash, ann + offset, tal_count(ann) - offset);
2130-
2131-
sign_hash(&node_pkey, &hash, &sig);
2118+
g_proxy_impl = PROXY_IMPL_COMPLETE;
21322119

21332120
reply = towire_hsm_node_announcement_sig_reply(NULL, &sig);
21342121
return req_reply(conn, c, take(reply));

contrib/remote_hsmd/proxy.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,12 @@ proxy_stat proxy_handle_channel_update_sig(
674674

675675
/* Skip the portion of the channel_update that we don't sign */
676676
size_t offset = 2 + 64; /* sizeof(type) + sizeof(signature) */
677-
size_t cusz = tal_count(channel_update);
677+
size_t annsz = tal_count(channel_update);
678678

679679
last_message = "";
680680
SignChannelUpdateRequest req;
681681
marshal_node_id(&self_id, req.mutable_node_id());
682-
req.set_channel_update(channel_update + offset, cusz - offset);
682+
req.set_channel_update(channel_update + offset, annsz - offset);
683683

684684
ClientContext context;
685685
SignChannelUpdateReply rsp;
@@ -1274,24 +1274,19 @@ proxy_stat proxy_handle_sign_node_announcement(
12741274

12751275
/* Skip the portion of the channel_update that we don't sign */
12761276
size_t offset = 2 + 64; /* sizeof(type) + sizeof(signature) */
1277-
size_t cusz = tal_count(node_announcement);
1277+
size_t annsz = tal_count(node_announcement);
12781278

12791279
last_message = "";
12801280
SignNodeAnnouncementRequest req;
12811281
marshal_node_id(&self_id, req.mutable_node_id());
1282-
req.set_node_announcement(node_announcement + offset, cusz - offset);
1282+
req.set_node_announcement(node_announcement + offset, annsz - offset);
12831283

12841284
ClientContext context;
12851285
SignNodeAnnouncementReply rsp;
12861286
Status status = stub->SignNodeAnnouncement(&context, req, &rsp);
12871287
if (status.ok()) {
1288-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
1289-
#if 0
12901288
unmarshal_ecdsa_signature(rsp.signature(), o_sig);
1291-
#else
1292-
memset(o_sig->data, '\0', sizeof(o_sig->data));
1293-
#endif
1294-
status_debug("%s:%d %s self_id=%s node_sig=%s bitcoin_sig=%s",
1289+
status_debug("%s:%d %s self_id=%s sig=%s",
12951290
__FILE__, __LINE__, __FUNCTION__,
12961291
dump_node_id(&self_id).c_str(),
12971292
dump_secp256k1_ecdsa_signature(o_sig).c_str());

0 commit comments

Comments
 (0)