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

Removing match key provider from HPKE for now #659

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/hpke/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct Info<'a> {
pub(super) key_id: KeyIdentifier,
pub(super) epoch: Epoch,
pub(super) event_type: EventType,
pub(super) match_key_provider_origin: &'a str,
pub(super) helper_origin: &'a str,
pub(super) site_domain: &'a str,
}
Expand Down Expand Up @@ -49,14 +48,9 @@ impl<'a> Info<'a> {
key_id: KeyIdentifier,
epoch: Epoch,
event_type: EventType,
match_key_provider_origin: &'a str,
helper_origin: &'a str,
site_domain: &'a str,
) -> Result<Self, NonAsciiStringError<'a>> {
if !match_key_provider_origin.is_ascii() {
return Err(match_key_provider_origin.into());
}

if !helper_origin.is_ascii() {
return Err(helper_origin.into());
}
Expand All @@ -69,7 +63,6 @@ impl<'a> Info<'a> {
key_id,
epoch,
event_type,
match_key_provider_origin,
helper_origin,
site_domain,
})
Expand All @@ -79,19 +72,16 @@ impl<'a> Info<'a> {
/// sender or receiver context.
pub(super) fn into_bytes(self) -> Box<[u8]> {
let info_len = DOMAIN.len()
+ self.match_key_provider_origin.len()
+ self.helper_origin.len()
+ self.site_domain.len()
+ 4 // account for 4 delimiters
+ 3 // account for 4 delimiters
+ std::mem::size_of_val(&self.key_id)
+ std::mem::size_of_val(&self.epoch)
+ std::mem::size_of_val(&self.event_type);
let mut r = Vec::with_capacity(info_len);

r.extend_from_slice(DOMAIN.as_bytes());
r.push(0);
r.extend_from_slice(self.match_key_provider_origin.as_bytes());
r.push(0);
r.extend_from_slice(self.helper_origin.as_bytes());
r.push(0);
r.extend_from_slice(self.site_domain.as_bytes());
Expand Down
26 changes: 7 additions & 19 deletions src/hpke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ mod tests {
}

impl<R: RngCore + CryptoRng> EncryptionSuite<R> {
const MKP_ORIGIN: &'static str = "";
const HELPER_ORIGIN: &'static str = "foo";
const SITE_DOMAIN: &'static str = "xn--mozilla.com.xn--example.com";

Expand Down Expand Up @@ -250,7 +249,6 @@ mod tests {
key_id,
self.epoch,
event_type,
Self::MKP_ORIGIN,
Self::HELPER_ORIGIN,
Self::SITE_DOMAIN,
)
Expand All @@ -269,7 +267,6 @@ mod tests {
key_id,
self.epoch,
event_type,
Self::MKP_ORIGIN,
Self::HELPER_ORIGIN,
Self::SITE_DOMAIN,
)
Expand Down Expand Up @@ -297,9 +294,9 @@ mod tests {
/// Make sure we obey the spec
#[test]
fn ipa_info_serialize() {
let aad = Info::new(255, 32767, EventType::Trigger, "mkp_origin", "foo", "bar").unwrap();
let aad = Info::new(255, 32767, EventType::Trigger, "foo", "bar").unwrap();
assert_eq!(
b"private-attribution\0mkp_origin\0foo\0bar\0\xff\x7f\xff\x01",
b"private-attribution\0foo\0bar\0\xff\x7f\xff\x01",
aad.into_bytes().as_ref()
);
}
Expand Down Expand Up @@ -414,17 +411,16 @@ mod tests {
proptest::proptest! {
#![proptest_config(ProptestConfig::with_cases(50))]
#[test]
fn arbitrary_info_corruption(corrupted_info_field in 1..6,
mkp_origin in "[a-z]{10}",
fn arbitrary_info_corruption(corrupted_info_field in 1..5,
site_domain in "[a-z]{10}",
helper_origin in "[a-z]{10}",
trigger_bit in 0_u8..=1,
seed: [u8; 32]) {
let mut rng = StdRng::from_seed(seed);
let mut suite = EncryptionSuite::new(10, rng.clone());
// keep the originals, in case if we need to damage them
let (mut mkp_clone, mut site_domain_clone, mut helper_clone) = (mkp_origin.clone(), site_domain.clone(), helper_origin.clone());
let info = Info::new(0, 0, EventType::try_from(trigger_bit).unwrap(), &mkp_origin, &site_domain, &helper_origin).unwrap();
let (mut site_domain_clone, mut helper_clone) = (site_domain.clone(), helper_origin.clone());
let info = Info::new(0, 0, EventType::try_from(trigger_bit).unwrap(), &site_domain, &helper_origin).unwrap();
let mut encryption = suite.seal_with_info(info, &new_share(0, 0));

let info = match corrupted_info_field {
Expand All @@ -441,30 +437,22 @@ mod tests {
..encryption.info
},
4 => {
corrupt_str(&mut mkp_clone, &mut rng);

Info {
match_key_provider_origin: &mkp_clone,
..encryption.info
}
}
5 => {
corrupt_str(&mut site_domain_clone, &mut rng);

Info {
site_domain: &site_domain_clone,
..encryption.info
}
},
6 => {
5 => {
corrupt_str(&mut helper_clone, &mut rng);

Info {
helper_origin: &helper_clone,
..encryption.info
}
}
_ => panic!("bad test setup: only 6 fields can be corrupted, asked to corrupt: {corrupted_info_field}")
_ => panic!("bad test setup: only 5 fields can be corrupted, asked to corrupt: {corrupted_info_field}")
};

open_in_place(&suite.registry, &encryption.enc, &mut encryption.ct, info).unwrap_err();
Expand Down