patch remove-payer-backcompat.patch

This commit is contained in:
Rusty Russell 2021-07-05 15:53:13 +09:30 committed by neil saitug
parent e4e1396447
commit 424ac84263
9 changed files with 18 additions and 132 deletions

View File

@ -553,8 +553,7 @@ int main(int argc, char *argv[])
print_features(invreq->features);
if (invreq->quantity)
print_quantity(*invreq->quantity);
/* Note: old format didn't include this, so we don't complain! */
if (invreq->payer_signature)
if (must_have(invreq, payer_signature))
well_formed &= print_signature("invoice_request",
"payer_signature",
invreq->fields,
@ -563,18 +562,8 @@ int main(int argc, char *argv[])
if (invreq->recurrence_counter) {
print_recurrence_counter(invreq->recurrence_counter,
invreq->recurrence_start);
/* Old form included recurrence_signature */
if (invreq->recurrence_signature)
well_formed &= print_signature("invoice_request",
"recurrence_signature",
invreq->fields,
invreq->payer_key,
invreq->recurrence_signature);
else /* New form definitely should have this! */
must_have(invreq, payer_signature);
} else {
must_not_have(invreq, recurrence_start);
must_not_have(invreq, recurrence_signature);
}
if (!print_extra_fields(invreq->fields))
well_formed = false;

View File

@ -461,13 +461,6 @@ static struct command_result *json_createinvoicerequest(struct command *cmd,
&merkle, invreq->payer_info, invreq->payer_key,
invreq->payer_signature);
/* Backwards compat for older version! */
if (deprecated_apis && invreq->recurrence_counter) {
invreq->recurrence_signature = tal(invreq, struct bip340sig);
hsm_sign_b12(cmd->ld, "invoice_request", "recurrence_signature",
&merkle, invreq->payer_info, invreq->payer_key,
invreq->recurrence_signature);
}
response = json_stream_success(cmd);
json_add_string(response, "bolt12", invrequest_encode(tmpctx, invreq));
if (label)

View File

@ -674,10 +674,7 @@ static void json_add_invoice_request(struct json_stream *js,
* - MUST fail the request if there is no `payer_signature` field.
* - MUST fail the request if `payer_signature` is not correct.
*/
/* Older spec didn't have this, so we allow omission for now. */
if (invreq->payer_signature) {
json_add_bip340sig(js, "payer_signature",
invreq->payer_signature);
if (invreq->payer_key
&& !bolt12_check_signature(invreq->fields,
"invoice_request",
@ -691,21 +688,7 @@ static void json_add_invoice_request(struct json_stream *js,
} else {
json_add_string(js, "warning_invoice_request_missing_payer_signature",
"Missing payer_signature");
if (!deprecated_apis)
valid = false;
}
if (deprecated_apis && invreq->recurrence_counter) {
if (invreq->payer_key
&& !bolt12_check_signature(invreq->fields,
"invoice_request",
"recurrence_signature",
invreq->payer_key,
invreq->recurrence_signature)) {
json_add_string(js, "warning_invoice_request_invalid_recurrence_signature",
"Bad recurrence_signature");
valid = false;
}
valid = false;
}
json_add_bool(js, "valid", valid);

View File

@ -408,21 +408,6 @@ static struct command_result *check_previous_invoice(struct command *cmd,
return send_outreq(cmd->plugin, req);
}
/* Obsolete recurrence_signature; we still check if present. */
static bool check_recurrence_sig(const struct tlv_invoice_request *invreq,
const struct pubkey32 *payer_key,
const struct bip340sig *sig)
{
struct sha256 merkle, sighash;
merkle_tlv(invreq->fields, &merkle);
sighash_from_merkle("invoice_request", "recurrence_signature",
&merkle, &sighash);
return secp256k1_schnorrsig_verify(secp256k1_ctx,
sig->u8,
sighash.u.u8, &payer_key->pubkey) == 1;
}
/* BOLT-offers #12:
* - MUST fail the request if `payer_signature` is not correct.
*/
@ -721,17 +706,13 @@ static struct command_result *listoffers_done(struct command *cmd,
return err;
}
/* FIXME: payer_signature is now always required, but we let it go
* for now. */
if (!deprecated_apis) {
err = invreq_must_have(cmd, ir, payer_signature);
if (err)
return err;
if (!check_payer_sig(ir->invreq,
ir->invreq->payer_key,
ir->invreq->payer_signature)) {
return fail_invreq(cmd, ir, "bad payer_signature");
}
err = invreq_must_have(cmd, ir, payer_signature);
if (err)
return err;
if (!check_payer_sig(ir->invreq,
ir->invreq->payer_key,
ir->invreq->payer_signature)) {
return fail_invreq(cmd, ir, "bad payer_signature");
}
if (ir->offer->recurrence) {
@ -748,23 +729,6 @@ static struct command_result *listoffers_done(struct command *cmd,
err = invreq_must_have(cmd, ir, recurrence_counter);
if (err)
return err;
if (deprecated_apis) {
if (ir->invreq->recurrence_signature) {
if (!check_recurrence_sig(ir->invreq,
ir->invreq->payer_key,
ir->invreq->recurrence_signature)) {
return fail_invreq(cmd, ir,
"bad recurrence_signature");
}
} else {
/* You really do need payer_signature if
* you're using recurrence: we rely on it! */
err = invreq_must_have(cmd, ir, payer_signature);
if (err)
return err;
}
}
} else {
/* BOLT-offers #12:
* - otherwise (the offer had no `recurrence`):

View File

@ -63,10 +63,8 @@ tlvtype,invoice_request,payer_info,50
tlvdata,invoice_request,payer_info,blob,byte,...
tlvtype,invoice_request,replace_invoice,56
tlvdata,invoice_request,replace_invoice,payment_hash,sha256,
tlvtype,invoice_request,payer_signature,241
tlvtype,invoice_request,payer_signature,240
tlvdata,invoice_request,payer_signature,sig,bip340sig,
tlvtype,invoice_request,recurrence_signature,240
tlvdata,invoice_request,recurrence_signature,sig,bip340sig,
tlvtype,invoice,chains,2
tlvdata,invoice,chains,chains,chain_hash,...
tlvtype,invoice,offer_id,4

1 tlvtype,offer,chains,2
63 tlvdata,invoice_request,payer_info,blob,byte,...
64 tlvtype,invoice_request,replace_invoice,56
65 tlvdata,invoice_request,replace_invoice,payment_hash,sha256,
66 tlvtype,invoice_request,payer_signature,241 tlvtype,invoice_request,payer_signature,240
67 tlvdata,invoice_request,payer_signature,sig,bip340sig,
tlvtype,invoice_request,recurrence_signature,240
tlvdata,invoice_request,recurrence_signature,sig,bip340sig,
68 tlvtype,invoice,chains,2
69 tlvdata,invoice,chains,chains,chain_hash,...
70 tlvtype,invoice,offer_id,4

View File

@ -63,10 +63,8 @@ tlvtype,invoice_request,payer_info,50
tlvdata,invoice_request,payer_info,blob,byte,...
tlvtype,invoice_request,replace_invoice,56
tlvdata,invoice_request,replace_invoice,payment_hash,sha256,
tlvtype,invoice_request,payer_signature,241
tlvtype,invoice_request,payer_signature,240
tlvdata,invoice_request,payer_signature,sig,bip340sig,
tlvtype,invoice_request,recurrence_signature,240
tlvdata,invoice_request,recurrence_signature,sig,bip340sig,
tlvtype,invoice,chains,2
tlvdata,invoice,chains,chains,chain_hash,...
tlvtype,invoice,offer_id,4

1 tlvtype,offer,chains,2
63 tlvdata,invoice_request,payer_info,blob,byte,...
64 tlvtype,invoice_request,replace_invoice,56
65 tlvdata,invoice_request,replace_invoice,payment_hash,sha256,
66 tlvtype,invoice_request,payer_signature,241 tlvtype,invoice_request,payer_signature,240
67 tlvdata,invoice_request,payer_signature,sig,bip340sig,
tlvtype,invoice_request,recurrence_signature,240
tlvdata,invoice_request,recurrence_signature,sig,bip340sig,
68 tlvtype,invoice,chains,2
69 tlvdata,invoice,chains,chains,chain_hash,...
70 tlvtype,invoice,offer_id,4

32
wire/bolt12_wiregen.c generated
View File

@ -855,29 +855,6 @@ static void fromwire_tlv_invoice_request_payer_signature(const u8 **cursor, size
fromwire_bip340sig(cursor, plen, &*r->payer_signature);
}
/* INVOICE_REQUEST MSG: recurrence_signature */
static u8 *towire_tlv_invoice_request_recurrence_signature(const tal_t *ctx, const void *vrecord)
{
const struct tlv_invoice_request *r = vrecord;
u8 *ptr;
if (!r->recurrence_signature)
return NULL;
ptr = tal_arr(ctx, u8, 0);
towire_bip340sig(&ptr, r->recurrence_signature);
return ptr;
}
static void fromwire_tlv_invoice_request_recurrence_signature(const u8 **cursor, size_t *plen, void *vrecord)
{
struct tlv_invoice_request *r = vrecord;
r->recurrence_signature = tal(r, struct bip340sig);
fromwire_bip340sig(cursor, plen, &*r->recurrence_signature);
}
const struct tlv_record_type tlvs_invoice_request[] = {
{ 2, towire_tlv_invoice_request_chains, fromwire_tlv_invoice_request_chains },
@ -891,19 +868,18 @@ const struct tlv_record_type tlvs_invoice_request[] = {
{ 50, towire_tlv_invoice_request_payer_info, fromwire_tlv_invoice_request_payer_info },
{ 56, towire_tlv_invoice_request_replace_invoice, fromwire_tlv_invoice_request_replace_invoice },
{ 68, towire_tlv_invoice_request_recurrence_start, fromwire_tlv_invoice_request_recurrence_start },
{ 240, towire_tlv_invoice_request_recurrence_signature, fromwire_tlv_invoice_request_recurrence_signature },
{ 241, towire_tlv_invoice_request_payer_signature, fromwire_tlv_invoice_request_payer_signature },
{ 240, towire_tlv_invoice_request_payer_signature, fromwire_tlv_invoice_request_payer_signature },
};
void towire_invoice_request(u8 **pptr, const struct tlv_invoice_request *record)
{
towire_tlv(pptr, tlvs_invoice_request, 13, record);
towire_tlv(pptr, tlvs_invoice_request, 12, record);
}
bool fromwire_invoice_request(const u8 **cursor, size_t *max, struct tlv_invoice_request *record)
{
return fromwire_tlv(cursor, max, tlvs_invoice_request, 13, record, &record->fields);
return fromwire_tlv(cursor, max, tlvs_invoice_request, 12, record, &record->fields);
}
bool invoice_request_is_valid(const struct tlv_invoice_request *record, size_t *err_index)
@ -1708,4 +1684,4 @@ bool invoice_error_is_valid(const struct tlv_invoice_error *record, size_t *err_
return tlv_fields_valid(record->fields, NULL, err_index);
}
// SHA256STAMP:4e69a9a1519146453c234fe466d01c351cd0a21dc2c4e90538f73ed2f37fdc77
// SHA256STAMP:95d5be81bb0846cff337017b812800a19bf176d3182dd605bfe03086c14ef1f4

8
wire/bolt12_wiregen.h generated
View File

@ -94,7 +94,6 @@ struct tlv_invoice_request {
u8 *payer_info;
struct sha256 *replace_invoice;
struct bip340sig *payer_signature;
struct bip340sig *recurrence_signature;
};
struct tlv_invoice {
/* Raw fields including unknown ones. */
@ -215,7 +214,7 @@ void towire_invoice_request(u8 **pptr, const struct tlv_invoice_request *record)
bool invoice_request_is_valid(const struct tlv_invoice_request *record,
size_t *err_index);
#define TLVS_ARRAY_SIZE_invoice_request 13
#define TLVS_ARRAY_SIZE_invoice_request 12
extern const struct tlv_record_type tlvs_invoice_request[];
@ -233,8 +232,7 @@ enum invoice_request_types {
TLV_INVOICE_REQUEST_PAYER_INFO = 50,
TLV_INVOICE_REQUEST_REPLACE_INVOICE = 56,
TLV_INVOICE_REQUEST_RECURRENCE_START = 68,
TLV_INVOICE_REQUEST_RECURRENCE_SIGNATURE = 240,
TLV_INVOICE_REQUEST_PAYER_SIGNATURE = 241,
TLV_INVOICE_REQUEST_PAYER_SIGNATURE = 240,
};
struct tlv_invoice *tlv_invoice_new(const tal_t *ctx);
@ -325,4 +323,4 @@ struct fallback_address *fromwire_fallback_address(const tal_t *ctx, const u8 **
#endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */
// SHA256STAMP:4e69a9a1519146453c234fe466d01c351cd0a21dc2c4e90538f73ed2f37fdc77
// SHA256STAMP:95d5be81bb0846cff337017b812800a19bf176d3182dd605bfe03086c14ef1f4

View File

@ -1,13 +0,0 @@
diff --git a/wire/bolt12_wire.csv b/wire/bolt12_wire.csv
index 4c7108b98..7216e6b22 100644
--- a/wire/bolt12_wire.csv
+++ b/wire/bolt12_wire.csv
@@ -65,6 +65,8 @@ tlvtype,invoice_request,replace_invoice,56
tlvdata,invoice_request,replace_invoice,payment_hash,sha256,
tlvtype,invoice_request,payer_signature,241
tlvdata,invoice_request,payer_signature,sig,bip340sig,
+tlvtype,invoice_request,recurrence_signature,240
+tlvdata,invoice_request,recurrence_signature,sig,bip340sig,
tlvtype,invoice,chains,2
tlvdata,invoice,chains,chains,chain_hash,...
tlvtype,invoice,offer_id,4