Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove openssl dependency for GCS #367

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -114,12 +116,10 @@ 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 = []
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 = []
Expand All @@ -132,4 +132,3 @@ dist-tests = []

[workspace]
exclude = ["tests/test-crate"]

4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
12 changes: 7 additions & 5 deletions src/cache/gcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::io;
use std::rc::Rc;
use std::time;

use base64;
use cache::{
Cache,
CacheRead,
Expand All @@ -33,7 +34,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};
Expand Down Expand Up @@ -224,14 +224,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)
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::error;
use std::io;
use std::process;

use base64;
use bincode;
use futures::Future;
use futures::future;
Expand Down Expand Up @@ -50,6 +51,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")];
Expand Down