forked from mirrors/gecko-dev
Bug 1864754 - Update code to work with new lib. r=tcampbell
Differential Revision: https://phabricator.services.mozilla.com/D193723
This commit is contained in:
parent
cc147bba97
commit
ac1f456962
3 changed files with 37 additions and 24 deletions
|
|
@ -163,7 +163,7 @@ impl Shardable for ThinVec<u16> {
|
||||||
/// Pre-fill the info part of the HPKE sealing with the constants from the standard.
|
/// Pre-fill the info part of the HPKE sealing with the constants from the standard.
|
||||||
fn make_base_info() -> Vec<u8> {
|
fn make_base_info() -> Vec<u8> {
|
||||||
let mut info = Vec::<u8>::new();
|
let mut info = Vec::<u8>::new();
|
||||||
const START: &[u8] = "dap-04 input share".as_bytes();
|
const START: &[u8] = "dap-07 input share".as_bytes();
|
||||||
info.extend(START);
|
info.extend(START);
|
||||||
const FIXED: u8 = 1;
|
const FIXED: u8 = 1;
|
||||||
info.push(FIXED);
|
info.push(FIXED);
|
||||||
|
|
@ -246,7 +246,8 @@ fn get_dap_report_internal<T: Shardable>(
|
||||||
Ok(Report {
|
Ok(Report {
|
||||||
metadata,
|
metadata,
|
||||||
public_share: encoded_public_share,
|
public_share: encoded_public_share,
|
||||||
encrypted_input_shares: vec![leader_payload, helper_payload],
|
leader_encrypted_input_share: leader_payload,
|
||||||
|
helper_encrypted_input_share: helper_payload,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
//!
|
//!
|
||||||
//! The current draft standard with the definition of these structs is available here:
|
//! The current draft standard with the definition of these structs is available here:
|
||||||
//! https://github.com/ietf-wg-ppm/draft-ietf-ppm-dap
|
//! https://github.com/ietf-wg-ppm/draft-ietf-ppm-dap
|
||||||
//! This code is based on version 02 of the standard available here:
|
//! This code is based on version 07 of the standard available here:
|
||||||
//! https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html
|
//! https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html
|
||||||
|
|
||||||
use prio::codec::{
|
use prio::codec::{
|
||||||
decode_u16_items, decode_u32_items, encode_u16_items, encode_u32_items, CodecError, Decode,
|
decode_u16_items, decode_u32_items, encode_u16_items, encode_u32_items, CodecError, Decode,
|
||||||
|
|
@ -17,10 +17,10 @@ use prio::codec::{
|
||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::{Rng, RngCore};
|
||||||
|
|
||||||
/// opaque TaskId[32];
|
/// opaque TaskId[32];
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-task-configuration
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-task-configuration
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct TaskID(pub [u8; 32]);
|
pub struct TaskID(pub [u8; 32]);
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ impl Encode for TaskID {
|
||||||
|
|
||||||
/// uint64 Time;
|
/// uint64 Time;
|
||||||
/// seconds elapsed since start of UNIX epoch
|
/// seconds elapsed since start of UNIX epoch
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-protocol-definition
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-protocol-definition
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Time(pub u64);
|
pub struct Time(pub u64);
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl Time {
|
||||||
/// ExtensionType extension_type;
|
/// ExtensionType extension_type;
|
||||||
/// opaque extension_data<0..2^16-1>;
|
/// opaque extension_data<0..2^16-1>;
|
||||||
/// } Extension;
|
/// } Extension;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-upload-extensions
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-upload-extensions
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Extension {
|
pub struct Extension {
|
||||||
extension_type: ExtensionType,
|
extension_type: ExtensionType,
|
||||||
|
|
@ -103,7 +103,7 @@ impl Encode for Extension {
|
||||||
/// TBD(0),
|
/// TBD(0),
|
||||||
/// (65535)
|
/// (65535)
|
||||||
/// } ExtensionType;
|
/// } ExtensionType;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-upload-extensions
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-upload-extensions
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
enum ExtensionType {
|
enum ExtensionType {
|
||||||
|
|
@ -123,7 +123,8 @@ impl ExtensionType {
|
||||||
/// Extension extensions<0..2^16-1>;
|
/// Extension extensions<0..2^16-1>;
|
||||||
/// opaque payload<0..2^32-1>;
|
/// opaque payload<0..2^32-1>;
|
||||||
/// } PlaintextInputShare;
|
/// } PlaintextInputShare;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#section-4.3.2-9
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#section-4.4.2-9
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PlaintextInputShare {
|
pub struct PlaintextInputShare {
|
||||||
pub extensions: Vec<Extension>,
|
pub extensions: Vec<Extension>,
|
||||||
pub payload: Vec<u8>,
|
pub payload: Vec<u8>,
|
||||||
|
|
@ -138,7 +139,7 @@ impl Encode for PlaintextInputShare {
|
||||||
|
|
||||||
/// Identifier for a server's HPKE configuration
|
/// Identifier for a server's HPKE configuration
|
||||||
/// uint8 HpkeConfigId;
|
/// uint8 HpkeConfigId;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-protocol-definition
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-protocol-definition
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub struct HpkeConfigId(u8);
|
pub struct HpkeConfigId(u8);
|
||||||
|
|
||||||
|
|
@ -165,8 +166,8 @@ impl Encode for HpkeConfigId {
|
||||||
/// uint16 HpkeAeadId; /* Defined in [HPKE] */
|
/// uint16 HpkeAeadId; /* Defined in [HPKE] */
|
||||||
/// uint16 HpkeKemId; /* Defined in [HPKE] */
|
/// uint16 HpkeKemId; /* Defined in [HPKE] */
|
||||||
/// uint16 HpkeKdfId; /* Defined in [HPKE] */
|
/// uint16 HpkeKdfId; /* Defined in [HPKE] */
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-hpke-configuration-request
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-hpke-configuration-request
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HpkeConfig {
|
pub struct HpkeConfig {
|
||||||
pub id: HpkeConfigId,
|
pub id: HpkeConfigId,
|
||||||
pub kem_id: u16,
|
pub kem_id: u16,
|
||||||
|
|
@ -203,7 +204,7 @@ impl Encode for HpkeConfig {
|
||||||
/// opaque enc<1..2^16-1>; /* encapsulated HPKE key */
|
/// opaque enc<1..2^16-1>; /* encapsulated HPKE key */
|
||||||
/// opaque payload<1..2^32-1>; /* ciphertext */
|
/// opaque payload<1..2^32-1>; /* ciphertext */
|
||||||
/// } HpkeCiphertext;
|
/// } HpkeCiphertext;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-protocol-definition
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-protocol-definition
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct HpkeCiphertext {
|
pub struct HpkeCiphertext {
|
||||||
pub config_id: HpkeConfigId,
|
pub config_id: HpkeConfigId,
|
||||||
|
|
@ -234,7 +235,7 @@ impl Encode for HpkeCiphertext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// opaque ReportID[16];
|
/// opaque ReportID[16];
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-protocol-definition
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-protocol-definition
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct ReportID(pub [u8; 16]);
|
pub struct ReportID(pub [u8; 16]);
|
||||||
|
|
||||||
|
|
@ -268,7 +269,7 @@ impl AsRef<[u8; 16]> for ReportID {
|
||||||
/// ReportID report_id;
|
/// ReportID report_id;
|
||||||
/// Time time;
|
/// Time time;
|
||||||
/// } ReportMetadata;
|
/// } ReportMetadata;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-upload-request
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-upload-request
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct ReportMetadata {
|
pub struct ReportMetadata {
|
||||||
pub report_id: ReportID,
|
pub report_id: ReportID,
|
||||||
|
|
@ -294,26 +295,34 @@ impl Encode for ReportMetadata {
|
||||||
/// struct {
|
/// struct {
|
||||||
/// ReportMetadata metadata;
|
/// ReportMetadata metadata;
|
||||||
/// opaque public_share<0..2^32-1>;
|
/// opaque public_share<0..2^32-1>;
|
||||||
/// HpkeCiphertext encrypted_input_shares<1..2^32-1>;
|
/// HpkeCiphertext leader_encrypted_input_share;
|
||||||
|
/// HpkeCiphertext helper_encrypted_input_share;
|
||||||
/// } Report;
|
/// } Report;
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-upload-request
|
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-upload-request
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Report {
|
pub struct Report {
|
||||||
pub metadata: ReportMetadata,
|
pub metadata: ReportMetadata,
|
||||||
pub public_share: Vec<u8>,
|
pub public_share: Vec<u8>,
|
||||||
pub encrypted_input_shares: Vec<HpkeCiphertext>,
|
pub leader_encrypted_input_share: HpkeCiphertext,
|
||||||
|
pub helper_encrypted_input_share: HpkeCiphertext,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Report {
|
impl Report {
|
||||||
/// Creates a minimal report for use in tests.
|
/// Creates a minimal report for use in tests.
|
||||||
pub fn new_dummy() -> Self {
|
pub fn new_dummy() -> Self {
|
||||||
|
let mut enc = [0u8; 32];
|
||||||
|
rand::thread_rng().fill_bytes(&mut enc);
|
||||||
|
let mut payload = [0u8; 200];
|
||||||
|
rand::thread_rng().fill_bytes(&mut payload);
|
||||||
Report {
|
Report {
|
||||||
metadata: ReportMetadata {
|
metadata: ReportMetadata {
|
||||||
report_id: ReportID::generate(),
|
report_id: ReportID::generate(),
|
||||||
time: Time::generate(1),
|
time: Time::generate(1),
|
||||||
},
|
},
|
||||||
public_share: vec![],
|
public_share: vec![],
|
||||||
encrypted_input_shares: vec![],
|
leader_encrypted_input_share: HpkeCiphertext { config_id: HpkeConfigId(5), enc: vec![1, 2, 3, 4, 5], payload: vec![6, 7, 8, 9, 10] },
|
||||||
|
helper_encrypted_input_share: HpkeCiphertext { config_id: HpkeConfigId(100), enc: enc.into(), payload: payload.into() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -322,14 +331,16 @@ impl Decode for Report {
|
||||||
fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError> {
|
fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError> {
|
||||||
let metadata = ReportMetadata::decode(bytes)?;
|
let metadata = ReportMetadata::decode(bytes)?;
|
||||||
let public_share: Vec<u8> = decode_u32_items(&(), bytes)?;
|
let public_share: Vec<u8> = decode_u32_items(&(), bytes)?;
|
||||||
let encrypted_input_shares: Vec<HpkeCiphertext> = decode_u32_items(&(), bytes)?;
|
let leader_encrypted_input_share: HpkeCiphertext = HpkeCiphertext::decode(bytes)?;
|
||||||
|
let helper_encrypted_input_share: HpkeCiphertext = HpkeCiphertext::decode(bytes)?;
|
||||||
|
|
||||||
let remaining_bytes = bytes.get_ref().len() - (bytes.position() as usize);
|
let remaining_bytes = bytes.get_ref().len() - (bytes.position() as usize);
|
||||||
if remaining_bytes == 0 {
|
if remaining_bytes == 0 {
|
||||||
Ok(Report {
|
Ok(Report {
|
||||||
metadata,
|
metadata,
|
||||||
public_share,
|
public_share,
|
||||||
encrypted_input_shares,
|
leader_encrypted_input_share,
|
||||||
|
helper_encrypted_input_share,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(CodecError::BytesLeftOver(remaining_bytes))
|
Err(CodecError::BytesLeftOver(remaining_bytes))
|
||||||
|
|
@ -341,6 +352,7 @@ impl Encode for Report {
|
||||||
fn encode(&self, bytes: &mut Vec<u8>) {
|
fn encode(&self, bytes: &mut Vec<u8>) {
|
||||||
self.metadata.encode(bytes);
|
self.metadata.encode(bytes);
|
||||||
encode_u32_items(bytes, &(), &self.public_share);
|
encode_u32_items(bytes, &(), &self.public_share);
|
||||||
encode_u32_items(bytes, &(), &self.encrypted_input_shares);
|
self.leader_encrypted_input_share.encode(bytes);
|
||||||
|
self.helper_encrypted_input_share.encode(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ function uploadHandler(request, response) {
|
||||||
console.log(body.available());
|
console.log(body.available());
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
true,
|
true,
|
||||||
body.available() == 410 || body.available() == 3658,
|
body.available() == 406 || body.available() == 3654,
|
||||||
"Wrong request body size."
|
"Wrong request body size."
|
||||||
);
|
);
|
||||||
received = true;
|
received = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue