From d99113e558829bc95ca2a1542c88766c650c6133 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 5 Feb 2019 11:32:46 +0100 Subject: [PATCH 1/3] Remove openssl dependency for GCS --- Cargo.toml | 5 +++-- src/cache/gcs.rs | 11 ++++++----- src/errors.rs | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 515c2d755..0f7323ec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,8 @@ void = { version = "1", optional = true } [patch.crates-io] # Waiting for https://github.com/tiny-http/tiny-http/pull/151 tiny_http = { git = "https://github.com/aidanhs/tiny-http-sccache.git", rev = "a14fa0a" } +# Waiting for https://github.com/Keats/jsonwebtoken/pull/74 +jsonwebtoken = { git = "https://github.com/Jake-Shadle/jsonwebtoken.git", rev = "2f469a61" } [dev-dependencies] assert_cmd = "0.9" @@ -119,7 +121,7 @@ all-windows = ["redis", "s3", "memcached", "azure"] azure = ["chrono", "hyper", "hyperx", "rust-crypto", "url"] s3 = ["chrono", "hyper", "hyperx", "reqwest", "rust-crypto", "simple-s3"] simple-s3 = [] -gcs = ["chrono", "hyper", "jsonwebtoken", "openssl", "reqwest", "url"] +gcs = ["chrono", "hyper", "jsonwebtoken", "reqwest", "url"] memcached = ["memcached-rs"] # Enable features that require unstable features of Nightly Rust. unstable = [] @@ -132,4 +134,3 @@ dist-tests = [] [workspace] exclude = ["tests/test-crate"] - diff --git a/src/cache/gcs.rs b/src/cache/gcs.rs index 05f8fa033..31fc84a3b 100644 --- a/src/cache/gcs.rs +++ b/src/cache/gcs.rs @@ -33,7 +33,6 @@ use hyper::Method; use reqwest; use reqwest::async::{Request, Client}; use jwt; -use openssl; use serde_json; use url::form_urlencoded; use url::percent_encoding::{percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET}; @@ -224,14 +223,16 @@ impl GCSCredentialProvider { issued_at: chrono::offset::Utc::now().timestamp(), }; - let binary_key = openssl::rsa::Rsa::private_key_from_pem( - self.sa_key.private_key.as_bytes() - )?.private_key_to_der()?; + // Could also use the pem crate, but that seems overly complicated for just the specific + // case of GCP keys + let key_string = self.sa_key.private_key.splitn(5, "-----").nth(2).ok_or_else(|| "invalid key format")?; + // Skip the leading `\n` + let key_bytes = base64::decode_config(key_string[1..].as_bytes(), base64::MIME)?; let auth_request_jwt = jwt::encode( &jwt::Header::new(jwt::Algorithm::RS256), &jwt_claims, - &binary_key, + &key_bytes, )?; Ok(auth_request_jwt) diff --git a/src/errors.rs b/src/errors.rs index 5707c3f51..48535a167 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -50,6 +50,7 @@ error_chain! { Json(serde_json::Error); Jwt(jwt::errors::Error) #[cfg(feature = "jsonwebtoken")]; Openssl(openssl::error::ErrorStack) #[cfg(feature = "openssl")]; + Base64Decode(base64::DecodeError); Bincode(bincode::Error); Memcached(memcached::proto::Error) #[cfg(feature = "memcached")]; Redis(redis::RedisError) #[cfg(feature = "redis")]; From 9f65ec06ec201b4d1094b5f865ab7aa6ac5db801 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 5 Feb 2019 11:57:23 +0100 Subject: [PATCH 2/3] Fix older compilers --- src/cache/gcs.rs | 1 + src/errors.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cache/gcs.rs b/src/cache/gcs.rs index 31fc84a3b..37720cf8a 100644 --- a/src/cache/gcs.rs +++ b/src/cache/gcs.rs @@ -19,6 +19,7 @@ use std::io; use std::rc::Rc; use std::time; +use base64; use cache::{ Cache, CacheRead, diff --git a/src/errors.rs b/src/errors.rs index 48535a167..877860e3c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -20,6 +20,7 @@ use std::error; use std::io; use std::process; +use base64; use bincode; use futures::Future; use futures::future; From ab69b4e6a9b660e95ae053426e48491989d67959 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 5 Feb 2019 12:01:58 +0100 Subject: [PATCH 3/3] Remove 'all-windows' feature --- Cargo.toml | 2 -- appveyor.yml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f7323ec7..2e6a2a215 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,8 +116,6 @@ tokio-reactor = "0.1" [features] default = ["s3"] all = ["redis", "s3", "memcached", "gcs", "azure"] -# gcs requires openssl, which is a pain on Windows. -all-windows = ["redis", "s3", "memcached", "azure"] azure = ["chrono", "hyper", "hyperx", "rust-crypto", "url"] s3 = ["chrono", "hyper", "hyperx", "reqwest", "rust-crypto", "simple-s3"] simple-s3 = [] diff --git a/appveyor.yml b/appveyor.yml index 8f8602372..7a6764fce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,10 +16,10 @@ install: - cargo -V build_script: -- cmd: cargo build %RELEASE% --verbose --features="all-windows %EXTRA_FEATURES%" +- cmd: cargo build %RELEASE% --verbose --features="all %EXTRA_FEATURES%" test_script: -- cmd: cargo test --all %RELEASE% --verbose --features="all-windows %EXTRA_FEATURES%" +- cmd: cargo test --all %RELEASE% --verbose --features="all %EXTRA_FEATURES%" for: