Skip to content

Entitlement verification: Fix request verification#839

Merged
tonidero merged 4 commits into
entitlements-verificationfrom
entitlement-verification-fix-request-verification
Mar 8, 2023
Merged

Entitlement verification: Fix request verification#839
tonidero merged 4 commits into
entitlements-verificationfrom
entitlement-verification-fix-request-verification

Conversation

@tonidero

@tonidero tonidero commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

Description

There was a mismatch in what body the signing expects and what the body we read from the response. We were missing an end of line at the end of the body when verifying the signature. This fixes that issue.

@tonidero tonidero added the pr:fix A bug fix label Mar 3, 2023
@tonidero tonidero requested a review from a team March 3, 2023 11:09

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Forgot to add the url path to this error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about adding a test making sure this happens, but it's tricky since this all happens internally to this class and it seemed wrong to move that logic away from this class. I thought with the real data test would be enough to cover this case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm why adding a line break? Responses always end with it, and if they stop adding it, then the signature needs to account for that.
In iOS I added the line break to the test to replicate what the real responses look like so the signature matches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, the way we are reading the body in android (per lines) actually removes that line break. Which was causing the signature verification to fail. Adding this line break at the end actually fixes the issue (it verifies correctly).

Having said that, you might be right... It might be more accurate to change how we read the body to avoid modifying it at all... Will work on that tomorrow. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍🏻

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed approach in latest commits @NachoSoto. Lmk what you think!

@codecov

codecov Bot commented Mar 3, 2023

Copy link
Copy Markdown

Codecov Report

Merging #839 (86d1287) into entitlements-verification (86d1287) will not change coverage.
The diff coverage is n/a.

❗ Current head 86d1287 differs from pull request most recent head 125eefa. Consider uploading reports for the commit 125eefa to get more accurate results

@@                    Coverage Diff                     @@
##           entitlements-verification     #839   +/-   ##
==========================================================
  Coverage                      82.62%   82.62%           
==========================================================
  Files                            137      137           
  Lines                           4501     4501           
  Branches                         587      587           
==========================================================
  Hits                            3719     3719           
  Misses                           562      562           
  Partials                         220      220           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something I don't think we want to do this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm why adding a line break? Responses always end with it, and if they stop adding it, then the signature needs to account for that.
In iOS I added the line break to the test to replicate what the real responses look like so the signature matches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will read the whole text, it would not be that performant if we had multiple lines, but responses are usually minified anyway so it shouldn't really matter. This way we avoid removing the final new line from the body. CC @vegaro in case you have any thoughts about this approach.

Another thing I noticed is that we were not closing the BufferedReader but we are closing the inputStream later on, so I think we shouldn't be leaking it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is much simpler 👍🏻

@tonidero tonidero requested a review from NachoSoto March 8, 2023 11:22
@tonidero tonidero force-pushed the entitlement-verification-fix-request-verification branch 2 times, most recently from 8619d16 to 125eefa Compare March 8, 2023 11:35

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way you could add a failing test to make sure this missing line break is caught in signature verification?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is much simpler 👍🏻

@tonidero

tonidero commented Mar 8, 2023

Copy link
Copy Markdown
Contributor Author

Is there a way you could add a failing test to make sure this missing line break is caught in signature verification?

I tried adding that test before and it was difficult but then again, we only want to make sure the new lines are not stripped from the payload, so adding a test for that was easy 👍

@tonidero tonidero force-pushed the entitlement-verification-fix-request-verification branch from 71f99ed to b7b2a25 Compare March 8, 2023 15:38
@tonidero tonidero merged commit 89a0e58 into entitlements-verification Mar 8, 2023
@tonidero tonidero deleted the entitlement-verification-fix-request-verification branch March 8, 2023 16:00
tonidero added a commit that referenced this pull request Mar 15, 2023
### Description
There was a mismatch in what body the signing expects and what the body
we read from the response. We were missing an end of line at the end of
the body when verifying the signature. This fixes that issue.
@tonidero tonidero mentioned this pull request Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants