Skip to content

Commit

Permalink
Bump dependencies, bump versions of all three crates (durch#113)
Browse files Browse the repository at this point in the history
* Bump dependencies (durch#112)

* aws-region 0.22.0

* aws-creds 0.24.0

* s3 0.24.0

Co-authored-by: Jonas Platte <[email protected]>
  • Loading branch information
durch and jplatte authored Sep 17, 2020
1 parent 1541abf commit a513abc
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
9 changes: 4 additions & 5 deletions aws-creds/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-creds"
version = "0.23.4"
version = "0.24.0"
authors = ["Drazen Urch"]
description = "Tiny Rust library for working with Amazon IAM credential,s, supports `s3` crate"
repository = "https://github.com/durch/rust-s3"
Expand All @@ -16,11 +16,10 @@ path = "src/lib.rs"

[dependencies]
simpl = "0.1.0"
dirs = "2.0.2"
rust-ini = "0.15.2"
reqwest = {version = "0.10", features = ["json", "blocking"]}
dirs = "3"
rust-ini = "0.15"
attohttpc = {version = "0.15", features = ["json"]}
url = "2"
serde-xml-rs = "0.4"
serde = "1"
serde_derive = "1"

13 changes: 8 additions & 5 deletions aws-creds/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Credentials {
],
)
.unwrap();
let response = reqwest::blocking::get(url.as_str())?;
let response = attohttpc::get(url.as_str()).send()?;
let serde_response =
serde_xml::from_str::<AssumeRoleWithWebIdentityResponse>(&response.text()?).unwrap();
// assert!(serde_xml::from_str::<AssumeRoleWithWebIdentityResponse>(&response.text()?).unwrap());
Expand Down Expand Up @@ -268,20 +268,23 @@ impl Credentials {
let resp: HashMap<String, String> =
match env::var("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI") {
Ok(credentials_path) => Some(
reqwest::blocking::get(&format!("http://169.254.170.2{}", credentials_path))?
attohttpc::get(&format!("http://169.254.170.2{}", credentials_path))
.send()?
.json()?,
),
Err(_) => {
let resp: HashMap<String, String> =
reqwest::blocking::get("http://169.254.169.254/latest/meta-data/iam/info")?
attohttpc::get("http://169.254.169.254/latest/meta-data/iam/info")
.send()?
.json()?;
if let Some(arn) = resp.get("InstanceProfileArn") {
if let Some(role) = arn.split('/').last() {
Some(
reqwest::blocking::get(&format!(
attohttpc::get(&format!(
"http://169.254.169.254/latest/meta-data/iam/security-credentials/{}",
role
))?
))
.send()?
.json()?,
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion aws-creds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate serde_derive;

simpl::err!(AwsCredsError, {
Utf8@std::str::Utf8Error;
Reqwest@reqwest::Error;
Reqwest@attohttpc::Error;
Env@std::env::VarError;
Ini@ini::ini::Error;
Io@std::io::Error;
Expand Down
5 changes: 2 additions & 3 deletions aws-region/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-region"
version = "0.21.0"
version = "0.22.0"
authors = ["Drazen Urch"]
description = "Tiny Rust library for working with Amazon AWS regions, supports `s3` crate"
repository = "https://github.com/durch/rust-s3"
Expand All @@ -15,5 +15,4 @@ name = "awsregion"
path = "src/lib.rs"

[dependencies]
simpl = "0.1.0-alpha"

simpl = "0.1.0"
14 changes: 7 additions & 7 deletions s3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-s3"
version = "0.23.0"
version = "0.24.0"
authors = ["Drazen Urch"]
description = "Tiny Rust library for working with Amazon S3 and compatible object storage APIs"
repository = "https://github.com/durch/rust-s3"
Expand All @@ -22,20 +22,20 @@ path = "bin/simple_crud.rs"
base64 = "0.12"
chrono = "0.4"
hex = "0.4"
hmac = "0.7"
hmac = "0.9"
reqwest = {version = "0.10", features = ["json", "stream"]}
serde_derive = "1"
serde = "1"
serde-xml-rs = "0.4.0"
sha2 = "0.8"
serde-xml-rs = "0.4"
sha2 = "0.9"
md5 = "0.7"
url = "2"
futures = "0.3"
tokio = {version="0.2", features=["macros", "io-util", "stream"]}
rand = "0.7"
simpl = "0.1.0"
aws-region = "0.21"
aws-creds = "0.23"
aws-region = "0.22"
aws-creds = "0.24"
log = "0.4"
percent-encoding = "2"
async-std = "1"
Expand All @@ -50,4 +50,4 @@ native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]

[dev-dependencies]
tokio = {version="0.2", features=["fs"]}
tokio = {version="0.2", features=["fs"]}
22 changes: 11 additions & 11 deletions s3/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Write;
use super::bucket::Bucket;
use super::command::Command;
use chrono::{DateTime, Utc};
use hmac::Mac;
use hmac::{Mac, NewMac};
use reqwest::header::{self, HeaderMap, HeaderName, HeaderValue};
use reqwest::{Client, Response};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -157,18 +157,18 @@ impl<'a> Request<'a> {
match &self.command {
Command::PutObject { content, .. } => {
let mut sha = Sha256::default();
sha.input(content);
hex::encode(sha.result().as_slice())
sha.update(content);
hex::encode(sha.finalize().as_slice())
}
Command::PutObjectTagging { tags } => {
let mut sha = Sha256::default();
sha.input(tags.as_bytes());
hex::encode(sha.result().as_slice())
sha.update(tags.as_bytes());
hex::encode(sha.finalize().as_slice())
}
Command::CompleteMultipartUpload { data, .. } => {
let mut sha = Sha256::default();
sha.input(data.to_string().as_bytes());
hex::encode(sha.result().as_slice())
sha.update(data.to_string().as_bytes());
hex::encode(sha.finalize().as_slice())
}
_ => EMPTY_PAYLOAD_SHA.into(),
}
Expand Down Expand Up @@ -238,8 +238,8 @@ impl<'a> Request<'a> {
let canonical_request = self.presigned_canonical_request(&headers)?;
let string_to_sign = self.string_to_sign(&canonical_request);
let mut hmac = signing::HmacSha256::new_varkey(&self.signing_key()?)?;
hmac.input(string_to_sign.as_bytes());
let signature = hex::encode(hmac.result().code());
hmac.update(string_to_sign.as_bytes());
let signature = hex::encode(hmac.finalize().into_bytes());
// let signed_header = signing::signed_header_string(&headers);
Ok(signature)
}
Expand All @@ -248,8 +248,8 @@ impl<'a> Request<'a> {
let canonical_request = self.canonical_request(headers);
let string_to_sign = self.string_to_sign(&canonical_request);
let mut hmac = signing::HmacSha256::new_varkey(&self.signing_key()?)?;
hmac.input(string_to_sign.as_bytes());
let signature = hex::encode(hmac.result().code());
hmac.update(string_to_sign.as_bytes());
let signature = hex::encode(hmac.finalize().into_bytes());
let signed_header = signing::signed_header_string(headers);
Ok(signing::authorization_header(
&self.bucket.access_key().unwrap(),
Expand Down
26 changes: 13 additions & 13 deletions s3/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::str;

use chrono::{DateTime, Utc};
use hmac::{Hmac, Mac};
use hmac::{Hmac, Mac, NewMac};
use reqwest::header::HeaderMap;
use sha2::{Digest, Sha256};
use url::Url;
Expand Down Expand Up @@ -113,12 +113,12 @@ pub fn scope_string(datetime: &DateTime<Utc>, region: &Region) -> String {
/// applied to sign requests.
pub fn string_to_sign(datetime: &DateTime<Utc>, region: &Region, canonical_req: &str) -> String {
let mut hasher = Sha256::default();
hasher.input(canonical_req.as_bytes());
hasher.update(canonical_req.as_bytes());
let string_to = format!(
"AWS4-HMAC-SHA256\n{timestamp}\n{scope}\n{hash}",
timestamp = datetime.format(LONG_DATETIME),
scope = scope_string(datetime, region),
hash = hex::encode(hasher.result().as_slice())
hash = hex::encode(hasher.finalize().as_slice())
);
string_to
}
Expand All @@ -133,14 +133,14 @@ pub fn signing_key(
) -> Result<Vec<u8>> {
let secret = format!("AWS4{}", secret_key);
let mut date_hmac = HmacSha256::new_varkey(secret.as_bytes())?;
date_hmac.input(datetime.format(SHORT_DATE).to_string().as_bytes());
let mut region_hmac = HmacSha256::new_varkey(&date_hmac.result().code())?;
region_hmac.input(region.to_string().as_bytes());
let mut service_hmac = HmacSha256::new_varkey(&region_hmac.result().code())?;
service_hmac.input(service.as_bytes());
let mut signing_hmac = HmacSha256::new_varkey(&service_hmac.result().code())?;
signing_hmac.input(b"aws4_request");
Ok(signing_hmac.result().code().to_vec())
date_hmac.update(datetime.format(SHORT_DATE).to_string().as_bytes());
let mut region_hmac = HmacSha256::new_varkey(&date_hmac.finalize().into_bytes())?;
region_hmac.update(region.to_string().as_bytes());
let mut service_hmac = HmacSha256::new_varkey(&region_hmac.finalize().into_bytes())?;
service_hmac.update(service.as_bytes());
let mut signing_hmac = HmacSha256::new_varkey(&service_hmac.finalize().into_bytes())?;
signing_hmac.update(b"aws4_request");
Ok(signing_hmac.finalize().into_bytes().to_vec())
}

/// Generate the AWS authorization header.
Expand Down Expand Up @@ -303,8 +303,8 @@ mod tests {
let secret = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
let signing_key = signing_key(&datetime, secret, &"us-east-1".parse().unwrap(), "s3");
let mut hmac = Hmac::<Sha256>::new_varkey(&signing_key.unwrap()).unwrap();
hmac.input(string_to_sign.as_bytes());
assert_eq!(expected, hex::encode(hmac.result().code()));
hmac.update(string_to_sign.as_bytes());
assert_eq!(expected, hex::encode(hmac.finalize().into_bytes()));
}

#[test]
Expand Down

0 comments on commit a513abc

Please sign in to comment.