tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 655a08675015317dcb33c51e917c970e89eec2f5
parent 17c4a9d25bf2593b7b5107ec9142971ade9b4ce2
Author: Mark Hammond <mhammond@skippinet.com.au>
Date:   Fri,  3 Oct 2025 14:20:58 +0000

Bug 1990108 (part 2) - Update ohttp and bhttp crates to git rev bf6a983845cc0b540effb3a615e92d914dfcfd0b. r=necko-reviewers,supply-chain-reviewers,toolkit-telemetry-reviewers,valentin,janerik

Differential Revision: https://phabricator.services.mozilla.com/D265724

Diffstat:
M.cargo/config.toml.in | 5+++++
MCargo.lock | 12+++++-------
MCargo.toml | 6++++++
Mnetwerk/protocol/http/binary_http/Cargo.toml | 2+-
Mnetwerk/protocol/http/binary_http/src/lib.rs | 7++++---
Msupply-chain/audits.toml | 12++++++++++++
Msupply-chain/config.toml | 8++++++++
Msupply-chain/imports.lock | 8++++----
Mthird_party/rust/bhttp/.cargo-checksum.json | 4++--
Mthird_party/rust/bhttp/Cargo.toml | 53++++++++++++++++++++++++++++++++++++++++-------------
Mthird_party/rust/bhttp/src/err.rs | 6++++++
Mthird_party/rust/bhttp/src/lib.rs | 122++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Mthird_party/rust/bhttp/src/parse.rs | 2+-
Mthird_party/rust/bhttp/src/rw.rs | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Mthird_party/rust/bhttp/tests/test.rs | 17+++++++++--------
Mthird_party/rust/ohttp/.cargo-checksum.json | 4++--
Dthird_party/rust/ohttp/Cargo.lock | 1013-------------------------------------------------------------------------------
Mthird_party/rust/ohttp/Cargo.toml | 48++++++++++++++----------------------------------
Mthird_party/rust/ohttp/src/err.rs | 5+----
Mthird_party/rust/ohttp/src/hpke.rs | 9---------
Mthird_party/rust/ohttp/src/nss/aead.rs | 18++++++++++--------
Mthird_party/rust/ohttp/src/nss/hpke.rs | 39+++++++++++++++++++++++++--------------
Mthird_party/rust/ohttp/src/nss/p11.rs | 6+++---
Mthird_party/rust/ohttp/src/rh/hpke.rs | 134++-----------------------------------------------------------------------------
Mtoolkit/components/glean/Cargo.toml | 2+-
Mtoolkit/components/glean/src/init/viaduct_uploader.rs | 2+-
26 files changed, 332 insertions(+), 1320 deletions(-)

