-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authenticate use of offer blinded paths #3139
Merged
TheBlueMatt
merged 29 commits into
lightningdevkit:main
from
jkczyz:2024-06-blinded-path-auth
Jul 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5278d31
Change Nonce visibility to pub
jkczyz 0a5918e
Reorder imports
jkczyz d7aeaa0
Move Nonce to a separate offers sub-module
jkczyz 219691f
Pass Nonce directly to OfferBuilder
jkczyz e156415
Add InvoiceRequest::verify_using_recipient_data
jkczyz c0cae08
Assert and document valid Metadata states
jkczyz c58a1bb
Clean up MessageContext docs
jkczyz 7904e3c
Wrap docs at 100 characters
jkczyz f546aad
Expand OffersContext::OutboundPayment docs
jkczyz 1ff8c8d
Fix grammar
jkczyz a5145e4
Fix OffersContext::Unknown docs
jkczyz 6a54618
Add OffersContext::InvoiceRequest
jkczyz 35b75fd
Authenticate InvoiceRequest using OfferContext
jkczyz bf42847
Elide metadata from Offer with derived keys
jkczyz 9d46340
Rename InvoiceRequest::verify
jkczyz f537abd
Add docs to Metadata::without_keys
jkczyz c2a120e
Authenticate Bolt12Invoice using OfferContext
jkczyz 559daeb
Don't send InvoiceError on failed authentication
jkczyz bdf3330
Add failure tests for offer message authentication
jkczyz fd596c3
Pass Nonce directly to InvoiceRequestBuilder
jkczyz 114954c
Pass Nonce directly to RefundBuilder
jkczyz 868fee7
Add Bolt12Invoice::verify_using_payer_data
jkczyz 14634c6
Add nonce to OffersContext::OutboundPayment
jkczyz 2c2f3fe
Authenticate Bolt12Invoice using BlindedPath data
jkczyz e6ee194
Include OffersContext in Event::InvoiceReceived
jkczyz 4ed37d8
Correct docs
jkczyz df5d7ea
Elide nonce from payer metadata
jkczyz 718bc47
Rename Bolt12Invoice::verify
jkczyz 825bda0
Add pending changelog for BOLT12 authentication
jkczyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -913,18 +913,28 @@ impl OfferContents { | |
self.signing_pubkey | ||
} | ||
|
||
/// Verifies that the offer metadata was produced from the offer in the TLV stream. | ||
pub(super) fn verify<T: secp256k1::Signing>( | ||
&self, bytes: &[u8], key: &ExpandedKey, secp_ctx: &Secp256k1<T> | ||
) -> Result<(OfferId, Option<Keypair>), ()> { | ||
match self.metadata() { | ||
self.verify_using_metadata(bytes, self.metadata.as_ref(), key, secp_ctx) | ||
} | ||
|
||
pub(super) fn verify_using_recipient_data<T: secp256k1::Signing>( | ||
&self, bytes: &[u8], nonce: Nonce, key: &ExpandedKey, secp_ctx: &Secp256k1<T> | ||
) -> Result<(OfferId, Option<Keypair>), ()> { | ||
self.verify_using_metadata(bytes, Some(&Metadata::RecipientData(nonce)), key, secp_ctx) | ||
} | ||
|
||
/// Verifies that the offer metadata was produced from the offer in the TLV stream. | ||
fn verify_using_metadata<T: secp256k1::Signing>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd feel much better if the two verification methods used different IVs. I know it shouldn't matter cause the offer can't be changed, but I'd feel better about it. |
||
&self, bytes: &[u8], metadata: Option<&Metadata>, key: &ExpandedKey, secp_ctx: &Secp256k1<T> | ||
) -> Result<(OfferId, Option<Keypair>), ()> { | ||
match metadata { | ||
Some(metadata) => { | ||
let tlv_stream = TlvStream::new(bytes).range(OFFER_TYPES).filter(|record| { | ||
match record.r#type { | ||
OFFER_METADATA_TYPE => false, | ||
OFFER_NODE_ID_TYPE => { | ||
!self.metadata.as_ref().unwrap().derives_recipient_keys() | ||
}, | ||
OFFER_NODE_ID_TYPE => !metadata.derives_recipient_keys(), | ||
_ => true, | ||
} | ||
}); | ||
|
@@ -933,7 +943,7 @@ impl OfferContents { | |
None => return Err(()), | ||
}; | ||
let keys = signer::verify_recipient_metadata( | ||
metadata, key, IV_BYTES, signing_pubkey, tlv_stream, secp_ctx | ||
metadata.as_ref(), key, IV_BYTES, signing_pubkey, tlv_stream, secp_ctx | ||
)?; | ||
|
||
let offer_id = OfferId::from_valid_invreq_tlv_stream(bytes); | ||
|
@@ -1296,6 +1306,14 @@ mod tests { | |
Err(_) => panic!("unexpected error"), | ||
} | ||
|
||
// Fails verification when using the wrong method | ||
let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() | ||
.build().unwrap() | ||
.sign(payer_sign).unwrap(); | ||
assert!( | ||
invoice_request.verify_using_recipient_data(nonce, &expanded_key, &secp_ctx).is_err() | ||
); | ||
|
||
// Fails verification with altered offer field | ||
let mut tlv_stream = offer.as_tlv_stream(); | ||
tlv_stream.amount = Some(100); | ||
|
@@ -1357,6 +1375,14 @@ mod tests { | |
Err(_) => panic!("unexpected error"), | ||
} | ||
|
||
let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() | ||
.build().unwrap() | ||
.sign(payer_sign).unwrap(); | ||
match invoice_request.verify_using_recipient_data(nonce, &expanded_key, &secp_ctx) { | ||
Ok(invoice_request) => assert_eq!(invoice_request.offer_id, offer.id()), | ||
Err(_) => panic!("unexpected error"), | ||
} | ||
|
||
// Fails verification with altered offer field | ||
let mut tlv_stream = offer.as_tlv_stream(); | ||
tlv_stream.amount = Some(100); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to update docs here to say that this is deprecated and users really need to use the
using_recipient_data
variant, this is just here for legacy offers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still needed for offers without blinded paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the method name to clarify the contexts in which it makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Updated now and did the same for invoice verification methods. Also updated some missed tests and docs.