From 446927f5879ab66490d0e109876af0cd383d595a Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 4 Jan 2022 15:23:41 +0200 Subject: [PATCH] replace outdated crypto crate --- Cargo.lock | 66 +++++++++++++++++++++++---------- peach-lib/Cargo.toml | 2 +- peach-lib/src/password_utils.rs | 12 ++++-- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62614be..6cf6598 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,6 +246,15 @@ dependencies = [ "generic-array 0.14.4", ] +[[package]] +name = "block-buffer" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "block-padding" version = "0.1.5" @@ -527,6 +536,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "crypto-mac" version = "0.10.1" @@ -626,6 +644,17 @@ dependencies = [ "generic-array 0.14.4", ] +[[package]] +name = "digest" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" +dependencies = [ + "block-buffer 0.10.0", + "crypto-common", + "generic-array 0.14.4", +] + [[package]] name = "dirs" version = "3.0.2" @@ -1706,6 +1735,12 @@ dependencies = [ "ws", ] +[[package]] +name = "keccak" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -2464,10 +2499,10 @@ dependencies = [ "log 0.4.14", "nanorand", "regex", - "rust-crypto", "serde 1.0.130", "serde_json", "serde_yaml", + "sha3", ] [[package]] @@ -3232,31 +3267,12 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "rust-crypto" -version = "0.2.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" -dependencies = [ - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "time 0.1.44", -] - [[package]] name = "rustc-demangle" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - [[package]] name = "rustc_version" version = "0.1.7" @@ -3465,6 +3481,16 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "sha3" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" +dependencies = [ + "digest 0.10.1", + "keccak", +] + [[package]] name = "sharded-slab" version = "0.1.4" diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 8085f69..7209185 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -13,7 +13,7 @@ jsonrpc-core = "8.0.1" log = "0.4" nanorand = "0.6.1" regex = "1" -rust-crypto = "0.2.36" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.8" +sha3 = "0.10.0" diff --git a/peach-lib/src/password_utils.rs b/peach-lib/src/password_utils.rs index 02a9b5c..ea3ec41 100644 --- a/peach-lib/src/password_utils.rs +++ b/peach-lib/src/password_utils.rs @@ -1,5 +1,5 @@ -use crypto::{digest::Digest, sha3::Sha3}; use nanorand::{Rng, WyRand}; +use sha3::{Digest, Sha3_256}; use crate::{config_manager, error::PeachError, sbot_client}; @@ -37,9 +37,13 @@ pub fn set_new_password(new_password: &str) -> Result<(), PeachError> { /// Creates a hash from a password string pub fn hash_password(password: &str) -> String { - let mut hasher = Sha3::sha3_256(); - hasher.input_str(password); - hasher.result_str() + let mut hasher = Sha3_256::new(); + // write input message + hasher.update(password); + // read hash digest + let result = hasher.finalize(); + // convert `u8` to `String` + result[0].to_string() } /// Sets a new temporary password for the admin user