Skip to content
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

Add PaymentId authentication to public API #3242

Merged

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Aug 14, 2024

When receiving an InvoiceError message, it should be authenticated before using it to abandon the payment. Add methods to PaymentId's public API for constructing and verifying an HMAC for use in OffersContext::OutboundPayment. This allows other implementations of OffersMessageHandler to construct the HMAC and authenticate the message.

@jkczyz jkczyz added this to the 0.0.124 milestone Aug 14, 2024
@TheBlueMatt
Copy link
Collaborator

CI is very sad, also feel free to rebase.

@jkczyz jkczyz force-pushed the 2024-08-payment-id-auth-api branch from 4a1450c to 877f115 Compare August 15, 2024 16:16
Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.14%. Comparing base (33e6995) to head (5bee20e).
Report is 31 commits behind head on main.

Files Patch % Lines
lightning/src/offers/signer.rs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3242      +/-   ##
==========================================
+ Coverage   89.78%   90.14%   +0.36%     
==========================================
  Files         123      124       +1     
  Lines      102330   106664    +4334     
  Branches   102330   106664    +4334     
==========================================
+ Hits        91876    96152    +4276     
- Misses       7763     7858      +95     
+ Partials     2691     2654      -37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkczyz jkczyz force-pushed the 2024-08-payment-id-auth-api branch from 877f115 to aba273a Compare August 16, 2024 16:33

/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
/// along with the given [`Nonce`].
pub fn hmac_for_offer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: *_for_offer -- this may also be used for refunds, right? May be easier to name it in relation to invoice errors since that's what it's used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't set the HMAC in refunds because (1) it would increase the QR code size and (2) we don't necessarily want someone to send an InvoiceError to one in response -- rather the Refund creator can set a short expiry or abandon it manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: naming -- how about hmac_using_nonce?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I do prefer that name... hmac_for_offer_payment also works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmac_for_offer_payment SGTM

@jkczyz jkczyz force-pushed the 2024-08-payment-id-auth-api branch from aba273a to c6c9c29 Compare August 16, 2024 17:44
@@ -410,6 +410,6 @@ pub(crate) fn hmac_for_payment_id(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: hmac_for_offer call above -- it looks like ExpandedKey::hmac_for_offer docs need an update since it is only supposed to be used to construct offer metadata atm. It almost looks like we should have used a new key for InvoiceError verification, though I might be missing a prior discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we are using it for both offer metadata and payer metadata. I think we were fine with this because we add different inputs for each use case. @TheBlueMatt Is that correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we use a different IV (which is always in the same position in the data being hashed) so its fine.

When receiving an InvoiceError message, it should be authenticated
before using it to abandon the payment. Add methods to PaymentId's
public API for constructing and verifying an HMAC for use in
OffersContext::OutboundPayment. This allows other implementations of
OffersMessageHandler to construct the HMAC and authenticate the message.
@jkczyz jkczyz force-pushed the 2024-08-payment-id-auth-api branch from c6c9c29 to 5bee20e Compare August 16, 2024 20:44
@valentinewallace valentinewallace merged commit ccce9d9 into lightningdevkit:main Aug 19, 2024
18 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants