Skip to content

Commit b5ced70

Browse files
committed
Added missing SignMessage API call.
1 parent 5ed5f6c commit b5ced70

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

contrib/remote_hsmd/TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ API Coverage
44

55
## Failing Tests
66

7+
# intermittent
78
tests/test_connection.py::test_restart_many_payments
8-
tests/test_misc.py::test_signmessage
99

1010

1111
#### proxy and server done
@@ -32,11 +32,11 @@ tests/test_misc.py::test_signmessage
3232
WIRE_HSM_SIGN_LOCAL_HTLC_TX
3333
WIRE_HSM_SIGN_REMOTE_HTLC_TO_US
3434
handle_check_future_secret
35+
handle_sign_message
3536

3637
#### need proxy and server
3738

3839
handle_sign_funding_tx
39-
handle_sign_message
4040

4141
Improvements
4242
----------------------------------------------------------------

contrib/remote_hsmd/hsmd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,19 @@ static struct io_plan *handle_sign_message(struct io_conn *conn,
21672167
if (!fromwire_hsm_sign_message(tmpctx, msg_in, &msg))
21682168
return bad_req(conn, c, msg_in);
21692169

2170+
proxy_stat rv = proxy_handle_sign_message(msg, &rsig);
2171+
if (PROXY_PERMANENT(rv))
2172+
status_failed(STATUS_FAIL_INTERNAL_ERROR,
2173+
"proxy_%s failed: %s", __FUNCTION__,
2174+
proxy_last_message());
2175+
else if (!PROXY_SUCCESS(rv))
2176+
return bad_req_fmt(conn, c, msg_in,
2177+
"proxy_%s error: %s", __FUNCTION__,
2178+
proxy_last_message());
2179+
g_proxy_impl = PROXY_IMPL_MARSHALED;
2180+
2181+
/* FIXME - USE THE PROXIED VALUE WHEN SERVER SUPPORTS */
2182+
21702183
/* Prefixing by a known string means we'll never be convinced
21712184
* to sign some gossip message, etc. */
21722185
sha256_update(&sctx, "Lightning Signed Message:",

contrib/remote_hsmd/proxy.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,48 @@ proxy_stat proxy_handle_sign_invoice(
651651
}
652652
}
653653

654+
proxy_stat proxy_handle_sign_message(
655+
u8 *msg,
656+
secp256k1_ecdsa_recoverable_signature *o_sig)
657+
{
658+
status_debug(
659+
"%s:%d %s self_id=%s msg=%s",
660+
__FILE__, __LINE__, __FUNCTION__,
661+
dump_node_id(&self_id).c_str(),
662+
dump_hex(msg, tal_count(msg)).c_str()
663+
);
664+
665+
last_message = "";
666+
SignMessageRequest req;
667+
req.set_message(msg, tal_count(msg));
668+
669+
ClientContext context;
670+
SignMessageReply rsp;
671+
Status status = stub->SignMessage(&context, req, &rsp);
672+
if (status.ok()) {
673+
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
674+
#if 0
675+
output_ecdsa_recoverable_signature(rsp.signature(), o_sig);
676+
#else
677+
memset(o_sig, '\0', sizeof(*o_sig));
678+
#endif
679+
status_debug("%s:%d %s self_id=%s sig=%s",
680+
__FILE__, __LINE__, __FUNCTION__,
681+
dump_node_id(&self_id).c_str(),
682+
dump_secp256k1_ecdsa_recoverable_signature(
683+
o_sig).c_str());
684+
last_message = "success";
685+
return PROXY_OK;
686+
} else {
687+
status_unusual("%s:%d %s: self_id=%s %s",
688+
__FILE__, __LINE__, __FUNCTION__,
689+
dump_node_id(&self_id).c_str(),
690+
status.error_message().c_str());
691+
last_message = status.error_message();
692+
return map_status(status);
693+
}
694+
}
695+
654696
proxy_stat proxy_handle_channel_update_sig(
655697
struct bitcoin_blkid *chain_hash,
656698
struct short_channel_id *scid,

contrib/remote_hsmd/proxy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ proxy_stat proxy_handle_sign_invoice(
8080
u8 *hrpu8,
8181
secp256k1_ecdsa_recoverable_signature *o_sig);
8282

83+
proxy_stat proxy_handle_sign_message(
84+
u8 *msg,
85+
secp256k1_ecdsa_recoverable_signature *o_sig);
86+
8387
proxy_stat proxy_handle_channel_update_sig(
8488
struct bitcoin_blkid *chain_hash,
8589
struct short_channel_id *scid,

0 commit comments

Comments
 (0)