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

Upgrade hmac to 0.11 #1443

Merged
merged 1 commit into from
Sep 23, 2021
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
23 changes: 9 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ futures-intrusive = "0.4.0"
futures-util = { version = "0.3.5", default-features = false, features = ["alloc", "sink"] }
generic-array = { version = "0.14.4", default-features = false, optional = true }
hex = "0.4.2"
hmac = { version = "0.10.1", default-features = false, optional = true }
hmac = { version = "0.11.0", default-features = false, optional = true }
itoa = "0.4.5"
ipnetwork = { version = "0.17.0", default-features = false, optional = true }
mac_address = { version = "1.1", default-features = false, optional = true }
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/postgres/connection/sasl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) async fn authenticate(
)?;

// ClientKey := HMAC(SaltedPassword, "Client Key")
let mut mac = Hmac::<Sha256>::new_varkey(&salted_password).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&salted_password).map_err(Error::protocol)?;
mac.update(b"Client Key");

let client_key = mac.finalize().into_bytes();
Expand All @@ -122,7 +122,7 @@ pub(crate) async fn authenticate(
);

// ClientSignature := HMAC(StoredKey, AuthMessage)
let mut mac = Hmac::<Sha256>::new_varkey(&stored_key).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&stored_key).map_err(Error::protocol)?;
mac.update(&auth_message.as_bytes());

let client_signature = mac.finalize().into_bytes();
Expand All @@ -135,13 +135,13 @@ pub(crate) async fn authenticate(
.collect();

// ServerKey := HMAC(SaltedPassword, "Server Key")
let mut mac = Hmac::<Sha256>::new_varkey(&salted_password).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&salted_password).map_err(Error::protocol)?;
mac.update(b"Server Key");

let server_key = mac.finalize().into_bytes();

// ServerSignature := HMAC(ServerKey, AuthMessage)
let mut mac = Hmac::<Sha256>::new_varkey(&server_key).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(&server_key).map_err(Error::protocol)?;
mac.update(&auth_message.as_bytes());

// client-final-message = client-final-message-without-proof "," proof
Expand Down Expand Up @@ -197,7 +197,7 @@ fn gen_nonce() -> String {

// Hi(str, salt, i):
fn hi<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Result<[u8; 32], Error> {
let mut mac = Hmac::<Sha256>::new_varkey(s.as_bytes()).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;

mac.update(&salt);
mac.update(&1u32.to_be_bytes());
Expand All @@ -206,7 +206,7 @@ fn hi<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Result<[u8; 32], Error
let mut hi = u;

for _ in 1..iter_count {
let mut mac = Hmac::<Sha256>::new_varkey(s.as_bytes()).map_err(Error::protocol)?;
let mut mac = Hmac::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;
mac.update(u.as_slice());
u = mac.finalize().into_bytes();
hi = hi.iter().zip(u.iter()).map(|(&a, &b)| a ^ b).collect();
Expand Down