Skip to content

Commit 1ad626c

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 3c81fdb commit 1ad626c

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
@@ -10619,8 +10619,20 @@ where
1061910619
}
1062010620
},
1062110621
OffersMessage::Invoice(invoice) => {
10622+
let expected_payment_id = match context {
10623+
OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => None,
10624+
OffersContext::OutboundPayment { payment_id } => Some(payment_id),
10625+
_ => return ResponseInstruction::NoResponse,
10626+
};
10627+
1062210628
let result = match invoice.verify(expanded_key, secp_ctx) {
1062310629
Ok(payment_id) => {
10630+
if let Some(expected_payment_id) = expected_payment_id {
10631+
if payment_id != expected_payment_id {
10632+
return ResponseInstruction::NoResponse;
10633+
}
10634+
}
10635+
1062410636
let features = self.bolt12_invoice_features();
1062510637
if invoice.invoice_features().requires_unknown_bits_from(&features) {
1062610638
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)