From: Ian Jackson Date: Sun, 1 Aug 2021 11:42:10 +0000 (+0100) Subject: Add token X-Git-Tag: hippotat/1.0.0~404 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=eed250a621c920336e495b507a9667e6d2571e44;p=hippotat.git Add token Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index 510a42e..097897d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" @@ -366,6 +372,7 @@ name = "hippotat" version = "0.0.0" dependencies = [ "anyhow", + "base64", "configparser", "env_logger", "extend", diff --git a/Cargo.toml b/Cargo.toml index d4f12c7..0b5abec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ hippotat-macros = { path = "macros" } # versions specified here are mostly just guesses at what is needed # (or currently available): anyhow = "1" +base64 = "0.13" configparser = "2" env_logger = "0.9" futures = "0.3" diff --git a/src/bin/client.rs b/src/bin/client.rs index 2075448..a6cecb1 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -29,6 +29,16 @@ fn submit_request<'r, 'c:'r, C:HCC>( .saturating_add(Duration::from_nanos(999_999_999)) .as_secs(); + let time_t = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_else(|_| Duration::default()) // clock is being weird + .as_secs(); + let time_t = format!("{:x}", time_t); + let hmac = token_hmac(c.ic.secret.0.as_bytes(), time_t.as_bytes()); + let mut token = time_t; + write!(token, " ").unwrap(); + base64::encode_config_buf(&hmac, BASE64_CONFIG, &mut token); + let prefix1 = format!(into_crlfs!( r#"-- Content-Type: text/plain; charset="utf-8" @@ -39,7 +49,7 @@ fn submit_request<'r, 'c:'r, C:HCC>( {} {}"#), &c.ic.link.client, - "xxx token goes here", + token, c.ic.target_requests_outstanding, show_timeout, ); diff --git a/src/prelude.rs b/src/prelude.rs index 392faea..dc2f069 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -8,7 +8,7 @@ pub use std::convert::TryInto; pub use std::borrow::Cow; pub use std::cmp::{min, max}; pub use std::fs; -pub use std::fmt::{self, Debug, Display}; +pub use std::fmt::{self, Debug, Display, Write as _}; pub use std::future::Future; pub use std::io::{self, ErrorKind, Read as _}; pub use std::iter; @@ -21,8 +21,10 @@ pub use std::pin::Pin; pub use std::str::{self, FromStr}; pub use std::sync::Arc; pub use std::task::Poll; +pub use std::time::{SystemTime, UNIX_EPOCH}; pub use anyhow::{anyhow, Context}; +pub use base64::STANDARD_NO_PAD as BASE64_CONFIG; pub use extend::ext; pub use fehler::{throw, throws}; pub use futures::{poll, future};