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.
|
||||
fn make_base_info() -> Vec<u8> {
|
||||
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);
|
||||
const FIXED: u8 = 1;
|
||||
info.push(FIXED);
|
||||
|
|
@ -246,7 +246,8 @@ fn get_dap_report_internal<T: Shardable>(
|
|||
Ok(Report {
|
||||
metadata,
|
||||
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:
|
||||
//! https://github.com/ietf-wg-ppm/draft-ietf-ppm-dap
|
||||
//! This code is based on version 02 of the standard available here:
|
||||
//! https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html
|
||||
//! This code is based on version 07 of the standard available here:
|
||||
//! https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html
|
||||
|
||||
use prio::codec::{
|
||||
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::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use rand::Rng;
|
||||
use rand::{Rng, RngCore};
|
||||
|
||||
/// 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)]
|
||||
pub struct TaskID(pub [u8; 32]);
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ impl Encode for TaskID {
|
|||
|
||||
/// uint64 Time;
|
||||
/// 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)]
|
||||
pub struct Time(pub u64);
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ impl Time {
|
|||
/// ExtensionType extension_type;
|
||||
/// opaque extension_data<0..2^16-1>;
|
||||
/// } 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)]
|
||||
pub struct Extension {
|
||||
extension_type: ExtensionType,
|
||||
|
|
@ -103,7 +103,7 @@ impl Encode for Extension {
|
|||
/// TBD(0),
|
||||
/// (65535)
|
||||
/// } 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)]
|
||||
#[repr(u16)]
|
||||
enum ExtensionType {
|
||||
|
|
@ -123,7 +123,8 @@ impl ExtensionType {
|
|||
/// Extension extensions<0..2^16-1>;
|
||||
/// opaque payload<0..2^32-1>;
|
||||
/// } 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 extensions: Vec<Extension>,
|
||||
pub payload: Vec<u8>,
|
||||
|
|
@ -138,7 +139,7 @@ impl Encode for PlaintextInputShare {
|
|||
|
||||
/// Identifier for a server's HPKE configuration
|
||||
/// 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)]
|
||||
pub struct HpkeConfigId(u8);
|
||||
|
||||
|
|
@ -165,8 +166,8 @@ impl Encode for HpkeConfigId {
|
|||
/// uint16 HpkeAeadId; /* Defined in [HPKE] */
|
||||
/// uint16 HpkeKemId; /* Defined in [HPKE] */
|
||||
/// uint16 HpkeKdfId; /* Defined in [HPKE] */
|
||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-04.html#name-hpke-configuration-request
|
||||
#[derive(Debug)]
|
||||
/// https://www.ietf.org/archive/id/draft-ietf-ppm-dap-07.html#name-hpke-configuration-request
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct HpkeConfig {
|
||||
pub id: HpkeConfigId,
|
||||
pub kem_id: u16,
|
||||
|
|
@ -203,7 +204,7 @@ impl Encode for HpkeConfig {
|
|||
/// opaque enc<1..2^16-1>; /* encapsulated HPKE key */
|
||||
/// opaque payload<1..2^32-1>; /* ciphertext */
|
||||
/// } 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)]
|
||||
pub struct HpkeCiphertext {
|
||||
pub config_id: HpkeConfigId,
|
||||
|
|
@ -234,7 +235,7 @@ impl Encode for HpkeCiphertext {
|
|||
}
|
||||
|
||||
/// 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)]
|
||||
pub struct ReportID(pub [u8; 16]);
|
||||
|
||||
|
|
@ -268,7 +269,7 @@ impl AsRef<[u8; 16]> for ReportID {
|
|||
/// ReportID report_id;
|
||||
/// Time time;
|
||||
/// } 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)]
|
||||
pub struct ReportMetadata {
|
||||
pub report_id: ReportID,
|
||||
|
|
@ -294,26 +295,34 @@ impl Encode for ReportMetadata {
|
|||
/// struct {
|
||||
/// ReportMetadata metadata;
|
||||
/// 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;
|
||||
/// 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)]
|
||||
pub struct Report {
|
||||
pub metadata: ReportMetadata,
|
||||
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 {
|
||||
/// Creates a minimal report for use in tests.
|
||||
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 {
|
||||
metadata: ReportMetadata {
|
||||
report_id: ReportID::generate(),
|
||||
time: Time::generate(1),
|
||||
},
|
||||
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> {
|
||||
let metadata = ReportMetadata::decode(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);
|
||||
if remaining_bytes == 0 {
|
||||
Ok(Report {
|
||||
metadata,
|
||||
public_share,
|
||||
encrypted_input_shares,
|
||||
leader_encrypted_input_share,
|
||||
helper_encrypted_input_share,
|
||||
})
|
||||
} else {
|
||||
Err(CodecError::BytesLeftOver(remaining_bytes))
|
||||
|
|
@ -341,6 +352,7 @@ impl Encode for Report {
|
|||
fn encode(&self, bytes: &mut Vec<u8>) {
|
||||
self.metadata.encode(bytes);
|
||||
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());
|
||||
Assert.equal(
|
||||
true,
|
||||
body.available() == 410 || body.available() == 3658,
|
||||
body.available() == 406 || body.available() == 3654,
|
||||
"Wrong request body size."
|
||||
);
|
||||
received = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue