Skip to content

Commit 25e6780

Browse files
authored
Validate counterparty revocation (#29)
* set the rsignerd logging level to DEBUG * implemented hsmd validate_counterparty_revocation * added rerun-failed-tests
1 parent ec3a696 commit 25e6780

File tree

16 files changed

+219
-4
lines changed

16 files changed

+219
-4
lines changed

channeld/channeld.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,15 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
17321732
"Unexpected revoke_and_ack");
17331733
}
17341734

1735+
const u8 *msg2 = towire_hsmd_validate_revocation(tmpctx,
1736+
peer->next_index[REMOTE] - 2,
1737+
&old_commit_secret);
1738+
msg2 = hsm_req(tmpctx, take(msg2));
1739+
if (!fromwire_hsmd_validate_revocation_reply(msg2))
1740+
status_failed(STATUS_FAIL_HSM_IO,
1741+
"Bad hsm_validate_revocation_reply: %s",
1742+
tal_hex(tmpctx, msg));
1743+
17351744
/* BOLT #2:
17361745
*
17371746
* A receiving node:

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ def __init__(self, rsignerd_dir, rsignerd_port):
519519
TailableProc.__init__(self, rsignerd_dir)
520520
self.executable = env("REMOTE_SIGNER_CMD", 'rsignerd')
521521
self.opts = [
522+
'--log-level-console=DEBUG',
523+
'--log-level-disk=TRACE',
522524
'--datadir={}'.format(rsignerd_dir),
523525
'--port={}'.format(rsignerd_port),
524526
]

contrib/remote_hsmd/NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Run all of the integration tests:
3232
Run a single test:
3333

3434
./contrib/remote_hsmd/scripts/run-one-test $THETEST |& tee log
35+
36+
Re-run failures from prior run:
37+
38+
./contrib/remote_hsmd/scripts/rerun-failed-tests < log |& tee log2
3539

3640
Some popular tests:
3741

contrib/remote_hsmd/hsmd.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,34 @@ static struct io_plan *handle_validate_commitment_tx(struct io_conn *conn,
848848
NULL, old_secret, &next_per_commitment_point)));
849849
}
850850

851+
/* Validate the peer's signatures for our commitment and htlc txs. */
852+
static struct io_plan *handle_validate_revocation(struct io_conn *conn,
853+
struct client *c,
854+
const u8 *msg_in)
855+
{
856+
u64 revoke_num;
857+
struct secret old_secret;
858+
859+
if (!fromwire_hsmd_validate_revocation(msg_in,
860+
&revoke_num, &old_secret))
861+
bad_req(conn, c, msg_in);
862+
863+
proxy_stat rv = proxy_handle_validate_revocation(
864+
&c->id, c->dbid,
865+
revoke_num, &old_secret);
866+
if (PROXY_PERMANENT(rv))
867+
status_failed(STATUS_FAIL_INTERNAL_ERROR,
868+
"proxy_%s failed: %s", __FUNCTION__,
869+
proxy_last_message());
870+
else if (!PROXY_SUCCESS(rv))
871+
return bad_req_fmt(conn, c, msg_in,
872+
"proxy_%s error: %s", __FUNCTION__,
873+
proxy_last_message());
874+
875+
return req_reply(conn, c,
876+
take(towire_hsmd_validate_revocation_reply(NULL)));
877+
}
878+
851879
/*~ This is used by channeld to create signatures for the remote peer's
852880
* commitment transaction. It's functionally identical to signing our own,
853881
* but we expect to do this repeatedly as commitment transactions are
@@ -1636,6 +1664,7 @@ static bool check_client_capabilities(struct client *client,
16361664
case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:
16371665
case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:
16381666
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
1667+
case WIRE_HSMD_VALIDATE_REVOCATION:
16391668
return (client->capabilities & HSM_CAP_SIGN_REMOTE_TX) != 0;
16401669

16411670
case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:
@@ -1670,6 +1699,7 @@ static bool check_client_capabilities(struct client *client,
16701699
case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST:
16711700
case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY:
16721701
case WIRE_HSMD_VALIDATE_COMMITMENT_TX_REPLY:
1702+
case WIRE_HSMD_VALIDATE_REVOCATION_REPLY:
16731703
case WIRE_HSMD_SIGN_TX_REPLY:
16741704
case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:
16751705
case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:
@@ -1749,6 +1779,9 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
17491779
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
17501780
return handle_validate_commitment_tx(conn, c, c->msg_in);
17511781

1782+
case WIRE_HSMD_VALIDATE_REVOCATION:
1783+
return handle_validate_revocation(conn, c, c->msg_in);
1784+
17521785
case WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US:
17531786
return handle_sign_delayed_payment_to_us(conn, c, c->msg_in);
17541787

@@ -1800,6 +1833,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
18001833
case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST:
18011834
case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY:
18021835
case WIRE_HSMD_VALIDATE_COMMITMENT_TX_REPLY:
1836+
case WIRE_HSMD_VALIDATE_REVOCATION_REPLY:
18031837
case WIRE_HSMD_SIGN_TX_REPLY:
18041838
case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:
18051839
case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:

contrib/remote_hsmd/proxy.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,52 @@ proxy_stat proxy_handle_validate_commitment_tx(
12011201
}
12021202
}
12031203

1204+
proxy_stat proxy_handle_validate_revocation(
1205+
struct node_id *peer_id,
1206+
u64 dbid,
1207+
u64 revoke_num,
1208+
struct secret *old_secret)
1209+
{
1210+
STATUS_DEBUG(
1211+
"%s:%d %s { "
1212+
"\"self_id\":%s, \"peer_id\":%s, \"dbid\":%" PRIu64 ", "
1213+
"\"revoke_num\":%" PRIu64 ", "
1214+
"\"old_secret\":%s }",
1215+
__FILE__, __LINE__, __FUNCTION__,
1216+
dump_node_id(&self_id).c_str(),
1217+
dump_node_id(peer_id).c_str(),
1218+
dbid,
1219+
revoke_num,
1220+
dump_secret(old_secret).c_str()
1221+
);
1222+
1223+
last_message = "";
1224+
ValidateCounterpartyRevocationRequest req;
1225+
marshal_node_id(&self_id, req.mutable_node_id());
1226+
marshal_channel_nonce(peer_id, dbid, req.mutable_channel_nonce());
1227+
req.set_revoke_num(revoke_num);
1228+
marshal_secret(old_secret, req.mutable_old_secret());
1229+
1230+
ClientContext context;
1231+
ValidateCounterpartyRevocationReply rsp;
1232+
Status status = stub->ValidateCounterpartyRevocation(&context, req, &rsp);
1233+
if (status.ok()) {
1234+
STATUS_DEBUG("%s:%d %s { "
1235+
"\"self_id\":%s } ",
1236+
__FILE__, __LINE__, __FUNCTION__,
1237+
dump_node_id(&self_id).c_str());
1238+
last_message = "success";
1239+
return PROXY_OK;
1240+
} else {
1241+
status_unusual("%s:%d %s: self_id=%s %s",
1242+
__FILE__, __LINE__, __FUNCTION__,
1243+
dump_node_id(&self_id).c_str(),
1244+
status.error_message().c_str());
1245+
last_message = status.error_message();
1246+
return map_status(status);
1247+
}
1248+
}
1249+
12041250
proxy_stat proxy_handle_cannouncement_sig(
12051251
struct node_id *peer_id,
12061252
u64 dbid,

contrib/remote_hsmd/proxy.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ proxy_stat proxy_handle_validate_commitment_tx(
144144
struct secret **o_old_secret,
145145
struct pubkey *next_per_commitment_point);
146146

147+
proxy_stat proxy_handle_validate_revocation(
148+
struct node_id *peer_id,
149+
u64 dbid,
150+
u64 revoke_num,
151+
struct secret *old_secret);
152+
147153
proxy_stat proxy_handle_cannouncement_sig(
148154
struct node_id *peer_id,
149155
u64 dbid,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/sh
2+
3+
echo "accepts log w/ failures on stdin"
4+
5+
TESTS=`awk '/^FAILED tests/ {print $2}'`
6+
7+
PYTHONPATH=\
8+
$PWD/contrib/pyln-client:\
9+
$PWD/contrib/pyln-testing:\
10+
$PWD/contrib/pyln-proto \
11+
TEST_DEBUG=1 \
12+
DEVELOPER=1 \
13+
VALGRIND=0 \
14+
SUBDAEMON='hsmd:remote_hsmd' \
15+
REMOTE_SIGNER_CMD=$(pwd)/../rust-lightning-signer/target/debug/server \
16+
pytest \
17+
$TESTS \
18+
-n=32 --timeout=300 --timeout_method=thread

contrib/remote_hsmd/scripts/run-all-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SUBDAEMON='hsmd:remote_hsmd' \
44
REMOTE_SIGNER_CMD=$(pwd)/../rust-lightning-signer/target/debug/server \
55
make \
6-
-j32 PYTEST_PAR=64 \
6+
-j16 PYTEST_PAR=32 \
77
DEVELOPER=1 \
88
VALGRIND=0 \
99
SLOW_MACHINE=0 \

contrib/remote_hsmd/scripts/run-one-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ SUBDAEMON='hsmd:remote_hsmd' \
1414
REMOTE_SIGNER_CMD=$(pwd)/../rust-lightning-signer/target/debug/server \
1515
pytest \
1616
$THETEST \
17-
-v --timeout=300 --timeout_method=thread -x -s
17+
-v --timeout=300 --timeout_method=thread -x

hsmd/hsmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
657657
case WIRE_HSMD_READY_CHANNEL:
658658
case WIRE_HSMD_SIGN_COMMITMENT_TX:
659659
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
660+
case WIRE_HSMD_VALIDATE_REVOCATION:
660661
case WIRE_HSMD_SIGN_PENALTY_TO_US:
661662
case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:
662663
case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:
@@ -694,6 +695,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
694695
case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST:
695696
case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY:
696697
case WIRE_HSMD_VALIDATE_COMMITMENT_TX_REPLY:
698+
case WIRE_HSMD_VALIDATE_REVOCATION_REPLY:
697699
case WIRE_HSMD_SIGN_TX_REPLY:
698700
case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:
699701
case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:

0 commit comments

Comments
 (0)