Skip to content

Commit c2a120e

Browse files
committed
Authenticate Bolt12Invoice using OfferContext
When a Bolt12Invoice is handled with an OfferContext, use the containing payment_id to verify that it is for a pending outbound payment. Only invoices for refunds without any blinded paths can be verified without an OfferContext.
1 parent f537abd commit c2a120e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10804,8 +10804,20 @@ where
1080410804
}
1080510805
},
1080610806
OffersMessage::Invoice(invoice) => {
10807+
let expected_payment_id = match context {
10808+
OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => None,
10809+
OffersContext::OutboundPayment { payment_id } => Some(payment_id),
10810+
_ => return ResponseInstruction::NoResponse,
10811+
};
10812+
1080710813
let result = match invoice.verify(expanded_key, secp_ctx) {
1080810814
Ok(payment_id) => {
10815+
if let Some(expected_payment_id) = expected_payment_id {
10816+
if payment_id != expected_payment_id {
10817+
return ResponseInstruction::NoResponse;
10818+
}
10819+
}
10820+
1080910821
let features = self.bolt12_invoice_features();
1081010822
if invoice.invoice_features().requires_unknown_bits_from(&features) {
1081110823
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))

lightning/src/offers/invoice.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,13 @@ impl Bolt12Invoice {
787787
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
788788
signature_tlv_stream)
789789
}
790+
791+
pub(crate) fn is_for_refund_without_paths(&self) -> bool {
792+
match self.contents {
793+
InvoiceContents::ForOffer { .. } => false,
794+
InvoiceContents::ForRefund { .. } => self.message_paths().is_empty(),
795+
}
796+
}
790797
}
791798

792799
impl PartialEq for Bolt12Invoice {

0 commit comments

Comments
 (0)