Skip to content

Commit 110966e

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 2edd55e commit 110966e

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
@@ -10621,8 +10621,20 @@ where
1062110621
}
1062210622
},
1062310623
OffersMessage::Invoice(invoice) => {
10624+
let expected_payment_id = match context {
10625+
OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => None,
10626+
OffersContext::OutboundPayment { payment_id } => Some(payment_id),
10627+
_ => return ResponseInstruction::NoResponse,
10628+
};
10629+
1062410630
let result = match invoice.verify(expanded_key, secp_ctx) {
1062510631
Ok(payment_id) => {
10632+
if let Some(expected_payment_id) = expected_payment_id {
10633+
if payment_id != expected_payment_id {
10634+
return ResponseInstruction::NoResponse;
10635+
}
10636+
}
10637+
1062610638
let features = self.bolt12_invoice_features();
1062710639
if invoice.invoice_features().requires_unknown_bits_from(&features) {
1062810640
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)