Skip to content

Commit c7afd5c

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 1f26d05 commit c7afd5c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10520,17 +10520,31 @@ where
1052010520
Some(responder) => responder,
1052110521
None => return ResponseInstruction::NoResponse,
1052210522
};
10523+
10524+
let nonce = match context {
10525+
OffersContext::Unknown {} if invoice_request.metadata().is_some() => None,
10526+
OffersContext::InvoiceRequest { nonce } => Some(nonce),
10527+
_ => return ResponseInstruction::NoResponse,
10528+
};
10529+
1052310530
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
1052410531
&invoice_request
1052510532
) {
1052610533
Ok(amount_msats) => amount_msats,
1052710534
Err(error) => return responder.respond(OffersMessage::InvoiceError(error.into())),
1052810535
};
10529-
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
10530-
Ok(invoice_request) => invoice_request,
10531-
Err(()) => {
10532-
let error = Bolt12SemanticError::InvalidMetadata;
10533-
return responder.respond(OffersMessage::InvoiceError(error.into()));
10536+
10537+
let invoice_request = match nonce {
10538+
Some(nonce) => match invoice_request.verify_using_nonce(nonce, expanded_key, secp_ctx) {
10539+
Ok(invoice_request) => invoice_request,
10540+
Err(()) => return ResponseInstruction::NoResponse,
10541+
},
10542+
None => match invoice_request.verify(expanded_key, secp_ctx) {
10543+
Ok(invoice_request) => invoice_request,
10544+
Err(()) => {
10545+
let error = Bolt12SemanticError::InvalidMetadata;
10546+
return responder.respond(OffersMessage::InvoiceError(error.into()));
10547+
},
1053410548
},
1053510549
};
1053610550

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use bitcoin::blockdata::constants::ChainHash;
1919
use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey};
2020

21-
use crate::blinded_path::message::OffersContext;
2221
use crate::sign::{NodeSigner, Recipient};
22+
use crate::blinded_path::message::OffersContext;
2323
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
2424
use crate::ln::types::ChannelId;
2525
use crate::ln::features::{InitFeatures, NodeFeatures};

0 commit comments

Comments
 (0)