Skip to content

Commit 35b75fd

Browse files
committed
Authenticate InvoiceRequest using OfferContext
When an InvoiceRequest is handled with an OfferContext, use the containing nonce to verify that it is for a valid Offer. Otherwise, fall back to using Offer::metadata, which also contains the nonce. The latter is useful for supporting offers without blinded paths or those created prior to including an OffersContext in their blinded paths.
1 parent 6a54618 commit 35b75fd

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10703,19 +10703,35 @@ where
1070310703
Some(responder) => responder,
1070410704
None => return ResponseInstruction::NoResponse,
1070510705
};
10706+
10707+
let nonce = match context {
10708+
OffersContext::Unknown {} if invoice_request.metadata().is_some() => None,
10709+
OffersContext::InvoiceRequest { nonce } => Some(nonce),
10710+
_ => return ResponseInstruction::NoResponse,
10711+
};
10712+
10713+
let invoice_request = match nonce {
10714+
Some(nonce) => match invoice_request.verify_using_recipient_data(
10715+
nonce, expanded_key, secp_ctx,
10716+
) {
10717+
Ok(invoice_request) => invoice_request,
10718+
Err(()) => return ResponseInstruction::NoResponse,
10719+
},
10720+
None => match invoice_request.verify(expanded_key, secp_ctx) {
10721+
Ok(invoice_request) => invoice_request,
10722+
Err(()) => {
10723+
let error = Bolt12SemanticError::InvalidMetadata;
10724+
return responder.respond(OffersMessage::InvoiceError(error.into()));
10725+
},
10726+
},
10727+
};
10728+
1070610729
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
10707-
&invoice_request
10730+
&invoice_request.inner
1070810731
) {
1070910732
Ok(amount_msats) => amount_msats,
1071010733
Err(error) => return responder.respond(OffersMessage::InvoiceError(error.into())),
1071110734
};
10712-
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
10713-
Ok(invoice_request) => invoice_request,
10714-
Err(()) => {
10715-
let error = Bolt12SemanticError::InvalidMetadata;
10716-
return responder.respond(OffersMessage::InvoiceError(error.into()));
10717-
},
10718-
};
1071910735

1072010736
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
1072110737
let (payment_hash, payment_secret) = match self.create_inbound_payment(

lightning/src/offers/invoice_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ pub struct VerifiedInvoiceRequest {
613613
pub offer_id: OfferId,
614614

615615
/// The verified request.
616-
inner: InvoiceRequest,
616+
pub(crate) inner: InvoiceRequest,
617617

618618
/// Keys used for signing a [`Bolt12Invoice`] if they can be derived.
619619
///

0 commit comments

Comments
 (0)