Skip to content

Commit

Permalink
Update hmac version
Browse files Browse the repository at this point in the history
  • Loading branch information
kikakkz committed Mar 18, 2024
1 parent 5bfb459 commit 73dd3fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cfg-if = "1"
chrono = "0.4"
futures = { version = "0.3", optional = true }
hex = "0.4"
hmac = "0.10"
hmac = "0.11"
http = "0.2"
log = "0.4"
maybe-async = { version = "0.2" }
Expand Down
4 changes: 2 additions & 2 deletions s3/src/request_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub trait Request {
}
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()?)?;
let mut hmac = signing::HmacSha256::new_from_slice(&self.signing_key()?)?;
hmac.update(string_to_sign.as_bytes());
let signature = hex::encode(hmac.finalize().into_bytes());
// let signed_header = signing::signed_header_string(&headers);
Expand Down Expand Up @@ -249,7 +249,7 @@ pub trait Request {
fn authorization(&self, headers: &Headers) -> Result<String> {
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()?)?;
let mut hmac = signing::HmacSha256::new_from_slice(&self.signing_key()?)?;
hmac.update(string_to_sign.as_bytes());
let signature = hex::encode(hmac.finalize().into_bytes());
let signed_header = signing::signed_header_string(headers);
Expand Down
8 changes: 4 additions & 4 deletions s3/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ pub fn signing_key(
service: &str,
) -> Result<Vec<u8>> {
let secret = format!("AWS4{}", secret_key);
let mut date_hmac = HmacSha256::new_varkey(secret.as_bytes())?;
let mut date_hmac = HmacSha256::new_from_slice(secret.as_bytes())?;
date_hmac.update(datetime.format(SHORT_DATE).to_string().as_bytes());
let mut region_hmac = HmacSha256::new_varkey(&date_hmac.finalize().into_bytes())?;
let mut region_hmac = HmacSha256::new_from_slice(&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())?;
let mut service_hmac = HmacSha256::new_from_slice(&region_hmac.finalize().into_bytes())?;
service_hmac.update(service.as_bytes());
let mut signing_hmac = HmacSha256::new_varkey(&service_hmac.finalize().into_bytes())?;
let mut signing_hmac = HmacSha256::new_from_slice(&service_hmac.finalize().into_bytes())?;
signing_hmac.update(b"aws4_request");
Ok(signing_hmac.finalize().into_bytes().to_vec())
}
Expand Down

0 comments on commit 73dd3fe

Please sign in to comment.