diff --git a/.cargo/config.toml.in b/.cargo/config.toml.in @@ -75,6 +75,11 @@ git = "https://github.com/jfkthame/mapped_hyph.git" rev = "eff105f6ad7ec9b79816cfc1985a28e5340ad14b" replace-with = "vendored-sources" +[source."git+https://github.com/martinthomson/ohttp.git?rev=bf6a983845cc0b540effb3a615e92d914dfcfd0b"] +git = "https://github.com/martinthomson/ohttp.git" +rev = "bf6a983845cc0b540effb3a615e92d914dfcfd0b" +replace-with = "vendored-sources" + [source."git+https://github.com/mozilla/application-services?rev=f6f667f590ac15367fc37eb1ad3a6bdea4ffc526"] git = "https://github.com/mozilla/application-services" rev = "f6f667f590ac15367fc37eb1ad3a6bdea4ffc526" diff --git a/Cargo.lock b/Cargo.lock @@ -425,9 +425,8 @@ dependencies = [ [[package]] name = "bhttp" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1300dca7a20730cce82c33fbf8795862556645ef5e9ee835390278c3fe1eb1d0" +version = "0.6.1" +source = "git+https://github.com/martinthomson/ohttp.git?rev=bf6a983845cc0b540effb3a615e92d914dfcfd0b#bf6a983845cc0b540effb3a615e92d914dfcfd0b" dependencies = [ "thiserror 1.999.999", ] @@ -5065,11 +5064,10 @@ dependencies = [ [[package]] name = "ohttp" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a87f4e4cd78d1619b98b6119cde887d20489f70339b9425af080b00db714b6" +version = "0.6.1" +source = "git+https://github.com/martinthomson/ohttp.git?rev=bf6a983845cc0b540effb3a615e92d914dfcfd0b#bf6a983845cc0b540effb3a615e92d914dfcfd0b" dependencies = [ - "bindgen 0.69.999", + "bindgen 0.72.0", "byteorder", "hex", "log", diff --git a/Cargo.toml b/Cargo.toml @@ -257,6 +257,12 @@ objc = { git = "https://github.com/glandium/rust-objc", rev = "4de89f5aa9851ceca # allocator-api2 + f95e3419ce41883904fcb2279b52aa35b5f04d76 + fdd92751afa7ce34408b677004b429d597e72c90 allocator-api2 = { git = "https://github.com/glandium/allocator-api2", rev = "ad5f3d56a5a4519eff52af4ff85293431466ef5c" } +# patch ohttp - app-services relies on a version yet to be released. However, even if a new version was released it +# will have bumped the `toml` crate to a version which would cause dupes here. We should remove this and revert back +# to a published version when we can upgrade both a-s and m-c to the same version. +ohttp = { git = "https://github.com/martinthomson/ohttp.git", rev = "bf6a983845cc0b540effb3a615e92d914dfcfd0b" } +bhttp = { git = "https://github.com/martinthomson/ohttp.git", rev = "bf6a983845cc0b540effb3a615e92d914dfcfd0b" } + # application-services overrides to make updating them all simpler. context_id = { git = "https://github.com/mozilla/application-services", rev = "f6f667f590ac15367fc37eb1ad3a6bdea4ffc526" } error-support = { git = "https://github.com/mozilla/application-services", rev = "f6f667f590ac15367fc37eb1ad3a6bdea4ffc526" } diff --git a/netwerk/protocol/http/binary_http/Cargo.toml b/netwerk/protocol/http/binary_http/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" [dependencies] nserror = { path = "../../../../xpcom/rust/nserror" } nsstring = { path = "../../../../xpcom/rust/nsstring" } -bhttp = "0.3" +bhttp = "0.6" thin-vec = { version = "0.2.1", features = ["gecko-ffi"] } xpcom = { path = "../../../../xpcom/rust/xpcom" } diff --git a/netwerk/protocol/http/binary_http/src/lib.rs b/netwerk/protocol/http/binary_http/src/lib.rs @@ -9,7 +9,7 @@ extern crate thin_vec; #[macro_use] extern crate xpcom; -use bhttp::{Message, Mode}; +use bhttp::{Message, Mode, StatusCode}; use nserror::{nsresult, NS_ERROR_FAILURE, NS_ERROR_INVALID_ARG, NS_ERROR_UNEXPECTED, NS_OK}; use nsstring::{nsACString, nsCString}; use std::io::Cursor; @@ -180,7 +180,7 @@ impl BinaryHttp { .collect(); let content = decoded.content().to_vec(); let binary_http_response = BinaryHttpResponse::allocate(InitBinaryHttpResponse { - status, + status: status.into(), headers, content, }); @@ -232,7 +232,8 @@ impl BinaryHttp { fn encode_response(&self, response: &nsIBinaryHttpResponse) -> Result<ThinVec<u8>, nsresult> { let mut status = 0; unsafe { response.GetStatus(&mut status) }.to_result()?; - let mut message = Message::response(status); + let mut message = + Message::response(StatusCode::try_from(status).map_err(|_| NS_ERROR_FAILURE)?); let mut header_names = ThinVec::new(); unsafe { response.GetHeaderNames(&mut header_names) }.to_result()?; let mut header_values = ThinVec::with_capacity(header_names.len()); diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml @@ -1024,6 +1024,12 @@ who = "Mike Hommey <mh+mozilla@glandium.org>" criteria = "safe-to-deploy" delta = "0.13.0 -> 0.13.1" +[[audits.bhttp]] +who = "Mark Hammond <mhammond@skippinet.com.au>" +criteria = "safe-to-deploy" +delta = "0.6.1 -> 0.6.1@git:bf6a983845cc0b540effb3a615e92d914dfcfd0b" +importable = false + [[audits.bindgen]] who = "Emilio Cobos Álvarez <emilio@crisal.io>" criteria = "safe-to-deploy" @@ -4490,6 +4496,12 @@ criteria = "safe-to-deploy" delta = "0.33.0 -> 0.36.4" notes = "Hardly any new unsafe code, no new dependencies nor side-effectful std functions. Plenty of new tests." +[[audits.ohttp]] +who = "Mark Hammond <mhammond@skippinet.com.au>" +criteria = "safe-to-deploy" +delta = "0.6.1 -> 0.6.1@git:bf6a983845cc0b540effb3a615e92d914dfcfd0b" +importable = false + [[audits.once_cell]] who = "Mike Hommey <mh+mozilla@glandium.org>" criteria = "safe-to-deploy" diff --git a/supply-chain/config.toml b/supply-chain/config.toml @@ -31,6 +31,10 @@ notes = "This is the upstream code plus the ARM intrinsics workaround from qcms, audit-as-crates-io = true notes = "This is the upstream code plus a few local fixes, see bug 1685697." +[policy.bhttp] +audit-as-crates-io = true +notes = "This is upstream code in between released versions." + [policy."bindgen:0.72.0@git:9366e0af8da529c958b4cd4fcbe492d951c86f5c"] audit-as-crates-io = true notes = "This is the upstream code not yet released" @@ -199,6 +203,10 @@ notes = "This is a pinned version of the upstream code, pending update of the cr audit-as-crates-io = true notes = "This is the upstream code plus a backported fix." +[policy.ohttp] +audit-as-crates-io = true +notes = "This is upstream code in between released versions." + [policy.osclientcerts] audit-as-crates-io = false notes = "This is a first-party crate that happens to have been pushed to crates.io a very long time ago but was yanked." diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock @@ -44,8 +44,8 @@ user-login = "jschanck" user-name = "John Schanck" [[publisher.bhttp]] -version = "0.3.1" -when = "2023-02-23" +version = "0.6.1" +when = "2025-06-19" user-id = 128763 user-login = "martinthomson" user-name = "Martin Thomson" @@ -457,8 +457,8 @@ user-login = "seanmonstar" user-name = "Sean McArthur" [[publisher.ohttp]] -version = "0.6.0" -when = "2025-06-18" +version = "0.6.1" +when = "2025-06-19" user-id = 128763 user-login = "martinthomson" user-name = "Martin Thomson" diff --git a/third_party/rust/bhttp/.cargo-checksum.json b/third_party/rust/bhttp/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"50cee393fec5ecf4c7c34fbbaefa37c3c5a6bf6c3acee2d035ac49d691c74f16","README.md":"30c2c4a78875fd78a6b007954ed0aceed4004983e5ff62a38261bbcd1a9c36a3","src/err.rs":"0b605edff622d043c9269675c74e412f3363a04060f2921356d0afcd27987c02","src/lib.rs":"0aff5fd18b0f90f3228a8f4c643ebb679fca8c909f497cbeb2f7e18009d8e932","src/parse.rs":"a2428cf6736cb6d251bb2c95d80d84f3c3fd0197a831f94045408ac592fd7013","src/rw.rs":"a667035f34b41e2492a417d1aad6454422f6769ece578faa75205a6335449511","tests/test.rs":"ec171a6a4d469de8d4fe921872a9c0e15b27ae9ca2c19ff4e756b5941e0a8b57"},"package":"1300dca7a20730cce82c33fbf8795862556645ef5e9ee835390278c3fe1eb1d0"} -\ No newline at end of file +{"files":{"Cargo.toml":"f67579f75f89317e8e2137cbfd59a2656692313921744089fda61c698743dc25","README.md":"30c2c4a78875fd78a6b007954ed0aceed4004983e5ff62a38261bbcd1a9c36a3","src/err.rs":"f380bc2c62cc0acc7d2a11f988b8cbd94014ae1665cdf5271165a511e7be0800","src/lib.rs":"619c1508a57222561bc4c193dafbcf88bf7685a743e99a90c44cf26874abaea2","src/parse.rs":"c759c0446c1016b412c4d294686713f296888dfa9713d9c6fa7382d4e4b5540a","src/rw.rs":"df7a0efd46e3ac0561428929bd447aef97ce380c83d2855996a0bf3a71cee0a7","tests/test.rs":"37c93b4f3e74ab474004bdc2d6688e970443ee006c4ea7101fcfcf17e8f7f880"},"package":null} +\ No newline at end of file diff --git a/third_party/rust/bhttp/Cargo.toml b/third_party/rust/bhttp/Cargo.toml @@ -11,24 +11,33 @@ [package] edition = "2021" +rust-version = "1.82.0" name = "bhttp" -version = "0.3.1" +version = "0.6.1" authors = ["Martin Thomson <mt@lowentropy.net>"] -description = "Binary HTTP messages (draft-ietf-httpbis-binary-message)" -readme = "README.md" +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "Binary HTTP messages (RFC 9292)" +homepage = "https://github.com/martinthomson/ohttp" +readme = "../README.md" +keywords = [ + "ohttp", + "http", + "bhttp", + "ietf", +] +categories = [ + "network-programming", + "web-programming", + "security", +] license = "MIT OR Apache-2.0" repository = "https://github.com/martinthomson/ohttp" -[dependencies.thiserror] -version = "1" - -[dependencies.url] -version = "2" -optional = true - -[dev-dependencies.hex] -version = "0.4" - [features] bhttp = [ "read-bhttp", @@ -43,3 +52,21 @@ read-bhttp = [] read-http = ["url"] write-bhttp = [] write-http = [] + +[lib] +name = "bhttp" +path = "src/lib.rs" + +[[test]] +name = "test" +path = "tests/test.rs" + +[dependencies] +thiserror = "1" + +[dependencies.url] +version = "2" +optional = true + +[dev-dependencies] +hex = "0.4" diff --git a/third_party/rust/bhttp/src/err.rs b/third_party/rust/bhttp/src/err.rs @@ -6,10 +6,16 @@ pub enum Error { ConnectUnsupported, #[error("a field contained invalid Unicode: {0}")] CharacterEncoding(#[from] std::string::FromUtf8Error), + #[error("read a response when expecting a request")] + ExpectedRequest, + #[error("read a request when expecting a response")] + ExpectedResponse, #[error("a field contained an integer value that was out of range: {0}")] IntRange(#[from] std::num::TryFromIntError), #[error("the mode of the message was invalid")] InvalidMode, + #[error("the status code of a response needs to be in 100..=599")] + InvalidStatus, #[error("IO error {0}")] Io(#[from] std::io::Error), #[error("a field or line was missing a necessary character 0x{0:x}")] diff --git a/third_party/rust/bhttp/src/lib.rs b/third_party/rust/bhttp/src/lib.rs @@ -10,6 +10,7 @@ use std::convert::TryFrom; feature = "write-bhttp" ))] use std::io; + #[cfg(feature = "read-http")] use url::Url; @@ -18,6 +19,9 @@ mod parse; #[cfg(any(feature = "read-bhttp", feature = "write-bhttp"))] mod rw; +#[cfg(any(feature = "read-http", feature = "read-bhttp",))] +use std::borrow::BorrowMut; + pub use err::Error; #[cfg(any( feature = "read-http", @@ -33,8 +37,6 @@ use parse::{index_of, trim_ows, COMMA}; use rw::{read_varint, read_vec}; #[cfg(feature = "write-bhttp")] use rw::{write_len, write_varint, write_vec}; -#[cfg(any(feature = "read-http", feature = "read-bhttp",))] -use std::borrow::BorrowMut; #[cfg(feature = "read-http")] const CONTENT_LENGTH: &[u8] = b"content-length"; @@ -43,7 +45,48 @@ const COOKIE: &[u8] = b"cookie"; const TRANSFER_ENCODING: &[u8] = b"transfer-encoding"; const CHUNKED: &[u8] = b"chunked"; -pub type StatusCode = u16; +#[derive(Clone, Copy, PartialEq, Eq)] +pub struct StatusCode(u16); + +impl StatusCode { + pub const OK: Self = StatusCode(200); + + #[must_use] + pub fn informational(self) -> bool { + matches!(self.0, 100..=199) + } + + #[must_use] + pub fn code(self) -> u16 { + self.0 + } +} + +impl TryFrom<u64> for StatusCode { + type Error = Error; + + fn try_from(value: u64) -> Result<Self, Self::Error> { + Self::try_from(u16::try_from(value).map_err(|_| Error::InvalidStatus)?) + } +} + +impl TryFrom<u16> for StatusCode { + type Error = Error; + + fn try_from(value: u16) -> Result<Self, Self::Error> { + if matches!(value, 100..=599) { + Ok(Self(value)) + } else { + Err(Error::InvalidStatus) + } + } +} + +impl From<StatusCode> for u16 { + fn from(value: StatusCode) -> Self { + value.code() + } +} pub trait ReadSeek: io::BufRead + io::Seek {} impl<T> ReadSeek for io::Cursor<T> where T: AsRef<[u8]> {} @@ -53,7 +96,7 @@ impl<T> ReadSeek for io::BufReader<T> where T: io::Read + io::Seek {} #[cfg(any(feature = "read-bhttp", feature = "write-bhttp"))] pub enum Mode { KnownLength, - IndefiniteLength, + IndeterminateLength, } pub struct Field { @@ -386,7 +429,7 @@ impl ControlData { if index_of(SLASH, &a).is_some() { // Probably a response, so treat it as such. let status_str = String::from_utf8(b)?; - let code = status_str.parse::<u16>()?; + let code = StatusCode::try_from(status_str.parse::<u64>()?)?; Ok(Self::Response(code)) } else if index_of(COLON, &b).is_some() { // Now try to parse the URL. @@ -442,7 +485,9 @@ impl ControlData { path, } } else { - Self::Response(u16::try_from(read_varint(r)?.ok_or(Error::Truncated)?)?) + Self::Response(StatusCode::try_from( + read_varint(r)?.ok_or(Error::Truncated)?, + )?) }; Ok(v) } @@ -452,7 +497,7 @@ impl ControlData { #[must_use] fn informational(&self) -> Option<StatusCode> { match self { - Self::Response(v) if *v >= 100 && *v < 200 => Some(*v), + Self::Response(v) if v.informational() => Some(*v), _ => None, } } @@ -463,8 +508,8 @@ impl ControlData { match (self, mode) { (Self::Request { .. }, Mode::KnownLength) => 0, (Self::Response(_), Mode::KnownLength) => 1, - (Self::Request { .. }, Mode::IndefiniteLength) => 2, - (Self::Response(_), Mode::IndefiniteLength) => 3, + (Self::Request { .. }, Mode::IndeterminateLength) => 2, + (Self::Response(_), Mode::IndeterminateLength) => 3, } } @@ -482,7 +527,7 @@ impl ControlData { write_vec(authority, w)?; write_vec(path, w)?; } - Self::Response(status) => write_varint(*status, w)?, + Self::Response(status) => write_varint(status.code(), w)?, } Ok(()) } @@ -507,7 +552,7 @@ impl ControlData { w.write_all(b" HTTP/1.1\r\n")?; } Self::Response(status) => { - let buf = format!("HTTP/1.1 {} Reason\r\n", *status); + let buf = format!("HTTP/1.1 {} Reason\r\n", status.code()); w.write_all(buf.as_bytes())?; } } @@ -538,7 +583,7 @@ impl InformationalResponse { #[cfg(feature = "write-bhttp")] fn write_bhttp(&self, mode: Mode, w: &mut impl io::Write) -> Res<()> { - write_varint(self.status, w)?; + write_varint(self.status.code(), w)?; self.fields.write_bhttp(mode, w)?; Ok(()) } @@ -660,30 +705,31 @@ impl Message { let mut header = FieldSection::read_http(r)?; - let (content, trailer) = if matches!(control.status(), Some(204) | Some(304)) { - // 204 and 304 have no body, no matter what Content-Length says. - // Unfortunately, we can't do the same for responses to HEAD. - (Vec::new(), FieldSection::default()) - } else if header.is_chunked() { - let content = Self::read_chunked(r)?; - let trailer = FieldSection::read_http(r)?; - (content, trailer) - } else { - let mut content = Vec::new(); - if let Some(cl) = header.get(CONTENT_LENGTH) { - let cl_str = String::from_utf8(Vec::from(cl))?; - let cl_int = cl_str.parse::<usize>()?; - if cl_int > 0 { - content.resize(cl_int, 0); - r.borrow_mut().read_exact(&mut content)?; - } + let (content, trailer) = + if matches!(control.status().map(StatusCode::code), Some(204 | 304)) { + // 204 and 304 have no body, no matter what Content-Length says. + // Unfortunately, we can't do the same for responses to HEAD. + (Vec::new(), FieldSection::default()) + } else if header.is_chunked() { + let content = Self::read_chunked(r)?; + let trailer = FieldSection::read_http(r)?; + (content, trailer) } else { - // Note that for a request, the spec states that the content is - // empty, but this just reads all input like for a response. - r.borrow_mut().read_to_end(&mut content)?; - } - (content, FieldSection::default()) - }; + let mut content = Vec::new(); + if let Some(cl) = header.get(CONTENT_LENGTH) { + let cl_str = String::from_utf8(Vec::from(cl))?; + let cl_int = cl_str.parse::<usize>()?; + if cl_int > 0 { + content.resize(cl_int, 0); + r.borrow_mut().read_exact(&mut content)?; + } + } else { + // Note that for a request, the spec states that the content is + // empty, but this just reads all input like for a response. + r.borrow_mut().read_to_end(&mut content)?; + } + (content, FieldSection::default()) + }; header.strip_connection_headers(); Ok(Self { @@ -734,7 +780,7 @@ impl Message { let request = t == 0 || t == 2; let mode = match t { 0 | 1 => Mode::KnownLength, - 2 | 3 => Mode::IndefiniteLength, + 2 | 3 => Mode::IndeterminateLength, _ => return Err(Error::InvalidMode), }; @@ -748,7 +794,7 @@ impl Message { let header = FieldSection::read_bhttp(mode, r)?; let mut content = read_vec(r)?.unwrap_or_default(); - if mode == Mode::IndefiniteLength && !content.is_empty() { + if mode == Mode::IndeterminateLength && !content.is_empty() { loop { let mut extra = read_vec(r)?.unwrap_or_default(); if extra.is_empty() { @@ -779,7 +825,7 @@ impl Message { self.header.write_bhttp(mode, w)?; write_vec(&self.content, w)?; - if mode == Mode::IndefiniteLength && !self.content.is_empty() { + if mode == Mode::IndeterminateLength && !self.content.is_empty() { write_len(0, w)?; } self.trailer.write_bhttp(mode, w)?; diff --git a/third_party/rust/bhttp/src/parse.rs b/third_party/rust/bhttp/src/parse.rs @@ -56,7 +56,7 @@ pub fn index_of(v: u8, line: &[u8]) -> Option<usize> { pub fn split_at(v: u8, mut line: Vec<u8>) -> Option<(Vec<u8>, Vec<u8>)> { index_of(v, &line).map(|i| { let tail = line.split_off(i + 1); - let _ = line.pop(); + _ = line.pop(); (line, tail) }) } diff --git a/third_party/rust/bhttp/src/rw.rs b/third_party/rust/bhttp/src/rw.rs @@ -1,18 +1,17 @@ -use crate::err::Res; -#[cfg(feature = "read-bhttp")] -use crate::{err::Error, ReadSeek}; #[cfg(feature = "read-bhttp")] use std::borrow::BorrowMut; use std::{convert::TryFrom, io}; +use crate::err::Res; +#[cfg(feature = "read-bhttp")] +use crate::{err::Error, ReadSeek}; + #[cfg(feature = "write-bhttp")] #[allow(clippy::cast_possible_truncation)] -fn write_uint(n: u8, v: impl Into<u64>, w: &mut impl io::Write) -> Res<()> { - let v = v.into(); - assert!(n > 0 && usize::from(n) < std::mem::size_of::<u64>()); - for i in 0..n { - w.write_all(&[((v >> (8 * (n - i - 1))) & 0xff) as u8])?; - } +pub(crate) fn write_uint<const N: usize>(v: impl Into<u64>, w: &mut impl io::Write) -> Res<()> { + let v = v.into().to_be_bytes(); + assert!((1..=std::mem::size_of::<u64>()).contains(&N)); + w.write_all(&v[std::mem::size_of::<u64>() - N..])?; Ok(()) } @@ -20,11 +19,11 @@ fn write_uint(n: u8, v: impl Into<u64>, w: &mut impl io::Write) -> Res<()> { pub fn write_varint(v: impl Into<u64>, w: &mut impl io::Write) -> Res<()> { let v = v.into(); match () { - _ if v < (1 << 6) => write_uint(1, v, w), - _ if v < (1 << 14) => write_uint(2, v | (1 << 14), w), - _ if v < (1 << 30) => write_uint(4, v | (2 << 30), w), - _ if v < (1 << 62) => write_uint(8, v | (3 << 62), w), - _ => panic!("Varint value too large"), + () if v < (1 << 6) => write_uint::<1>(v, w), + () if v < (1 << 14) => write_uint::<2>(v | (1 << 14), w), + () if v < (1 << 30) => write_uint::<4>(v | (2 << 30), w), + () if v < (1 << 62) => write_uint::<8>(v | (3 << 62), w), + () => panic!("varint value too large"), } } @@ -49,15 +48,16 @@ where let mut buf = [0; 7]; let count = r.borrow_mut().read(&mut buf[..n])?; if count == 0 { - return Ok(None); + Ok(None) } else if count < n { - return Err(Error::Truncated); - } - let mut v = 0; - for i in &buf[..n] { - v = (v << 8) | u64::from(*i); + Err(Error::Truncated) + } else { + let mut v = 0; + for i in &buf[..n] { + v = (v << 8) | u64::from(*i); + } + Ok(Some(v)) } - Ok(Some(v)) } #[cfg(feature = "read-bhttp")] @@ -95,7 +95,7 @@ where if end - pos < len { return Err(Error::Truncated); } - let _ = r.seek(SeekFrom::Start(pos))?; + _ = r.seek(SeekFrom::Start(pos))?; let mut v = vec![0; usize::try_from(len)?]; r.read_exact(&mut v)?; @@ -104,3 +104,67 @@ where Ok(None) } } + +#[cfg(test)] +mod test { + use std::io::Cursor; + + use super::{read_varint, write_varint}; + use crate::{rw::read_vec, Error}; + + #[test] + fn basics() { + for i in [ + 0_u64, + 1, + 17, + 63, + 64, + 100, + 0x3fff, + 0x4000, + 0x1_0002, + 0x3fff_ffff, + 0x4000_0000, + 0x3456_dead_beef, + 0x3fff_ffff_ffff_ffff, + ] { + let mut buf = Vec::new(); + write_varint(i, &mut buf).unwrap(); + let sz_bytes = (64 - i.leading_zeros() + 2).div_ceil(8); // +2 size bits, rounded up + assert_eq!( + buf.len(), + usize::try_from(sz_bytes.next_power_of_two()).unwrap() + ); + + let o = read_varint(&mut Cursor::new(buf.clone())).unwrap(); + assert_eq!(Some(i), o); + + for cut in 1..buf.len() { + let e = read_varint(&mut Cursor::new(buf[..cut].to_vec())).unwrap_err(); + assert!(matches!(e, Error::Truncated)); + } + } + } + + #[test] + fn read_nothing() { + let o = read_varint(&mut Cursor::new(Vec::new())).unwrap(); + assert!(o.is_none()); + } + + #[test] + #[should_panic(expected = "varint value too large")] + fn too_big() { + std::mem::drop(write_varint(0x4000_0000_0000_0000_u64, &mut Vec::new())); + } + + #[test] + fn too_big_vec() { + let mut buf = Vec::new(); + write_varint(10_u64, &mut buf).unwrap(); + buf.resize(10, 0); // Not enough extra for the promised length. + let e = read_vec(&mut Cursor::new(buf.clone())).unwrap_err(); + assert!(matches!(e, Error::Truncated)); + } +} diff --git a/third_party/rust/bhttp/tests/test.rs b/third_party/rust/bhttp/tests/test.rs @@ -1,9 +1,10 @@ // Rather than grapple with #[cfg(...)] for every variable and import. #![cfg(all(feature = "http", feature = "bhttp"))] -use bhttp::{Error, Message, Mode}; use std::{io::Cursor, mem::drop}; +use bhttp::{Error, Message, Mode}; + const CHUNKED_HTTP: &[u8] = b"HTTP/1.1 200 OK\r\n\ Transfer-Encoding: camel, chunked\r\n\ \r\n\ @@ -23,7 +24,7 @@ const CHUNKED_KNOWN: &[u8] = &[ 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x43, 0x52, 0x4c, 0x46, 0x2e, 0x0d, 0x0a, 0x0d, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, 0x65, 0x72, 0x04, 0x74, 0x65, 0x78, 0x74, ]; -const CHUNKED_INDEFINITE: &[u8] = &[ +const CHUNKED_INDETERMINATE: &[u8] = &[ 0x03, 0x40, 0xc8, 0x00, 0x1d, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x43, 0x52, 0x4c, 0x46, 0x2e, 0x0d, 0x0a, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, 0x65, 0x72, 0x04, 0x74, 0x65, 0x78, 0x74, @@ -58,8 +59,8 @@ fn chunked_read_known() { } #[test] -fn chunked_read_indefinite() { - drop(Message::read_bhttp(&mut Cursor::new(CHUNKED_INDEFINITE)).unwrap()); +fn chunked_read_indeterminate() { + drop(Message::read_bhttp(&mut Cursor::new(CHUNKED_INDETERMINATE)).unwrap()); } #[test] @@ -74,14 +75,14 @@ fn chunked_to_known() { } #[test] -fn chunked_to_indefinite() { +fn chunked_to_indeterminate() { let m = Message::read_http(&mut Cursor::new(CHUNKED_HTTP)).unwrap(); assert!(m.header().get(TRANSFER_ENCODING).is_none()); let mut buf = Vec::new(); - m.write_bhttp(Mode::IndefiniteLength, &mut buf).unwrap(); + m.write_bhttp(Mode::IndeterminateLength, &mut buf).unwrap(); println!("result: {}", hex::encode(&buf)); - assert_eq!(&buf[..], CHUNKED_INDEFINITE); + assert_eq!(&buf[..], CHUNKED_INDETERMINATE); } #[test] @@ -137,7 +138,7 @@ fn tiny_response() { const RESPONSE: &[u8] = &[0x01, 0x40, 0xc8]; let m = Message::read_bhttp(&mut Cursor::new(RESPONSE)).unwrap(); assert!(m.informational().is_empty()); - assert_eq!(m.control().status().unwrap(), 200); + assert_eq!(m.control().status().unwrap().code(), 200); assert!(m.control().method().is_none()); assert!(m.control().scheme().is_none()); assert!(m.control().authority().is_none()); diff --git a/third_party/rust/ohttp/.cargo-checksum.json b/third_party/rust/ohttp/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.lock":"622e3baf2dfa2877383d36bfa4533f6f25503bfadc8a4a8dc575a349d5431979","Cargo.toml":"5260b29fc57caee665b6454d4d7b7e478e7a01699886c11cab3f0bba89f353c1","README.md":"ca2de60828b7ec7d80729fd3e064cd8e08e3a72a94a50f29b7f4bd23b044fdbd","bindings/bindings.toml":"a016870127b63151e760c964d687934a4883ee165bdd9718341c8dd50be5a3f2","bindings/nspr_err.h":"2d5205d017b536c2d838bcf9bc4ec79f96dd50e7bb9b73892328781f1ee6629d","bindings/nspr_error.h":"e41c03c77b8c22046f8618832c9569fbcc7b26d8b9bbc35eea7168f35e346889","bindings/nss_init.h":"cd4dffd0c629ece5786736dd6d26db8a96f56fd56ef95b150c623c41080c2f9e","bindings/nss_p11.h":"a16f60d0210d5823f2d92d0c04988a0bb1da85901388490cb3e755a62cc7d5dd","bindings/nss_secerr.h":"713e8368bdae5159af7893cfa517dabfe5103cede051dee9c9557c850a2defc6","build.rs":"4a107baae67552e72f4db35a6dfdcef2101ff38350130f33ff37c882f542b934","src/config.rs":"bea6c3af58f3d03e9c06fa008523c57b6ea71a3c37a575823719418ea50e2072","src/err.rs":"533b382c7e74906521395fdff4b514981535fe1b45b307528c547bb545765adf","src/hpke.rs":"b98b3a1d2e87bd89d43d89e2513e2d3211832aef3fd2157337939186aa7c8531","src/lib.rs":"bfc972343aa3fa6707b0aaea04c25f1b6fa2ff3f9e9761ae6a09f9be52fce214","src/nss/aead.rs":"1c7982c7020eaa573fe5b9b713ec8134057269a9c369b9632040ebfad562befa","src/nss/err.rs":"d367116bf9840ebe06d358066a1755f7d9936438dbc2e4e71a6b345d05e4bcd5","src/nss/hkdf.rs":"fe66619f75affd4b812494c1433411b382a49b4bfbad5c0ac4deea89fea8065b","src/nss/hpke.rs":"cbd353d2f0c8db82fcf25dac2f2d2554e8a6258c4b21e0279e618fb2f992c49c","src/nss/mod.rs":"0308592fbc48ecf7cd13a92f2b0cea29fbcd9b8082586cee21d36329bf71042a","src/nss/p11.rs":"e3404eb484906fd7fa97f91cc8740f6660f9a064d229c5d16b6a74efa37ecfee","src/rand.rs":"be3a82fb6090b5cb833c2b8ba6e72690b9f44f7f91477e2c5b70b75623174b87","src/rh/aead.rs":"88dd43ffec20a8870a424d27dbda0a9db74f4b3d1b03097220854a304ab091cd","src/rh/hkdf.rs":"4c6e59ca24498939e9b8da2da6336ae2f62396101f1b9b25f1ae587ab21c1a9d","src/rh/hpke.rs":"1eff4bb08f3d6ac6fb0cc75e1c05785e58d5c0a436227d0b0e48ead6b5ed77ed","src/rh/mod.rs":"850772462778a74fd7402b4bb765ad57011b02729e6aa1bb3236afd490e5c3a4"},"package":"a4a87f4e4cd78d1619b98b6119cde887d20489f70339b9425af080b00db714b6"} -\ No newline at end of file +{"files":{"Cargo.toml":"74baeadbe2810a83b2e49bab9ea7069bc033873b83a9e8cee16adee94bba73d6","README.md":"ca2de60828b7ec7d80729fd3e064cd8e08e3a72a94a50f29b7f4bd23b044fdbd","bindings/bindings.toml":"a016870127b63151e760c964d687934a4883ee165bdd9718341c8dd50be5a3f2","bindings/nspr_err.h":"2d5205d017b536c2d838bcf9bc4ec79f96dd50e7bb9b73892328781f1ee6629d","bindings/nspr_error.h":"e41c03c77b8c22046f8618832c9569fbcc7b26d8b9bbc35eea7168f35e346889","bindings/nss_init.h":"cd4dffd0c629ece5786736dd6d26db8a96f56fd56ef95b150c623c41080c2f9e","bindings/nss_p11.h":"a16f60d0210d5823f2d92d0c04988a0bb1da85901388490cb3e755a62cc7d5dd","bindings/nss_secerr.h":"713e8368bdae5159af7893cfa517dabfe5103cede051dee9c9557c850a2defc6","build.rs":"4a107baae67552e72f4db35a6dfdcef2101ff38350130f33ff37c882f542b934","src/config.rs":"bea6c3af58f3d03e9c06fa008523c57b6ea71a3c37a575823719418ea50e2072","src/err.rs":"f94da3b7d148e491471d5b6b0d450597b5e3ea05126576352b2879b446ff1430","src/hpke.rs":"d09e673a967f76e59f0b9c9d4c8ad25a9cf1f580dc7ebbdcbefc03f30e0642e7","src/lib.rs":"bfc972343aa3fa6707b0aaea04c25f1b6fa2ff3f9e9761ae6a09f9be52fce214","src/nss/aead.rs":"4bab67456c774f557035c01f5fb10be61f76c95ce4d7773d599268dba4527ec2","src/nss/err.rs":"d367116bf9840ebe06d358066a1755f7d9936438dbc2e4e71a6b345d05e4bcd5","src/nss/hkdf.rs":"fe66619f75affd4b812494c1433411b382a49b4bfbad5c0ac4deea89fea8065b","src/nss/hpke.rs":"e9dc855fa5c91a57d86c32859ab2f5e0c6f51bb2e97ac5710a5ce5152e1f2082","src/nss/mod.rs":"0308592fbc48ecf7cd13a92f2b0cea29fbcd9b8082586cee21d36329bf71042a","src/nss/p11.rs":"f6e68fe5a81271db63fd11e601bc83e5dca3b589064b528bc50403eaccf8c627","src/rand.rs":"be3a82fb6090b5cb833c2b8ba6e72690b9f44f7f91477e2c5b70b75623174b87","src/rh/aead.rs":"88dd43ffec20a8870a424d27dbda0a9db74f4b3d1b03097220854a304ab091cd","src/rh/hkdf.rs":"4c6e59ca24498939e9b8da2da6336ae2f62396101f1b9b25f1ae587ab21c1a9d","src/rh/hpke.rs":"0de3fd7a12ff551308a5ce6ad04cf077296571c265ddd3083d62b2bf7e51f70d","src/rh/mod.rs":"850772462778a74fd7402b4bb765ad57011b02729e6aa1bb3236afd490e5c3a4"},"package":null} +\ No newline at end of file diff --git a/third_party/rust/ohttp/Cargo.lock b/third_party/rust/ohttp/Cargo.lock @@ -1,1013 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aead" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" -dependencies = [ - "generic-array", - "rand_core", -] - -[[package]] -name = "aead" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" -dependencies = [ - "crypto-common", - "generic-array", -] - -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures 0.2.17", - "opaque-debug", -] - -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher 0.4.4", - "cpufeatures 0.2.17", -] - -[[package]] -name = "aes-gcm" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc3be92e19a7ef47457b8e6f90707e12b6ac5d20c6f3866584fa3be0787d839f" -dependencies = [ - "aead 0.4.3", - "aes 0.7.5", - "cipher 0.3.0", - "ctr 0.7.0", - "ghash 0.4.4", - "subtle", -] - -[[package]] -name = "aes-gcm" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" -dependencies = [ - "aead 0.5.2", - "aes 0.8.4", - "cipher 0.4.4", - "ctr 0.9.2", - "ghash 0.5.1", - "subtle", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "bindgen" -version = "0.69.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "itertools", - "lazy_static", - "lazycell", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", -] - -[[package]] -name = "bitflags" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chacha20" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee7ad89dc1128635074c268ee661f90c3f7e83d9fd12910608c36b47d6c3412" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures 0.1.5", - "zeroize", -] - -[[package]] -name = "chacha20" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" -dependencies = [ - "cfg-if", - "cipher 0.4.4", - "cpufeatures 0.2.17", -] - -[[package]] -name = "chacha20poly1305" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1580317203210c517b6d44794abfbe600698276db18127e37ad3e69bf5e848e5" -dependencies = [ - "aead 0.4.3", - "chacha20 0.7.1", - "cipher 0.3.0", - "poly1305 0.7.2", - "zeroize", -] - -[[package]] -name = "chacha20poly1305" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" -dependencies = [ - "aead 0.5.2", - "chacha20 0.9.1", - "cipher 0.4.4", - "poly1305 0.8.0", - "zeroize", -] - -[[package]] -name = "cipher" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" -dependencies = [ - "generic-array", -] - -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", - "zeroize", -] - -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "cpufeatures" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" -dependencies = [ - "libc", -] - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "rand_core", - "typenum", -] - -[[package]] -name = "crypto-mac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25fab6889090c8133f3deb8f73ba3c65a7f456f66436fc012a1b1e272b1e103e" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "ctr" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a232f92a03f37dd7d7dd2adc67166c77e9cd88de5b019b9a9eecfaeaf7bfd481" -dependencies = [ - "cipher 0.3.0", -] - -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher 0.4.4", -] - -[[package]] -name = "curve25519-dalek" -version = "4.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "curve25519-dalek-derive", - "fiat-crypto", - "rustc_version", - "subtle", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "crypto-common", - "subtle", -] - -[[package]] -name = "either" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7914353092ddf589ad78f25c5c1c21b7f80b0ff8621e7c814c3485b5306da9d" - -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "log", -] - -[[package]] -name = "fiat-crypto" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "ghash" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" -dependencies = [ - "opaque-debug", - "polyval 0.5.3", -] - -[[package]] -name = "ghash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" -dependencies = [ - "opaque-debug", - "polyval 0.6.2", -] - -[[package]] -name = "glob" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hkdf" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01706d578d5c281058480e673ae4086a9f4710d8df1ad80a5b03e39ece5f886b" -dependencies = [ - "digest 0.9.0", - "hmac 0.11.0", -] - -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac 0.12.1", -] - -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest 0.9.0", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "hpke" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e04a5933a381bb81f00b083fce6b4528e16d735dbeecbb2bdb45e0dbbf3f7e17" -dependencies = [ - "aead 0.5.2", - "aes-gcm 0.10.3", - "byteorder", - "chacha20poly1305 0.10.1", - "digest 0.10.7", - "generic-array", - "hkdf 0.12.4", - "hmac 0.12.1", - "rand_core", - "sha2 0.10.8", - "subtle", - "x25519-dalek", - "zeroize", -] - -[[package]] -name = "hpke_pq" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b405447b60d50d27aaaba4fb6d7888d63868dcc4f3409bf6c4250360de07ba" -dependencies = [ - "aead 0.5.2", - "aes-gcm 0.10.3", - "byteorder", - "chacha20poly1305 0.10.1", - "digest 0.10.7", - "generic-array", - "hkdf 0.12.4", - "hmac 0.12.1", - "rand_core", - "safe_pqc_kyber", - "sha2 0.10.8", - "subtle", - "x25519-dalek", - "zeroize", -] - -[[package]] -name = "inout" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" -dependencies = [ - "generic-array", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.170" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" - -[[package]] -name = "libloading" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "log" -version = "0.4.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "mozbuild" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "903970ae2f248d7275214cf8f387f8ba0c4ea7e3d87a320e85493db60ce28616" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "ohttp" -version = "0.6.0" -dependencies = [ - "aead 0.4.3", - "aes-gcm 0.9.2", - "bindgen", - "byteorder", - "chacha20poly1305 0.8.0", - "env_logger", - "hex", - "hkdf 0.11.0", - "hpke", - "hpke_pq", - "log", - "mozbuild", - "rand", - "regex", - "serde", - "serde_derive", - "sha2 0.9.9", - "thiserror", - "toml", -] - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "poly1305" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" -dependencies = [ - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash 0.4.0", -] - -[[package]] -name = "poly1305" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" -dependencies = [ - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash 0.5.1", -] - -[[package]] -name = "polyval" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash 0.4.0", -] - -[[package]] -name = "polyval" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash 0.5.1", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "regex" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - -[[package]] -name = "safe_pqc_kyber" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "108c4ad7fe882cbb078ff40de415658e9d827f636e4fb17e7d5a97503a9aceaf" -dependencies = [ - "rand_core", -] - -[[package]] -name = "semver" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" - -[[package]] -name = "serde" -version = "1.0.218" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.218" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures 0.2.17", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "digest 0.10.7", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - -[[package]] -name = "unicode-ident" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe" - -[[package]] -name = "universal-hash" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" -dependencies = [ - "crypto-common", - "subtle", -] - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "x25519-dalek" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" -dependencies = [ - "curve25519-dalek", - "rand_core", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/third_party/rust/ohttp/Cargo.toml b/third_party/rust/ohttp/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.81.0" +rust-version = "1.82.0" name = "ohttp" -version = "0.6.0" +version = "0.6.1" authors = ["Martin Thomson <mt@lowentropy.net>"] build = "build.rs" autolib = false @@ -23,7 +23,7 @@ autotests = false autobenches = false description = "Oblivious HTTP" homepage = "https://github.com/martinthomson/ohttp" -readme = "README.md" +readme = "../README.md" keywords = [ "ohttp", "http", @@ -52,7 +52,6 @@ gecko = [ "mozbuild", ] nss = ["bindgen"] -pq = ["hpke-pq"] rust-hpke = [ "rand", "aead", @@ -69,6 +68,11 @@ unsafe-print-secrets = [] name = "ohttp" path = "src/lib.rs" +[dependencies] +byteorder = "1.4" +hex = "0.4" +thiserror = "1" + [dependencies.aead] version = "0.4" features = ["std"] @@ -78,16 +82,10 @@ optional = true version = "0.9" optional = true -[dependencies.byteorder] -version = "1.4" - [dependencies.chacha20poly1305] version = "0.8" optional = true -[dependencies.hex] -version = "0.4" - [dependencies.hkdf] version = "0.11" optional = true @@ -101,17 +99,6 @@ features = [ optional = true default-features = false -[dependencies.hpke-pq] -version = "0.11.0" -features = [ - "std", - "x25519", - "xyber768d00", -] -optional = true -default-features = false -package = "hpke_pq" - [dependencies.log] version = "0.4" default-features = false @@ -128,15 +115,17 @@ optional = true version = "0.9" optional = true -[dependencies.thiserror] -version = "1" - [dev-dependencies.env_logger] version = "0.10" default-features = false +[build-dependencies] +serde = "1.0" +serde_derive = "1.0" +toml = "0.5" + [build-dependencies.bindgen] -version = "0.69" +version = "0.72" features = ["runtime"] optional = true default-features = false @@ -144,12 +133,3 @@ default-features = false [build-dependencies.mozbuild] version = "0.1" optional = true - -[build-dependencies.serde] -version = "1.0" - -[build-dependencies.serde_derive] -version = "1.0" - -[build-dependencies.toml] -version = "0.5" diff --git a/third_party/rust/ohttp/src/err.rs b/third_party/rust/ohttp/src/err.rs @@ -10,12 +10,9 @@ pub enum Error { Crypto(#[from] crate::nss::Error), #[error("an error was found in the format")] Format, - #[cfg(all(feature = "rust-hpke", not(feature = "pq")))] + #[cfg(feature = "rust-hpke")] #[error("a problem occurred with HPKE: {0}")] Hpke(#[from] ::hpke::HpkeError), - #[cfg(all(feature = "rust-hpke", feature = "pq"))] - #[error("a problem occurred with HPKE: {0}")] - Hpke(#[from] ::hpke_pq::HpkeError), #[error("an internal error occurred")] Internal, #[error("the wrong type of key was provided for the selected KEM")] diff --git a/third_party/rust/ohttp/src/hpke.rs b/third_party/rust/ohttp/src/hpke.rs @@ -32,9 +32,6 @@ macro_rules! convert_enum { convert_enum! { pub enum Kem { X25519Sha256 = 32, - - #[cfg(feature = "pq")] - X25519Kyber768Draft00 = 48, } } @@ -43,9 +40,6 @@ impl Kem { pub fn n_enc(self) -> usize { match self { Kem::X25519Sha256 => 32, - - #[cfg(feature = "pq")] - Kem::X25519Kyber768Draft00 => 1120, } } @@ -53,9 +47,6 @@ impl Kem { pub fn n_pk(self) -> usize { match self { Kem::X25519Sha256 => 32, - - #[cfg(feature = "pq")] - Kem::X25519Kyber768Draft00 => 1216, } } } diff --git a/third_party/rust/ohttp/src/nss/aead.rs b/third_party/rust/ohttp/src/nss/aead.rs @@ -1,3 +1,11 @@ +use std::{ + convert::{TryFrom, TryInto}, + mem, + os::raw::c_int, +}; + +use log::trace; + use super::{ err::secstatus_to_res, p11::{ @@ -13,12 +21,6 @@ use crate::{ err::{Error, Res}, hpke::Aead as AeadId, }; -use log::trace; -use std::{ - convert::{TryFrom, TryInto}, - mem, - os::raw::c_int, -}; /// All the nonces are the same length. Exploit that. pub const NONCE_LEN: usize = 12; @@ -143,7 +145,7 @@ impl Aead { aad.as_ptr(), c_int_len(aad.len()), ct.as_mut_ptr(), - &mut ct_len, + &raw mut ct_len, c_int_len(ct.len()), // signed :( tag.as_mut_ptr(), c_int_len(tag.len()), @@ -176,7 +178,7 @@ impl Aead { aad.as_ptr(), c_int_len(aad.len()), pt.as_mut_ptr(), - &mut pt_len, + &raw mut pt_len, c_int_len(pt.len()), // signed :( ct.as_ptr().add(pt_expected).cast_mut(), // const cast :( c_int_len(TAG_LEN), diff --git a/third_party/rust/ohttp/src/nss/hpke.rs b/third_party/rust/ohttp/src/nss/hpke.rs @@ -1,10 +1,3 @@ -use super::{ - super::hpke::{Aead, Kdf, Kem}, - err::{sec::SEC_ERROR_INVALID_ARGS, secstatus_to_res, Error}, - p11::{sys, Item, PrivateKey, PublicKey, Slot, SymKey}, -}; -use crate::err::Res; -use log::{log_enabled, trace}; use std::{ convert::TryFrom, ops::Deref, @@ -12,8 +5,16 @@ use std::{ ptr::{addr_of_mut, null, null_mut}, }; +use log::{log_enabled, trace}; pub use sys::{HpkeAeadId as AeadId, HpkeKdfId as KdfId, HpkeKemId as KemId}; +use super::{ + super::hpke::{Aead, Kdf, Kem}, + err::{sec::SEC_ERROR_INVALID_ARGS, secstatus_to_res, Error}, + p11::{sys, Item, PrivateKey, PublicKey, Slot, SymKey}, +}; +use crate::err::Res; + /// Configuration for `Hpke`. #[derive(Clone, Copy)] pub struct Config { @@ -96,7 +97,7 @@ impl Exporter for HpkeContext { self.ptr, &Item::wrap(info), c_uint::try_from(len).unwrap(), - &mut out, + &raw mut out, ) })?; SymKey::from_ptr(out) @@ -138,7 +139,12 @@ impl HpkeS { pub fn seal(&mut self, aad: &[u8], pt: &[u8]) -> Res<Vec<u8>> { let mut out: *mut sys::SECItem = null_mut(); secstatus_to_res(unsafe { - sys::PK11_HPKE_Seal(*self.context, &Item::wrap(aad), &Item::wrap(pt), &mut out) + sys::PK11_HPKE_Seal( + *self.context, + &Item::wrap(aad), + &Item::wrap(pt), + &raw mut out, + ) })?; let v = Item::from_ptr(out)?; Ok(unsafe { v.into_vec() }) @@ -203,7 +209,7 @@ impl HpkeR { *context, k.as_ptr(), c_uint::try_from(k.len()).unwrap(), - &mut ptr, + &raw mut ptr, ) })?; PublicKey::from_ptr(ptr) @@ -212,7 +218,12 @@ impl HpkeR { pub fn open(&mut self, aad: &[u8], ct: &[u8]) -> Res<Vec<u8>> { let mut out: *mut sys::SECItem = null_mut(); secstatus_to_res(unsafe { - sys::PK11_HPKE_Open(*self.context, &Item::wrap(aad), &Item::wrap(ct), &mut out) + sys::PK11_HPKE_Open( + *self.context, + &Item::wrap(aad), + &Item::wrap(ct), + &raw mut out, + ) })?; let v = Item::from_ptr(out)?; Ok(unsafe { v.into_vec() }) @@ -256,7 +267,7 @@ pub fn generate_key_pair(kem: Kem) -> Res<(PrivateKey, PublicKey)> { *slot, sys::CK_MECHANISM_TYPE::from(sys::CKM_EC_KEY_PAIR_GEN), addr_of_mut!(wrapped).cast(), - &mut public_ptr, + &raw mut public_ptr, sys::PK11_ATTR_SESSION | sys::PK11_ATTR_INSENSITIVE | sys::PK11_ATTR_PUBLIC, sys::CK_FLAGS::from(sys::CKF_DERIVE), sys::CK_FLAGS::from(sys::CKF_DERIVE), @@ -273,7 +284,7 @@ pub fn generate_key_pair(kem: Kem) -> Res<(PrivateKey, PublicKey)> { *slot, sys::CK_MECHANISM_TYPE::from(sys::CKM_EC_KEY_PAIR_GEN), addr_of_mut!(wrapped).cast(), - &mut public_ptr, + &raw mut public_ptr, sys::PK11_ATTR_SESSION | sys::PK11_ATTR_SENSITIVE | sys::PK11_ATTR_PRIVATE, sys::CK_FLAGS::from(sys::CKF_DERIVE), sys::CK_FLAGS::from(sys::CKF_DERIVE), @@ -286,7 +297,7 @@ pub fn generate_key_pair(kem: Kem) -> Res<(PrivateKey, PublicKey)> { assert_eq!(secret_ptr.is_null(), public_ptr.is_null()); let sk = PrivateKey::from_ptr(secret_ptr)?; let pk = PublicKey::from_ptr(public_ptr)?; - trace!("Generated key pair: sk={:?} pk={:?}", sk, pk); + trace!("Generated key pair: sk={sk:?} pk={pk:?}"); Ok((sk, pk)) } diff --git a/third_party/rust/ohttp/src/nss/p11.rs b/third_party/rust/ohttp/src/nss/p11.rs @@ -87,7 +87,7 @@ impl PrivateKey { PK11ObjectType::PK11_TypePrivKey, (**self).cast(), CK_ATTRIBUTE_TYPE::from(CKA_VALUE), - &mut key_item, + &raw mut key_item, ) })?; let slc = unsafe { @@ -98,7 +98,7 @@ impl PrivateKey { // use the scoped `Item` implementation. This is OK as long as nothing // panics between `PK11_ReadRawAttribute` succeeding and here. unsafe { - SECITEM_FreeItem(&mut key_item, PRBool::from(false)); + SECITEM_FreeItem(&raw mut key_item, PRBool::from(false)); } Ok(key) } @@ -135,7 +135,7 @@ impl PublicKey { sys::PK11_HPKE_Serialize( **self, buf.as_mut_ptr(), - &mut len, + &raw mut len, c_uint::try_from(buf.len()).unwrap(), ) })?; diff --git a/third_party/rust/ohttp/src/rh/hpke.rs b/third_party/rust/ohttp/src/rh/hpke.rs @@ -1,13 +1,8 @@ use std::ops::Deref; -#[cfg(not(feature = "pq"))] use ::hpke as rust_hpke; -#[cfg(feature = "pq")] -use ::hpke_pq as rust_hpke; use ::rand::thread_rng; use log::trace; -#[cfg(feature = "pq")] -use rust_hpke::kem::X25519Kyber768Draft00; use rust_hpke::{ aead::{AeadCtxR, AeadCtxS, AeadTag, AesGcm128, ChaCha20Poly1305}, kdf::HkdfSha256, @@ -66,9 +61,6 @@ impl Default for Config { #[derive(Clone)] pub enum PublicKey { X25519(<X25519HkdfSha256 as KemTrait>::PublicKey), - - #[cfg(feature = "pq")] - X25519Kyber768Draft00(<X25519Kyber768Draft00 as KemTrait>::PublicKey), } impl PublicKey { @@ -76,9 +68,6 @@ impl PublicKey { pub fn key_data(&self) -> Res<Vec<u8>> { Ok(match self { Self::X25519(k) => Vec::from(k.to_bytes().as_slice()), - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(k) => Vec::from(k.to_bytes().as_slice()), }) } } @@ -97,9 +86,6 @@ impl std::fmt::Debug for PublicKey { #[derive(Clone)] pub enum PrivateKey { X25519(<X25519HkdfSha256 as KemTrait>::PrivateKey), - - #[cfg(feature = "pq")] - X25519Kyber768Draft00(<X25519Kyber768Draft00 as KemTrait>::PrivateKey), } impl PrivateKey { @@ -107,9 +93,6 @@ impl PrivateKey { pub fn key_data(&self) -> Res<Vec<u8>> { Ok(match self { Self::X25519(k) => Vec::from(k.to_bytes().as_slice()), - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(k) => Vec::from(k.to_bytes().as_slice()), }) } } @@ -132,25 +115,12 @@ enum SenderContextX25519HkdfSha256HkdfSha256 { ChaCha20Poly1305(Box<AeadCtxS<ChaCha20Poly1305, HkdfSha256, X25519HkdfSha256>>), } -#[cfg(feature = "pq")] -enum SenderContextX25519Kyber768Draft00HkdfSha256 { - AesGcm128(Box<AeadCtxS<AesGcm128, HkdfSha256, X25519Kyber768Draft00>>), -} - enum SenderContextX25519HkdfSha256 { HkdfSha256(SenderContextX25519HkdfSha256HkdfSha256), } -#[cfg(feature = "pq")] -enum SenderContextX25519Kyber768Draft00 { - HkdfSha256(SenderContextX25519Kyber768Draft00HkdfSha256), -} - enum SenderContext { X25519HkdfSha256(SenderContextX25519HkdfSha256), - - #[cfg(feature = "pq")] - X25519Kyber768Draft00(SenderContextX25519Kyber768Draft00), } impl SenderContext { @@ -168,14 +138,6 @@ impl SenderContext { let tag = context.seal_in_place_detached(plaintext, aad)?; Vec::from(tag.to_bytes().as_slice()) } - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(SenderContextX25519Kyber768Draft00::HkdfSha256( - SenderContextX25519Kyber768Draft00HkdfSha256::AesGcm128(context), - )) => { - let tag = context.seal_in_place_detached(plaintext, aad)?; - Vec::from(tag.to_bytes().as_slice()) - } }) } @@ -191,13 +153,6 @@ impl SenderContext { )) => { context.export(info, out_buf)?; } - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(SenderContextX25519Kyber768Draft00::HkdfSha256( - SenderContextX25519Kyber768Draft00HkdfSha256::AesGcm128(context), - )) => { - context.export(info, out_buf)?; - } } Ok(()) } @@ -275,17 +230,6 @@ impl HpkeS { SenderContextX25519HkdfSha256::HkdfSha256, SenderContextX25519HkdfSha256HkdfSha256::ChaCha20Poly1305, }, - - #[cfg(feature = "pq")] - { - Kem::X25519Kyber768Draft00 => X25519Kyber768Draft00, - Kdf::HkdfSha256 => HkdfSha256, - Aead::Aes128Gcm => AesGcm128, - PublicKey::X25519Kyber768Draft00, - SenderContext::X25519Kyber768Draft00, - SenderContextX25519Kyber768Draft00::HkdfSha256, - SenderContextX25519Kyber768Draft00HkdfSha256::AesGcm128, - }, ]}; Ok(Self { @@ -333,25 +277,12 @@ enum ReceiverContextX25519HkdfSha256HkdfSha256 { ChaCha20Poly1305(Box<AeadCtxR<ChaCha20Poly1305, HkdfSha256, X25519HkdfSha256>>), } -#[cfg(feature = "pq")] -enum ReceiverContextX25519Kyber768Draft00HkdfSha256 { - AesGcm128(Box<AeadCtxR<AesGcm128, HkdfSha256, X25519Kyber768Draft00>>), -} - enum ReceiverContextX25519HkdfSha256 { HkdfSha256(ReceiverContextX25519HkdfSha256HkdfSha256), } -#[cfg(feature = "pq")] -enum ReceiverContextX25519Kyber768Draft00 { - HkdfSha256(ReceiverContextX25519Kyber768Draft00HkdfSha256), -} - enum ReceiverContext { X25519HkdfSha256(ReceiverContextX25519HkdfSha256), - - #[cfg(feature = "pq")] - X25519Kyber768Draft00(ReceiverContextX25519Kyber768Draft00), } impl ReceiverContext { @@ -381,20 +312,6 @@ impl ReceiverContext { context.open_in_place_detached(ct, aad, &tag)?; ct } - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(ReceiverContextX25519Kyber768Draft00::HkdfSha256( - ReceiverContextX25519Kyber768Draft00HkdfSha256::AesGcm128(context), - )) => { - if ciphertext.len() < AeadTag::<AesGcm128>::size() { - return Err(Error::Truncated); - } - let (ct, tag_slice) = - ciphertext.split_at_mut(ciphertext.len() - AeadTag::<AesGcm128>::size()); - let tag = AeadTag::<AesGcm128>::from_bytes(tag_slice)?; - context.open_in_place_detached(ct, aad, &tag)?; - ct - } }) } @@ -410,13 +327,6 @@ impl ReceiverContext { )) => { context.export(info, out_buf)?; } - - #[cfg(feature = "pq")] - Self::X25519Kyber768Draft00(ReceiverContextX25519Kyber768Draft00::HkdfSha256( - ReceiverContextX25519Kyber768Draft00HkdfSha256::AesGcm128(context), - )) => { - context.export(info, out_buf)?; - } } Ok(()) } @@ -491,17 +401,6 @@ impl HpkeR { ReceiverContextX25519HkdfSha256::HkdfSha256, ReceiverContextX25519HkdfSha256HkdfSha256::ChaCha20Poly1305, }, - - #[cfg(feature = "pq")] - { - Kem::X25519Kyber768Draft00 => X25519Kyber768Draft00, - Kdf::HkdfSha256 => HkdfSha256, - Aead::Aes128Gcm => AesGcm128, - PrivateKey::X25519Kyber768Draft00, - ReceiverContext::X25519Kyber768Draft00, - ReceiverContextX25519Kyber768Draft00::HkdfSha256, - ReceiverContextX25519Kyber768Draft00HkdfSha256::AesGcm128, - }, ]}; Ok(Self { context, config }) @@ -516,11 +415,6 @@ impl HpkeR { Kem::X25519Sha256 => { PublicKey::X25519(<X25519HkdfSha256 as KemTrait>::PublicKey::from_bytes(k)?) } - - #[cfg(feature = "pq")] - Kem::X25519Kyber768Draft00 => PublicKey::X25519Kyber768Draft00( - <X25519Kyber768Draft00 as KemTrait>::PublicKey::from_bytes(k)?, - ), }) } @@ -556,17 +450,8 @@ pub fn generate_key_pair(kem: Kem) -> Res<(PrivateKey, PublicKey)> { let (sk, pk) = X25519HkdfSha256::gen_keypair(&mut csprng); (PrivateKey::X25519(sk), PublicKey::X25519(pk)) } - - #[cfg(feature = "pq")] - Kem::X25519Kyber768Draft00 => { - let (sk, pk) = X25519Kyber768Draft00::gen_keypair(&mut csprng); - ( - PrivateKey::X25519Kyber768Draft00(sk), - PublicKey::X25519Kyber768Draft00(pk), - ) - } }; - trace!("Generated key pair: sk={:?} pk={:?}", sk, pk); + trace!("Generated key pair: sk={sk:?} pk={pk:?}"); Ok((sk, pk)) } @@ -577,17 +462,8 @@ pub fn derive_key_pair(kem: Kem, ikm: &[u8]) -> Res<(PrivateKey, PublicKey)> { let (sk, pk) = X25519HkdfSha256::derive_keypair(ikm); (PrivateKey::X25519(sk), PublicKey::X25519(pk)) } - - #[cfg(feature = "pq")] - Kem::X25519Kyber768Draft00 => { - let (sk, pk) = X25519Kyber768Draft00::derive_keypair(ikm); - ( - PrivateKey::X25519Kyber768Draft00(sk), - PublicKey::X25519Kyber768Draft00(pk), - ) - } }; - trace!("Derived key pair: sk={:?} pk={:?}", sk, pk); + trace!("Derived key pair: sk={sk:?} pk={pk:?}"); Ok((sk, pk)) } @@ -645,10 +521,4 @@ mod test { fn seal_open_chacha() { seal_open(Aead::ChaCha20Poly1305, Kem::X25519Sha256); } - - #[cfg(feature = "pq")] - #[test] - fn seal_open_xyber768d00() { - seal_open(Aead::Aes128Gcm, Kem::X25519Kyber768Draft00); - } } diff --git a/toolkit/components/glean/Cargo.toml b/toolkit/components/glean/Cargo.toml @@ -19,7 +19,7 @@ viaduct = "0.1" url = "2.1" thin-vec = { version = "0.2.1", features = ["gecko-ffi"] } ohttp = { version = "0.6", default-features = false, features = ["gecko", "nss", "client"] } -bhttp = "0.3" +bhttp = "0.6" thiserror = "1.0" mozbuild = "0.1" diff --git a/toolkit/components/glean/src/init/viaduct_uploader.rs b/toolkit/components/glean/src/init/viaduct_uploader.rs @@ -142,7 +142,7 @@ fn ohttp_upload(upload_request: PingUploadRequest) -> Result<UploadResult, Viadu .control() .status() .ok_or(ViaductUploaderError::Fatal)?; - Ok(UploadResult::http_status(res as i32)) + Ok(UploadResult::http_status(res.code() as i32)) } else { Ok(UploadResult::http_status(res.status as i32)) }