diff --git a/Cargo.lock b/Cargo.lock index 4db53837e..31b89ca5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3595,6 +3595,7 @@ dependencies = [ "derive_builder_fork_arti", "digest 0.10.6", "hex-literal", + "humantime 2.1.0", "rand 0.8.5", "signature", "thiserror", @@ -3987,6 +3988,7 @@ dependencies = [ "educe", "hex", "hex-literal", + "humantime 2.1.0", "itertools", "once_cell", "phf", @@ -4043,6 +4045,7 @@ dependencies = [ "hex-literal", "hkdf", "hmac", + "humantime 2.1.0", "itertools", "pin-project", "rand 0.8.5", diff --git a/crates/tor-cert/Cargo.toml b/crates/tor-cert/Cargo.toml index eb6e3b34b..1f70c2f1f 100644 --- a/crates/tor-cert/Cargo.toml +++ b/crates/tor-cert/Cargo.toml @@ -29,6 +29,7 @@ tor-llcrypto = { path = "../tor-llcrypto", version = "0.4.0" } [dev-dependencies] base64 = "0.13.0" hex-literal = "0.3" +humantime = "2" rand = "0.8" [package.metadata.docs.rs] all-features = true diff --git a/crates/tor-cert/tests/testvec_certs.rs b/crates/tor-cert/tests/testvec_certs.rs index ed371a8e2..222450adf 100644 --- a/crates/tor-cert/tests/testvec_certs.rs +++ b/crates/tor-cert/tests/testvec_certs.rs @@ -2,12 +2,11 @@ use tor_cert::rsa::RsaCrosscert; use tor_cert::{Ed25519Cert, KeyType}; use tor_checkable::{ExternallySigned, SelfSigned, Timebound}; -use std::time::{Duration, SystemTime}; - use hex_literal::hex; #[test] fn test_valid_ed() { + use humantime::parse_rfc3339; use tor_llcrypto::pk::ed25519::Ed25519Identity; // These are taken from a CERTS cell in a chutney network. let signing_key = hex!("F82294B866A31F01FC5D0DA8572850A9B929545C3266558D7D2316E3B74172B0"); @@ -15,7 +14,7 @@ fn test_valid_ed() { let signing_key = Ed25519Identity::from_bytes(&signing_key[..]).unwrap(); let identity_key = Ed25519Identity::from_bytes(&identity_key[..]).unwrap(); - let notional_time = SystemTime::UNIX_EPOCH + Duration::new(1601000000, 0); + let notional_time = parse_rfc3339("2020-09-25T02:13:20Z").unwrap(); // signing cert signed with signing key, type 4, one extension. let c = hex!( @@ -43,7 +42,7 @@ fn test_valid_ed() { assert_eq!(cert.cert_type(), 4.into()); assert_eq!( cert.expiry(), - SystemTime::UNIX_EPOCH + Duration::new(0x6cc2a * 3600, 0) + parse_rfc3339("2020-10-26T18:00:00Z").unwrap() ); // link cert signed with signing key, type 5, no extensions. @@ -72,13 +71,14 @@ fn test_valid_ed() { assert_eq!(cert.cert_type(), 5.into()); assert_eq!( cert.expiry(), - SystemTime::UNIX_EPOCH + Duration::new(0x6c98a * 3600, 0) + parse_rfc3339("2020-09-28T18:00:00Z").unwrap() ); } #[test] fn test_valid_rsa_cc() { - let notional_time = SystemTime::UNIX_EPOCH + Duration::new(1601000000, 0); + let notional_time = humantime::parse_rfc3339("2020-09-25T02:13:20Z").unwrap(); + let pk = hex!("30818902818100d38b1e6ceb946e0db0751f4cbace3dcb9688b6c25304227b4710c35afb73627e50500f5913e158b621802612d1c75827003703338375237552eb3cd3c12f6ab3604e60c1a2d26bb1fbad206ff023969a90909d6a65a5458a5312c26ebd3a3dad30302d4515cdcd264146ac18e6fc60a04bd3ec327f04294d96ba5aa25b464c3f0203010001"); let pk = tor_llcrypto::pk::rsa::PublicKey::from_der(&pk[..]).unwrap(); diff --git a/crates/tor-checkable/Cargo.toml b/crates/tor-checkable/Cargo.toml index 96891754b..636886934 100644 --- a/crates/tor-checkable/Cargo.toml +++ b/crates/tor-checkable/Cargo.toml @@ -23,3 +23,5 @@ tor-llcrypto = { path = "../tor-llcrypto", version = "0.4.0" } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] +[dev-dependencies] +humantime = "2" diff --git a/crates/tor-checkable/src/timed.rs b/crates/tor-checkable/src/timed.rs index 6e311aac4..a1525d34a 100644 --- a/crates/tor-checkable/src/timed.rs +++ b/crates/tor-checkable/src/timed.rs @@ -135,16 +135,18 @@ impl crate::Timebound for TimerangeBound { mod test { use super::*; use crate::{TimeValidityError, Timebound}; + use humantime::parse_rfc3339; use std::time::{Duration, SystemTime}; #[test] fn test_bounds() { + #![allow(clippy::unwrap_used)] let one_day = Duration::new(86400, 0); - let mixminion_v0_0_1 = SystemTime::UNIX_EPOCH + 12059 * one_day; //2003-01-07 - let tor_v0_0_2pre13 = SystemTime::UNIX_EPOCH + 12344 * one_day; //2003-10-19 - let cussed_nougat = SystemTime::UNIX_EPOCH + 14093 * one_day; //2008-08-02 - let tor_v0_4_4_5 = SystemTime::UNIX_EPOCH + 18520 * one_day; //2020-09-15 - let today = SystemTime::UNIX_EPOCH + 18527 * one_day; //2020-09-22 + let mixminion_v0_0_1 = parse_rfc3339("2003-01-07T00:00:00Z").unwrap(); + let tor_v0_0_2pre13 = parse_rfc3339("2003-10-19T00:00:00Z").unwrap(); + let cussed_nougat = parse_rfc3339("2008-08-02T00:00:00Z").unwrap(); + let tor_v0_4_4_5 = parse_rfc3339("2020-09-15T00:00:00Z").unwrap(); + let today = parse_rfc3339("2020-09-22T00:00:00Z").unwrap(); let tr = TimerangeBound::new((), ..tor_v0_4_4_5); assert_eq!(tr.start, None); diff --git a/crates/tor-netdoc/Cargo.toml b/crates/tor-netdoc/Cargo.toml index f1ae83eaa..1b9b44e8e 100644 --- a/crates/tor-netdoc/Cargo.toml +++ b/crates/tor-netdoc/Cargo.toml @@ -72,6 +72,7 @@ weak-table = "0.3.0" [dev-dependencies] hex-literal = "0.3" +humantime = "2" itertools = "0.10.1" serde_json = "1.0.50" [package.metadata.docs.rs] diff --git a/crates/tor-netdoc/src/doc/routerdesc.rs b/crates/tor-netdoc/src/doc/routerdesc.rs index a20e83c0c..9b3a9c117 100644 --- a/crates/tor-netdoc/src/doc/routerdesc.rs +++ b/crates/tor-netdoc/src/doc/routerdesc.rs @@ -934,7 +934,7 @@ mod test { ); assert_eq!( rd.published(), - time::SystemTime::UNIX_EPOCH + time::Duration::new(1668455932, 0) + humantime::parse_rfc3339("2022-11-14T19:58:52Z").unwrap() ); assert_eq!( rd.or_ports().collect::>(), diff --git a/crates/tor-proto/Cargo.toml b/crates/tor-proto/Cargo.toml index 11d17a6b3..d55b19639 100644 --- a/crates/tor-proto/Cargo.toml +++ b/crates/tor-proto/Cargo.toml @@ -62,6 +62,7 @@ zeroize = "1" [dev-dependencies] hex = "0.4" hex-literal = "0.3" +humantime = "2" itertools = "0.10.1" regex = { version = "1", default-features = false, features = ["std"] } statrs = "0.16.0" diff --git a/crates/tor-proto/src/channel/handshake.rs b/crates/tor-proto/src/channel/handshake.rs index fcc35cd35..0a7f0f29e 100644 --- a/crates/tor-proto/src/channel/handshake.rs +++ b/crates/tor-proto/src/channel/handshake.rs @@ -666,7 +666,7 @@ pub(super) mod test { #[test] fn connect_ok() -> Result<()> { tor_rtcompat::test_with_one_runtime!(|rt| async move { - let now = SystemTime::UNIX_EPOCH + Duration::from_secs(1217696400); + let now = humantime::parse_rfc3339("2008-08-02T17:00:00Z").unwrap(); let mut buf = Vec::new(); // versions cell buf.extend_from_slice(VERSIONS);