diff --git a/Cargo.lock b/Cargo.lock index fdc0ffd198186f1180b32dbdc1d0e1150ba99384..27283b9268fc59a8efe0e158be8c6f5013d379e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,14 +556,6 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clear_on_drop" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cloudabi" version = "0.0.3" @@ -861,7 +853,6 @@ dependencies = [ "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "durs-common-tools 0.2.0", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -870,6 +861,7 @@ dependencies = [ "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1017,7 +1009,6 @@ version = "0.3.0-dev" dependencies = [ "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dubp-currency-params 0.2.0", "dup-crypto 0.7.0", "durs-bc 0.3.0-dev", @@ -1038,6 +1029,7 @@ dependencies = [ "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3111,6 +3103,25 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "zeroize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09e55f0a5c2ca15795035d90c46bd0e73a5123b72f68f12596d6ba5282051380" "checksum actix-connect 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2b61480a8d30c94d5c883d79ef026b02ad6809931b0a4bb703f9545cd8c986" @@ -3164,7 +3175,6 @@ dependencies = [ "checksum chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77d2058ba29594f69c75e8a9018e0485e3914ca5084e3613cd64529042f5423b" "checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "433e7ac7d511768127ed85b0c4947f47a254131e37864b2dc13f52aa32cd37e5" "checksum combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" @@ -3390,3 +3400,5 @@ dependencies = [ "checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" "checksum ws 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a2c47b5798ccc774ffb93ff536aec7c4275d722fd9c740c83cdd1af1f2d94" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +"checksum zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" +"checksum zeroize_derive 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de251eec69fc7c1bc3923403d18ececb929380e016afe103da75f396704f8ca2" diff --git a/lib/core/core/Cargo.toml b/lib/core/core/Cargo.toml index 5b7526bfa04c97a623b43a9eda7ea5b68a0f5e0a..3e5bffb6cfba707910822443f8197f590eb77911 100644 --- a/lib/core/core/Cargo.toml +++ b/lib/core/core/Cargo.toml @@ -12,7 +12,6 @@ path = "src/lib.rs" [dependencies] chrono = "0.4" clap = "2.33.0" -clear_on_drop = "0.2.3" durs-bc = { path = "../../modules/blockchain/blockchain" } durs-common-tools = { path = "../../tools/common-tools" } durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" } @@ -33,5 +32,6 @@ serde_derive = "1.0.*" serde_json = "1.0.*" structopt= "0.3.9" unwrap = "1.2.1" +zeroize = { version = "1.1.0", features = ["zeroize_derive"] } [features] diff --git a/lib/core/core/src/commands/keys.rs b/lib/core/core/src/commands/keys.rs index 61736c8978c51c4ea9a310b8aae210964007cb51..8686a4b694012de612c504bcf8e4a4f466d7e1e6 100644 --- a/lib/core/core/src/commands/keys.rs +++ b/lib/core/core/src/commands/keys.rs @@ -19,9 +19,9 @@ use crate::commands::DursExecutableCoreCommand; use crate::errors::DursCoreError; use crate::DursCore; use clap::arg_enum; -use clear_on_drop::clear::Clear; use durs_conf::keypairs::cli::*; use durs_conf::DuRsConf; +use zeroize::Zeroize; #[derive(StructOpt, Debug, Clone)] #[structopt( @@ -121,7 +121,8 @@ pub struct ClearOpt { key: KeyKind, } -#[derive(StructOpt, Debug, Clone)] +#[derive(StructOpt, Debug, Clone, Zeroize)] +#[zeroize(drop)] /// SaltPasswordOpt pub struct SaltPasswordOpt { #[structopt(long = "salt")] @@ -133,14 +134,6 @@ pub struct SaltPasswordOpt { pub password: String, } -impl Drop for SaltPasswordOpt { - #[inline] - fn drop(&mut self) { - <String as Clear>::clear(&mut self.salt); - <String as Clear>::clear(&mut self.password); - } -} - #[derive(StructOpt, Debug, Copy, Clone)] /// WizardOpt pub struct WizardOpt {} diff --git a/lib/crypto/Cargo.toml b/lib/crypto/Cargo.toml index 06bf66cec28c0ef8fab90b0bf06bd31a05c383af..e5eb0616ee5e798c6c86fdb2af62a73e0a0f2b42 100644 --- a/lib/crypto/Cargo.toml +++ b/lib/crypto/Cargo.toml @@ -17,7 +17,6 @@ base64 = "0.11.0" bs58 = "0.3.0" byteorder = "1.3.2" chacha20-poly1305-aead = "0.1.2" -clear_on_drop = "0.2.3" failure = "0.1.5" ring = "0.16.9" scrypt = { version = "0.2", default-features = false } @@ -26,6 +25,7 @@ serde_derive = "1.0.*" durs-common-tools = { path = "../tools/common-tools", version = "0.2.0" } log = "0.4.*" unwrap = "1.2.1" +zeroize = { version = "1.1.0", features = ["zeroize_derive"] } [dev-dependencies] bincode = "1.2.0" diff --git a/lib/crypto/src/keys/ed25519.rs b/lib/crypto/src/keys/ed25519.rs index bfb8cc9ced64bdb704323b53fd9f8a878300c613..d0aac4b714bffbc5aa36a9ad4abce8474b4c6e3f 100644 --- a/lib/crypto/src/keys/ed25519.rs +++ b/lib/crypto/src/keys/ed25519.rs @@ -25,7 +25,6 @@ use crate::bases::b58::{bytes_to_str_base58, ToBase58}; use crate::bases::*; use crate::seeds::Seed32; use base64; -use clear_on_drop::clear::Clear; use ring::signature::{Ed25519KeyPair as RingKeyPair, KeyPair, UnparsedPublicKey, ED25519}; use serde::de::{Deserialize, Deserializer, Error, SeqAccess, Visitor}; use serde::ser::{Serialize, SerializeTuple, Serializer}; @@ -35,6 +34,7 @@ use std::fmt::{Debug, Display, Formatter}; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use unwrap::unwrap; +use zeroize::Zeroize; /// Maximal size of a public key in bytes pub static PUBKEY_SIZE_IN_BYTES: &usize = &32; @@ -333,6 +333,8 @@ impl KeyPairFromSeed32Generator { } } +#[derive(Zeroize)] +#[zeroize(drop)] /// Salted password pub struct SaltedPassword { salt: String, @@ -346,14 +348,6 @@ impl SaltedPassword { } } -impl Drop for SaltedPassword { - #[inline] - fn drop(&mut self) { - <String as Clear>::clear(&mut self.salt); - <String as Clear>::clear(&mut self.password); - } -} - /// Keypair generator with given parameters for `scrypt` keypair function. #[derive(Copy, Clone)] pub struct KeyPairFromSaltedPasswordGenerator { diff --git a/lib/crypto/src/seeds.rs b/lib/crypto/src/seeds.rs index ab9d9f68d2ffc8c561d391d715b42b9c1368b1f1..7d03033ca6d1b12d5b4a3c33da40afaa9717818a 100644 --- a/lib/crypto/src/seeds.rs +++ b/lib/crypto/src/seeds.rs @@ -17,13 +17,14 @@ use crate::bases::b58::{bytes_to_str_base58, ToBase58}; use crate::bases::*; -use clear_on_drop::clear::Clear; use durs_common_tools::fatal_error; use ring::rand; use std::fmt::{self, Debug, Display, Formatter}; +use zeroize::Zeroize; /// Store a 32 bytes seed used to generate keys. -#[derive(Clone, Default, Deserialize, PartialEq, Eq, Hash, Serialize)] +#[derive(Clone, Default, Deserialize, PartialEq, Eq, Hash, Serialize, Zeroize)] +#[zeroize(drop)] pub struct Seed32([u8; 32]); impl AsRef<[u8]> for Seed32 { @@ -50,13 +51,6 @@ impl Display for Seed32 { } } -impl Drop for Seed32 { - #[inline] - fn drop(&mut self) { - <[u8; 32] as Clear>::clear(&mut self.0); - } -} - impl Seed32 { #[inline] /// Create new seed