Skip to content

Commit

Permalink
remove superfluous dependency to generic-array
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Sep 13, 2023
1 parent 6ef3895 commit c06c573
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 0.6.12
- More mssql connection string options:
- `mssql://[username[:password]@]host/database[?instance=instance_name&packet_size=packet_size&client_program_version=client_program_version&client_pid=client_pid&hostname=hostname&app_name=app_name&server_name=server_name&client_interface_name=client_interface_name&language=language]`
- remove superfluous dependency to generic-array

## 0.6.11
- more encode and decode implementations for sqlite (decimal, bigdecimal, date)
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 0 additions & 2 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ postgres = [
mysql = [
"sha1",
"sha2",
"generic-array",
"num-bigint",
"digest",
"rand",
Expand Down Expand Up @@ -128,7 +127,6 @@ futures-util = { version = "0.3.19", default-features = false, features = ["allo
# used by the SQLite worker thread to block on the async mutex that locks the database handle
futures-executor = { version = "0.3.19", optional = true }
flume = { version = "0.10.9", optional = true, default-features = false, features = ["async"] }
generic-array = { version = "0.14.4", default-features = false, optional = true }
hex = "0.4.3"
hmac = { version = "0.12.0", default-features = false, optional = true }
itoa = "1.0.1"
Expand Down
15 changes: 7 additions & 8 deletions sqlx-core/src/mysql/connection/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bytes::buf::Chain;
use bytes::Bytes;
use digest::{Digest, OutputSizeUser};
use generic_array::GenericArray;
use digest::Digest;
use rand::thread_rng;
use rsa::{pkcs8::DecodePublicKey, Oaep, RsaPublicKey};
use sha1::Sha1;
Expand All @@ -21,9 +20,9 @@ impl AuthPlugin {
) -> Result<Vec<u8>, Error> {
match self {
// https://mariadb.com/kb/en/caching_sha2_password-authentication-plugin/
AuthPlugin::CachingSha2Password => Ok(scramble_sha256(password, nonce).to_vec()),
AuthPlugin::CachingSha2Password => Ok(scramble_sha256(password, nonce)),

AuthPlugin::MySqlNativePassword => Ok(scramble_sha1(password, nonce).to_vec()),
AuthPlugin::MySqlNativePassword => Ok(scramble_sha1(password, nonce)),

// https://mariadb.com/kb/en/sha256_password-plugin/
AuthPlugin::Sha256Password => encrypt_rsa(stream, 0x01, password, nonce).await,
Expand Down Expand Up @@ -71,7 +70,7 @@ impl AuthPlugin {
fn scramble_sha1(
password: &str,
nonce: &Chain<Bytes, Bytes>,
) -> GenericArray<u8, <Sha1 as OutputSizeUser>::OutputSize> {
) -> Vec<u8> {
// SHA1( password ) ^ SHA1( seed + SHA1( SHA1( password ) ) )
// https://mariadb.com/kb/en/connection/#mysql_native_password-plugin

Expand All @@ -93,13 +92,13 @@ fn scramble_sha1(

xor_eq(&mut pw_hash, &pw_seed_hash_hash);

pw_hash
pw_hash.to_vec()
}

fn scramble_sha256(
password: &str,
nonce: &Chain<Bytes, Bytes>,
) -> GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize> {
) -> Vec<u8> {
// XOR(SHA256(password), SHA256(seed, SHA256(SHA256(password))))
// https://mariadb.com/kb/en/caching_sha2_password-authentication-plugin/#sha-2-encrypted-password
let mut ctx = Sha256::new();
Expand All @@ -120,7 +119,7 @@ fn scramble_sha256(

xor_eq(&mut pw_hash, &pw_seed_hash_hash);

pw_hash
pw_hash.to_vec()
}

async fn encrypt_rsa<'s>(
Expand Down

0 comments on commit c06c573

Please sign in to comment.