Skip to content

Commit df5fd66

Browse files
committed
Added proxy_handle_sign_invoice and proxy_handle_sign_remote_htlc_tx.
1 parent 0f6cd0f commit df5fd66

File tree

4 files changed

+14
-96
lines changed

4 files changed

+14
-96
lines changed

contrib/remote_hsmd/NOTES.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ VALGRIND=0 \
3131
SLOW_MACHINE=1 \
3232
SUBDAEMON='hsmd:remote_hsmd' \
3333
pytest \
34-
tests/test_connection.py::test_balance \
34+
$THETEST \
3535
-v --timeout=550 --timeout_method=thread -x -s \
3636
|& tee log
3737
```
3838

39+
Some popular tests:
40+
41+
export THETEST=tests/test_connection.py::test_balance
42+
export THETEST=tests/test_pay.py::test_sendpay
43+
export THETEST=tests/test_pay.py::test_pay
44+
45+
3946
Tests remote_commitment:
4047

41-
tests/test_pay.py::test_sendpay
4248

4349
rust-lightning-signer
4450
----------------------------------------------------------------

contrib/remote_hsmd/TODO.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ API Coverage
66

77
# intermittent
88
tests/test_connection.py::test_funding_cancel_race
9+
tests/test_misc.py::test_bad_onion_immediate_peer
910

1011
## Proxy Scoreboard
1112

@@ -14,19 +15,19 @@ COMPLETE proxy_stat proxy_handle_pass_client_hsmfd
1415
COMPLETE proxy_stat proxy_handle_sign_remote_commitment_tx
1516
COMPLETE proxy_stat proxy_handle_channel_update_sig
1617
COMPLETE proxy_stat proxy_handle_sign_node_announcement
18+
COMPLETE proxy_stat proxy_handle_sign_remote_htlc_tx
19+
COMPLETE proxy_stat proxy_handle_sign_invoice
1720

1821
PARTIAL (-P2SH) proxy_stat proxy_handle_sign_withdrawal_tx
1922

2023
MARSHALED proxy_stat proxy_init_hsm
2124
MARSHALED proxy_stat proxy_handle_get_per_commitment_point
22-
MARSHALED proxy_stat proxy_handle_sign_invoice
2325
MARSHALED proxy_stat proxy_handle_sign_message
2426
MARSHALED proxy_stat proxy_handle_get_channel_basepoints
2527
MARSHALED proxy_stat proxy_handle_sign_mutual_close_tx
2628
MARSHALED proxy_stat proxy_handle_sign_commitment_tx
2729
MARSHALED proxy_stat proxy_handle_cannouncement_sig
2830
MARSHALED proxy_stat proxy_handle_sign_local_htlc_tx
29-
MARSHALED proxy_stat proxy_handle_sign_remote_htlc_tx
3031
MARSHALED proxy_stat proxy_handle_sign_delayed_payment_to_us
3132
MARSHALED proxy_stat proxy_handle_sign_remote_htlc_to_us
3233
MARSHALED proxy_stat proxy_handle_sign_penalty_to_us

contrib/remote_hsmd/hsmd.c

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,16 +1148,11 @@ static struct io_plan *handle_sign_remote_htlc_tx(struct io_conn *conn,
11481148
struct client *c,
11491149
const u8 *msg_in)
11501150
{
1151-
struct secret channel_seed;
11521151
struct bitcoin_tx *tx;
11531152
struct bitcoin_signature sig;
1154-
struct secrets secrets;
1155-
struct basepoints basepoints;
11561153
struct pubkey remote_per_commit_point;
11571154
struct amount_sat amount;
11581155
u8 *wscript;
1159-
struct privkey htlc_privkey;
1160-
struct pubkey htlc_pubkey;
11611156

11621157
if (!fromwire_hsm_sign_remote_htlc_tx(tmpctx, msg_in,
11631158
&tx, &wscript, &amount,
@@ -1185,39 +1180,7 @@ static struct io_plan *handle_sign_remote_htlc_tx(struct io_conn *conn,
11851180
return bad_req_fmt(conn, c, msg_in,
11861181
"proxy_%s error: %s", __FUNCTION__,
11871182
proxy_last_message());
1188-
g_proxy_impl = PROXY_IMPL_MARSHALED;
1189-
1190-
/* FIXME - server-side not implemented yet. Use original code
1191-
* below for now */
1192-
1193-
/*
1194-
assert(tal_count(sigs) == 1);
1195-
1196-
bool ok = signature_from_der(sigs[0][0], tal_count(sigs[0][0]), &sig);
1197-
assert(ok);
1198-
status_debug("%s:%d %s: signature: %s",
1199-
__FILE__, __LINE__, __FUNCTION__,
1200-
type_to_string(tmpctx, struct bitcoin_signature, &sig));
1201-
*/
1202-
1203-
get_channel_seed(&c->id, c->dbid, &channel_seed);
1204-
derive_basepoints(&channel_seed, NULL, &basepoints, &secrets, NULL);
1205-
1206-
if (!derive_simple_privkey(&secrets.htlc_basepoint_secret,
1207-
&basepoints.htlc,
1208-
&remote_per_commit_point,
1209-
&htlc_privkey))
1210-
return bad_req_fmt(conn, c, msg_in,
1211-
"Failed deriving htlc privkey");
1212-
1213-
if (!derive_simple_key(&basepoints.htlc,
1214-
&remote_per_commit_point,
1215-
&htlc_pubkey))
1216-
return bad_req_fmt(conn, c, msg_in,
1217-
"Failed deriving htlc pubkey");
1218-
1219-
sign_tx_input(tx, 0, NULL, wscript, &htlc_privkey, &htlc_pubkey,
1220-
SIGHASH_ALL, &sig);
1183+
g_proxy_impl = PROXY_IMPL_COMPLETE;
12211184

12221185
return req_reply(conn, c, take(towire_hsm_sign_tx_reply(NULL, &sig)));
12231186
}
@@ -2011,11 +1974,7 @@ static struct io_plan *handle_sign_invoice(struct io_conn *conn,
20111974
* entirely transparent to the C compiler. */
20121975
u5 *u5bytes;
20131976
u8 *hrpu8;
2014-
char *hrp;
2015-
struct sha256 sha;
20161977
secp256k1_ecdsa_recoverable_signature rsig;
2017-
struct hash_u5 hu5;
2018-
struct privkey node_pkey;
20191978

20201979
if (!fromwire_hsm_sign_invoice(tmpctx, msg_in, &u5bytes, &hrpu8))
20211980
return bad_req(conn, c, msg_in);
@@ -2029,46 +1988,7 @@ static struct io_plan *handle_sign_invoice(struct io_conn *conn,
20291988
return bad_req_fmt(conn, c, msg_in,
20301989
"proxy_%s error: %s", __FUNCTION__,
20311990
proxy_last_message());
2032-
g_proxy_impl = PROXY_IMPL_MARSHALED;
2033-
2034-
/* FIXME - USE THE PROXIED VALUE WHEN SERVER SUPPORTS */
2035-
2036-
/* BOLT #11:
2037-
*
2038-
* A writer... MUST set `signature` to a valid 512-bit
2039-
* secp256k1 signature of the SHA2 256-bit hash of the
2040-
* human-readable part, represented as UTF-8 bytes,
2041-
* concatenated with the data part (excluding the signature)
2042-
* with 0 bits appended to pad the data to the next byte
2043-
* boundary, with a trailing byte containing the recovery ID
2044-
* (0, 1, 2, or 3).
2045-
*/
2046-
2047-
/* FIXME: Check invoice! */
2048-
2049-
/*~ tal_dup_arr() does what you'd expect: allocate an array by copying
2050-
* another; the cast is needed because the hrp is a 'char' array, not
2051-
* a 'u8' (unsigned char) as it's the "human readable" part.
2052-
*
2053-
* The final arg of tal_dup_arr() is how many extra bytes to allocate:
2054-
* it's so often zero that I've thought about dropping the argument, but
2055-
* in cases like this (adding a NUL terminator) it's perfect. */
2056-
hrp = tal_dup_arr(tmpctx, char, (char *)hrpu8, tal_count(hrpu8), 1);
2057-
hrp[tal_count(hrpu8)] = '\0';
2058-
2059-
hash_u5_init(&hu5, hrp);
2060-
hash_u5(&hu5, u5bytes, tal_count(u5bytes));
2061-
hash_u5_done(&hu5, &sha);
2062-
2063-
node_key(&node_pkey, NULL);
2064-
/*~ By no small coincidence, this libsecp routine uses the exact
2065-
* recovery signature format mandated by BOLT 11. */
2066-
if (!secp256k1_ecdsa_sign_recoverable(secp256k1_ctx, &rsig,
2067-
(const u8 *)&sha,
2068-
node_pkey.secret.data,
2069-
NULL, NULL)) {
2070-
return bad_req_fmt(conn, c, msg_in, "Failed to sign invoice");
2071-
}
1991+
g_proxy_impl = PROXY_IMPL_COMPLETE;
20721992

20731993
return req_reply(conn, c,
20741994
take(towire_hsm_sign_invoice_reply(NULL, &rsig)));

contrib/remote_hsmd/proxy.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -608,19 +608,15 @@ proxy_stat proxy_handle_sign_invoice(
608608

609609
last_message = "";
610610
SignInvoiceRequest req;
611+
marshal_node_id(&self_id, req.mutable_node_id());
611612
req.set_data_part(u5bytes, tal_count(u5bytes));
612613
req.set_human_readable_part((const char *)hrpu8, tal_count(hrpu8));
613614

614615
ClientContext context;
615616
RecoverableNodeSignatureReply rsp;
616617
Status status = stub->SignInvoice(&context, req, &rsp);
617618
if (status.ok()) {
618-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
619-
#if 0
620619
unmarshal_ecdsa_recoverable_signature(rsp.signature(), o_sig);
621-
#else
622-
memset(o_sig, '\0', sizeof(*o_sig));
623-
#endif
624620
status_debug("%s:%d %s self_id=%s sig=%s",
625621
__FILE__, __LINE__, __FUNCTION__,
626622
dump_node_id(&self_id).c_str(),
@@ -1043,12 +1039,7 @@ proxy_stat proxy_handle_sign_remote_htlc_tx(
10431039
SignatureReply rsp;
10441040
Status status = stub->SignRemoteHTLCTx(&context, req, &rsp);
10451041
if (status.ok()) {
1046-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
1047-
#if 0
10481042
unmarshal_bitcoin_signature(rsp.signature(), o_sig);
1049-
#else
1050-
memset(o_sig, '\0', sizeof(*o_sig));
1051-
#endif
10521043
status_debug("%s:%d %s self_id=%s sig=%s",
10531044
__FILE__, __LINE__, __FUNCTION__,
10541045
dump_node_id(&self_id).c_str(),

0 commit comments

Comments
 (0)