Skip to content

Commit 100e856

Browse files
committed
Wrapped signatures w/ typed messages.
1 parent dac7da8 commit 100e856

File tree

5 files changed

+128
-137
lines changed

5 files changed

+128
-137
lines changed

contrib/remote_hsmd/dump.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C" {
1111
#include <common/status.h>
1212
#include <common/utils.h>
1313
#include <common/utxo.h>
14+
#include <secp256k1_recovery.h>
1415
}
1516

1617
#include "contrib/remote_hsmd/dump.h"
@@ -53,6 +54,12 @@ string dump_secp256k1_ecdsa_signature(const secp256k1_ecdsa_signature *sp)
5354
return dump_hex(sp->data, sizeof(sp->data));
5455
}
5556

57+
string dump_secp256k1_ecdsa_recoverable_signature(
58+
const secp256k1_ecdsa_recoverable_signature *sp)
59+
{
60+
return dump_hex(sp->data, sizeof(sp->data));
61+
}
62+
5663
string dump_node_id(const struct node_id *pp)
5764
{
5865
return dump_hex(pp->k, sizeof(pp->k));

contrib/remote_hsmd/dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ std::string dump_basepoints(const struct basepoints *bp);
55
std::string dump_bitcoin_txid(const struct bitcoin_txid *txid);
66
std::string dump_bitcoin_signature(const struct bitcoin_signature *sp);
77
std::string dump_secp256k1_ecdsa_signature(const secp256k1_ecdsa_signature *sp);
8+
std::string dump_secp256k1_ecdsa_recoverable_signature(const secp256k1_ecdsa_recoverable_signature *sp);
89
std::string dump_node_id(const struct node_id *pp);
910
std::string dump_pubkey(const struct pubkey *kp);
1011
std::string dump_unilateral_close_info(const struct unilateral_close_info *ip);

contrib/remote_hsmd/hsmd.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,11 +1036,10 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
10361036
* you'll crash if you assume it's there and you're wrong.) */
10371037
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
10381038

1039-
u8 *** sigs;
10401039
proxy_stat rv = proxy_handle_sign_commitment_tx(
10411040
tx, &remote_funding_pubkey, &funding,
10421041
&c->id, c->dbid,
1043-
&sigs);
1042+
&sig);
10441043
if (PROXY_PERMANENT(rv))
10451044
status_failed(STATUS_FAIL_INTERNAL_ERROR,
10461045
"proxy_%s failed: %s", __FUNCTION__,
@@ -1052,10 +1051,6 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
10521051
g_proxy_impl = PROXY_IMPL_MARSHALED;
10531052

10541053
#if 0
1055-
assert(tal_count(sigs) == 1);
1056-
1057-
bool ok = signature_from_der(sigs[0][0], tal_count(sigs[0][0]), &sig);
1058-
assert(ok);
10591054
status_debug("%s:%d %s: signature: %s",
10601055
__FILE__, __LINE__, __FUNCTION__,
10611056
type_to_string(tmpctx, struct bitcoin_signature, &sig));
@@ -1139,14 +1134,13 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
11391134
SIGHASH_ALL,
11401135
&sig);
11411136
*/
1142-
u8 *** sigs;
11431137
proxy_stat rv = proxy_handle_sign_remote_commitment_tx(
11441138
tx, &remote_funding_pubkey, &funding,
11451139
&c->id, c->dbid,
11461140
(const struct witscript **) output_witscripts,
11471141
&remote_per_commit,
11481142
option_static_remotekey,
1149-
&sigs);
1143+
&sig);
11501144
if (PROXY_PERMANENT(rv))
11511145
status_failed(STATUS_FAIL_INTERNAL_ERROR,
11521146
"proxy_%s failed: %s", __FUNCTION__,
@@ -1155,11 +1149,8 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
11551149
return bad_req_fmt(conn, c, msg_in,
11561150
"proxy_%s error: %s", __FUNCTION__,
11571151
proxy_last_message());
1158-
assert(tal_count(sigs) == 1);
11591152
g_proxy_impl = PROXY_IMPL_COMPLETE;
11601153

1161-
bool ok = signature_from_der(sigs[0][0], tal_count(sigs[0][0]), &sig);
1162-
assert(ok);
11631154
status_debug("%s:%d %s: signature: %s",
11641155
__FILE__, __LINE__, __FUNCTION__,
11651156
type_to_string(tmpctx, struct bitcoin_signature, &sig));
@@ -1694,11 +1685,10 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
16941685
/* Need input amount for signing */
16951686
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
16961687

1697-
u8 *** sigs;
16981688
proxy_stat rv = proxy_handle_sign_mutual_close_tx(
16991689
tx, &remote_funding_pubkey, &funding,
17001690
&c->id, c->dbid,
1701-
&sigs);
1691+
&sig);
17021692
if (PROXY_PERMANENT(rv))
17031693
status_failed(STATUS_FAIL_INTERNAL_ERROR,
17041694
"proxy_%s failed: %s", __FUNCTION__,
@@ -2046,8 +2036,7 @@ static struct io_plan *handle_sign_invoice(struct io_conn *conn,
20462036
if (!fromwire_hsm_sign_invoice(tmpctx, msg_in, &u5bytes, &hrpu8))
20472037
return bad_req(conn, c, msg_in);
20482038

2049-
u8 *sigbytes;
2050-
proxy_stat rv = proxy_handle_sign_invoice(u5bytes, hrpu8, &sigbytes);
2039+
proxy_stat rv = proxy_handle_sign_invoice(u5bytes, hrpu8, &rsig);
20512040
if (PROXY_PERMANENT(rv))
20522041
status_failed(STATUS_FAIL_INTERNAL_ERROR,
20532042
"proxy_%s failed: %s", __FUNCTION__,
@@ -2058,9 +2047,7 @@ static struct io_plan *handle_sign_invoice(struct io_conn *conn,
20582047
proxy_last_message());
20592048
g_proxy_impl = PROXY_IMPL_MARSHALED;
20602049

2061-
/* FIXME - convert the returned signature to an
2062-
* secp256k1_ecdsa_recoverable_signature and remove the code
2063-
* below. */
2050+
/* FIXME - USE THE PROXIED VALUE WHEN SERVER SUPPORTS */
20642051

20652052
/* BOLT #11:
20662053
*

0 commit comments

Comments
 (0)