chiark / gitweb /
Add token
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 11:42:10 +0000 (12:42 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 11:42:10 +0000 (12:42 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.lock
Cargo.toml
src/bin/client.rs
src/prelude.rs

index 510a42ee30fea8a9ce4f57e72e5e8489d794f7a2..097897d9bc9bcb53daa5847436cb7ef5d9413aec 100644 (file)
@@ -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",
index d4f12c7271457b190c064583203a2e5c32c48aae..0b5abecd6b10e3f451e97d02c666b0e1eaff937a 100644 (file)
@@ -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"
index 20754484f9455fdebdd1bdc68de3cbc022c78792..a6cecb168373052ac7bc81bda71aa3d2e6432f5b 100644 (file)
@@ -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,
   );
index 392faea3aa14be6373382065023e0bd6d3cf3975..dc2f0695e0304456159eccbafcf7f69eb0fdfad4 100644 (file)
@@ -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};