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

Adding tests to verify that encryption of match key happened correctly for ios side of in app browser #1043

Closed

Conversation

richajaindce
Copy link
Contributor

No description provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@akoshelev i am storing this blob file in test_data folder. Is this correct place to store it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am tempted to use something like rust-lang/cargo#2841 (comment) for large test files. If it is really small, perhaps you could hex-encode it and store it inside the test file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would still prefer for it to sit in a separate file as then we can compare this file with what we generate on client side by simply taking a diff. On the iOS side, I am going to dump a file with the contents and leaving an action item to validate the contents each time a change is made in the implementation

Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 95.12195% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 90.61%. Comparing base (cd0f869) to head (15a4a4a).

Files Patch % Lines
ipa-core/src/report/matchkey.rs 95.12% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #1043       +/-   ##
=========================================
+ Coverage      0   90.61%   +90.61%     
=========================================
  Files         0      174      +174     
  Lines         0    26265    +26265     
=========================================
+ Hits          0    23800    +23800     
- Misses        0     2465     +2465     

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am tempted to use something like rust-lang/cargo#2841 (comment) for large test files. If it is really small, perhaps you could hex-encode it and store it inside the test file

/// `ct_mk`: Enc(`match_key`)
/// associated data of `ct_mk`: `key_id`, `epoch`, `event_type`, `site_domain`,
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct EncryptedMatchKeyReport<B>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this is a lot of code just to test the match key decryption. Is it possible to pad the match key encryption with dummy secret shares of ts, event type, etc and use our generic report struct for this purpose?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have not examined them side by side, but this code looks similar to the existing report parsing code. I agree with @akoshelev that it might be better to fill out dummy data to be able to reuse the existing structs. Or, if there is a new report struct that we need for real-world use cases, then maybe non-test code should be added to handle that report format.

#[test]
fn test_matchkey_decrypt_encrypt() {
let mut rng = thread_rng();
let pk = hex::decode("92a6fb666c37c008defd74abf3204ebea685742eab8347b08e2f7c759893947a")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe you could avoid copy-pasting the same key material and set it up once as a constant for all tests.

but probably if you could use GenericReport you don't need to test the encryption roundtrip

/// `ct_mk`: Enc(`match_key`)
/// associated data of `ct_mk`: `key_id`, `epoch`, `event_type`, `site_domain`,
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct EncryptedMatchKeyReport<B>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have not examined them side by side, but this code looks similar to the existing report parsing code. I agree with @akoshelev that it might be better to fill out dummy data to be able to reuse the existing structs. Or, if there is a new report struct that we need for real-world use cases, then maybe non-test code should be added to handle that report format.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that this module is only for tests, maybe name it matchkey_test or something like that? If the necessary APIs are all public, another option is an integration test in ipa-core/tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how others feel about this, but I'd be in favor of moving away from mod.rs files, i.e. not doing this rename.

@richajaindce
Copy link
Contributor Author

Closing this in favor of #1071

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