-
Notifications
You must be signed in to change notification settings - Fork 25
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
[Decrypt script] In case decryption fails for a record, ignore and continue to decrypt #1270
Open
richajaindce
wants to merge
9
commits into
private-attribution:main
Choose a base branch
from
richajaindce:decrypt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
794c9ae
In case decryption fails, do not error out
richajaindce 9baca44
In case of an error it, log the error in the file and continue to pro…
richajaindce bd65cb5
Fixing test
richajaindce 40b2760
move error printing into iterator trait
eriktaubeneck 95af9ff
Merge pull request #36 from eriktaubeneck/decrypt
richajaindce ce50fbf
fix clippy error
eriktaubeneck f952513
Merge pull request #37 from eriktaubeneck/decrypt2
richajaindce fa2c862
Merge branch 'main' into decrypt
richajaindce 2f0e0c1
Adding deryption failure logging
richajaindce 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,7 +18,7 @@ use crate::{ | |||||
U128Conversions, | ||||||
}, | ||||||
hpke::{KeyRegistry, PrivateKeyOnly}, | ||||||
report::{EncryptedOprfReport, EventType, OprfReport, DEFAULT_KEY_ID}, | ||||||
report::{EncryptedOprfReport, EventType, InvalidReportError, OprfReport, DEFAULT_KEY_ID}, | ||||||
secret_sharing::IntoShares, | ||||||
test_fixture::{ipa::TestRawDataRecord, Reconstruct}, | ||||||
}; | ||||||
|
@@ -146,16 +146,15 @@ impl DecryptedReports { | |||||
} | ||||||
|
||||||
impl Iterator for DecryptedReports { | ||||||
type Item = OprfReport<BA8, BA3, BA20>; | ||||||
type Item = Result<OprfReport<BA8, BA3, BA20>, InvalidReportError>; | ||||||
|
||||||
fn next(&mut self) -> Option<Self::Item> { | ||||||
let mut line = String::new(); | ||||||
if self.reader.read_line(&mut line).unwrap() > 0 { | ||||||
let encrypted_report_bytes = hex::decode(line.trim()).unwrap(); | ||||||
let enc_report = | ||||||
EncryptedOprfReport::from_bytes(encrypted_report_bytes.as_slice()).unwrap(); | ||||||
let dec_report: OprfReport<BA8, BA3, BA20> = | ||||||
enc_report.decrypt(&self.key_registry).unwrap(); | ||||||
let dec_report = enc_report.decrypt(&self.key_registry); | ||||||
Some(dec_report) | ||||||
} else { | ||||||
None | ||||||
|
@@ -182,57 +181,63 @@ pub async fn decrypt_and_reconstruct(args: DecryptArgs) -> Result<(), BoxError> | |||||
.open(args.output_file)?, | ||||||
); | ||||||
|
||||||
for (dec_report1, (dec_report2, dec_report3)) in | ||||||
decrypted_reports1.zip(decrypted_reports2.zip(decrypted_reports3)) | ||||||
for (idx, (dec_report1, (dec_report2, dec_report3))) in decrypted_reports1 | ||||||
.zip(decrypted_reports2.zip(decrypted_reports3)) | ||||||
.enumerate() | ||||||
{ | ||||||
let timestamp = [ | ||||||
dec_report1.timestamp, | ||||||
dec_report2.timestamp, | ||||||
dec_report3.timestamp, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
let match_key = [ | ||||||
dec_report1.match_key, | ||||||
dec_report2.match_key, | ||||||
dec_report3.match_key, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
// these aren't reconstucted, so we explictly make sure | ||||||
// they are consistent across all three files, then set | ||||||
// it to the first one (without loss of generality) | ||||||
assert_eq!(dec_report1.event_type, dec_report2.event_type); | ||||||
assert_eq!(dec_report2.event_type, dec_report3.event_type); | ||||||
let is_trigger_report = dec_report1.event_type == EventType::Trigger; | ||||||
|
||||||
let breakdown_key = [ | ||||||
dec_report1.breakdown_key, | ||||||
dec_report2.breakdown_key, | ||||||
dec_report3.breakdown_key, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
let trigger_value = [ | ||||||
dec_report1.trigger_value, | ||||||
dec_report2.trigger_value, | ||||||
dec_report3.trigger_value, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
writeln!( | ||||||
writer, | ||||||
"{},{},{},{},{}", | ||||||
timestamp, | ||||||
match_key, | ||||||
u8::from(is_trigger_report), | ||||||
breakdown_key, | ||||||
trigger_value, | ||||||
)?; | ||||||
match (dec_report1, dec_report2, dec_report3) { | ||||||
(Ok(dec_report1), Ok(dec_report2), Ok(dec_report3)) => { | ||||||
let timestamp = [ | ||||||
dec_report1.timestamp, | ||||||
dec_report2.timestamp, | ||||||
dec_report3.timestamp, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
let match_key = [ | ||||||
dec_report1.match_key, | ||||||
dec_report2.match_key, | ||||||
dec_report3.match_key, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
// these aren't reconstucted, so we explictly make sure | ||||||
// they are consistent across all three files, then set | ||||||
// it to the first one (without loss of generality) | ||||||
assert_eq!(dec_report1.event_type, dec_report2.event_type); | ||||||
assert_eq!(dec_report2.event_type, dec_report3.event_type); | ||||||
let is_trigger_report = dec_report1.event_type == EventType::Trigger; | ||||||
|
||||||
let breakdown_key = [ | ||||||
dec_report1.breakdown_key, | ||||||
dec_report2.breakdown_key, | ||||||
dec_report3.breakdown_key, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
let trigger_value = [ | ||||||
dec_report1.trigger_value, | ||||||
dec_report2.trigger_value, | ||||||
dec_report3.trigger_value, | ||||||
] | ||||||
.reconstruct() | ||||||
.as_u128(); | ||||||
|
||||||
writeln!( | ||||||
writer, | ||||||
"{},{},{},{},{}", | ||||||
timestamp, | ||||||
match_key, | ||||||
u8::from(is_trigger_report), | ||||||
breakdown_key, | ||||||
trigger_value, | ||||||
)?; | ||||||
} | ||||||
_ => println!("Decryption failed for record no {idx}"), | ||||||
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.
Suggested change
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. FYI I ended up not adding a flag for this as this is useful information while decrypting rows @akoshelev |
||||||
} | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
|
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.
it may make sense to check each for errors explicitly up top, so that we make sure we log all 3. we'll want to make sure that all 3 are not decryptable. the suggestion is just a sketch, don't merge it directly.