Skip to content
Snippets Groups Projects
Commit 9d2123b3 authored by Éloïs's avatar Éloïs
Browse files

[fix] crypto: #185

parent d0963c3e
No related branches found
No related tags found
1 merge request!267Resolve "Migrate clear_on_drop -> zeroize"
...@@ -556,14 +556,6 @@ dependencies = [ ...@@ -556,14 +556,6 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "cloudabi" name = "cloudabi"
version = "0.0.3" version = "0.0.3"
...@@ -861,7 +853,6 @@ dependencies = [ ...@@ -861,7 +853,6 @@ dependencies = [
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -870,6 +861,7 @@ dependencies = [ ...@@ -870,6 +861,7 @@ dependencies = [
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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]] [[package]]
...@@ -1017,7 +1009,6 @@ version = "0.3.0-dev" ...@@ -1017,7 +1009,6 @@ version = "0.3.0-dev"
dependencies = [ dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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", "dubp-currency-params 0.2.0",
"dup-crypto 0.7.0", "dup-crypto 0.7.0",
"durs-bc 0.3.0-dev", "durs-bc 0.3.0-dev",
...@@ -1038,6 +1029,7 @@ dependencies = [ ...@@ -1038,6 +1029,7 @@ dependencies = [
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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]] [[package]]
...@@ -3111,6 +3103,25 @@ dependencies = [ ...@@ -3111,6 +3103,25 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "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] [metadata]
"checksum actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09e55f0a5c2ca15795035d90c46bd0e73a5123b72f68f12596d6ba5282051380" "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" "checksum actix-connect 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2b61480a8d30c94d5c883d79ef026b02ad6809931b0a4bb703f9545cd8c986"
...@@ -3164,7 +3175,6 @@ dependencies = [ ...@@ -3164,7 +3175,6 @@ dependencies = [
"checksum chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77d2058ba29594f69c75e8a9018e0485e3914ca5084e3613cd64529042f5423b" "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 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 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 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 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" "checksum combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
...@@ -3390,3 +3400,5 @@ dependencies = [ ...@@ -3390,3 +3400,5 @@ dependencies = [
"checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" "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 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 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"
...@@ -12,7 +12,6 @@ path = "src/lib.rs" ...@@ -12,7 +12,6 @@ path = "src/lib.rs"
[dependencies] [dependencies]
chrono = "0.4" chrono = "0.4"
clap = "2.33.0" clap = "2.33.0"
clear_on_drop = "0.2.3"
durs-bc = { path = "../../modules/blockchain/blockchain" } durs-bc = { path = "../../modules/blockchain/blockchain" }
durs-common-tools = { path = "../../tools/common-tools" } durs-common-tools = { path = "../../tools/common-tools" }
durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" } durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" }
...@@ -33,5 +32,6 @@ serde_derive = "1.0.*" ...@@ -33,5 +32,6 @@ serde_derive = "1.0.*"
serde_json = "1.0.*" serde_json = "1.0.*"
structopt= "0.3.9" structopt= "0.3.9"
unwrap = "1.2.1" unwrap = "1.2.1"
zeroize = { version = "1.1.0", features = ["zeroize_derive"] }
[features] [features]
...@@ -19,9 +19,9 @@ use crate::commands::DursExecutableCoreCommand; ...@@ -19,9 +19,9 @@ use crate::commands::DursExecutableCoreCommand;
use crate::errors::DursCoreError; use crate::errors::DursCoreError;
use crate::DursCore; use crate::DursCore;
use clap::arg_enum; use clap::arg_enum;
use clear_on_drop::clear::Clear;
use durs_conf::keypairs::cli::*; use durs_conf::keypairs::cli::*;
use durs_conf::DuRsConf; use durs_conf::DuRsConf;
use zeroize::Zeroize;
#[derive(StructOpt, Debug, Clone)] #[derive(StructOpt, Debug, Clone)]
#[structopt( #[structopt(
...@@ -121,7 +121,8 @@ pub struct ClearOpt { ...@@ -121,7 +121,8 @@ pub struct ClearOpt {
key: KeyKind, key: KeyKind,
} }
#[derive(StructOpt, Debug, Clone)] #[derive(StructOpt, Debug, Clone, Zeroize)]
#[zeroize(drop)]
/// SaltPasswordOpt /// SaltPasswordOpt
pub struct SaltPasswordOpt { pub struct SaltPasswordOpt {
#[structopt(long = "salt")] #[structopt(long = "salt")]
...@@ -133,14 +134,6 @@ pub struct SaltPasswordOpt { ...@@ -133,14 +134,6 @@ pub struct SaltPasswordOpt {
pub password: String, 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)] #[derive(StructOpt, Debug, Copy, Clone)]
/// WizardOpt /// WizardOpt
pub struct WizardOpt {} pub struct WizardOpt {}
......
...@@ -17,7 +17,6 @@ base64 = "0.11.0" ...@@ -17,7 +17,6 @@ base64 = "0.11.0"
bs58 = "0.3.0" bs58 = "0.3.0"
byteorder = "1.3.2" byteorder = "1.3.2"
chacha20-poly1305-aead = "0.1.2" chacha20-poly1305-aead = "0.1.2"
clear_on_drop = "0.2.3"
failure = "0.1.5" failure = "0.1.5"
ring = "0.16.9" ring = "0.16.9"
scrypt = { version = "0.2", default-features = false } scrypt = { version = "0.2", default-features = false }
...@@ -26,6 +25,7 @@ serde_derive = "1.0.*" ...@@ -26,6 +25,7 @@ serde_derive = "1.0.*"
durs-common-tools = { path = "../tools/common-tools", version = "0.2.0" } durs-common-tools = { path = "../tools/common-tools", version = "0.2.0" }
log = "0.4.*" log = "0.4.*"
unwrap = "1.2.1" unwrap = "1.2.1"
zeroize = { version = "1.1.0", features = ["zeroize_derive"] }
[dev-dependencies] [dev-dependencies]
bincode = "1.2.0" bincode = "1.2.0"
......
...@@ -25,7 +25,6 @@ use crate::bases::b58::{bytes_to_str_base58, ToBase58}; ...@@ -25,7 +25,6 @@ use crate::bases::b58::{bytes_to_str_base58, ToBase58};
use crate::bases::*; use crate::bases::*;
use crate::seeds::Seed32; use crate::seeds::Seed32;
use base64; use base64;
use clear_on_drop::clear::Clear;
use ring::signature::{Ed25519KeyPair as RingKeyPair, KeyPair, UnparsedPublicKey, ED25519}; use ring::signature::{Ed25519KeyPair as RingKeyPair, KeyPair, UnparsedPublicKey, ED25519};
use serde::de::{Deserialize, Deserializer, Error, SeqAccess, Visitor}; use serde::de::{Deserialize, Deserializer, Error, SeqAccess, Visitor};
use serde::ser::{Serialize, SerializeTuple, Serializer}; use serde::ser::{Serialize, SerializeTuple, Serializer};
...@@ -35,6 +34,7 @@ use std::fmt::{Debug, Display, Formatter}; ...@@ -35,6 +34,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::marker::PhantomData; use std::marker::PhantomData;
use unwrap::unwrap; use unwrap::unwrap;
use zeroize::Zeroize;
/// Maximal size of a public key in bytes /// Maximal size of a public key in bytes
pub static PUBKEY_SIZE_IN_BYTES: &usize = &32; pub static PUBKEY_SIZE_IN_BYTES: &usize = &32;
...@@ -333,6 +333,8 @@ impl KeyPairFromSeed32Generator { ...@@ -333,6 +333,8 @@ impl KeyPairFromSeed32Generator {
} }
} }
#[derive(Zeroize)]
#[zeroize(drop)]
/// Salted password /// Salted password
pub struct SaltedPassword { pub struct SaltedPassword {
salt: String, salt: String,
...@@ -346,14 +348,6 @@ impl SaltedPassword { ...@@ -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. /// Keypair generator with given parameters for `scrypt` keypair function.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct KeyPairFromSaltedPasswordGenerator { pub struct KeyPairFromSaltedPasswordGenerator {
......
...@@ -17,13 +17,14 @@ ...@@ -17,13 +17,14 @@
use crate::bases::b58::{bytes_to_str_base58, ToBase58}; use crate::bases::b58::{bytes_to_str_base58, ToBase58};
use crate::bases::*; use crate::bases::*;
use clear_on_drop::clear::Clear;
use durs_common_tools::fatal_error; use durs_common_tools::fatal_error;
use ring::rand; use ring::rand;
use std::fmt::{self, Debug, Display, Formatter}; use std::fmt::{self, Debug, Display, Formatter};
use zeroize::Zeroize;
/// Store a 32 bytes seed used to generate keys. /// 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]); pub struct Seed32([u8; 32]);
impl AsRef<[u8]> for Seed32 { impl AsRef<[u8]> for Seed32 {
...@@ -50,13 +51,6 @@ impl Display 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 { impl Seed32 {
#[inline] #[inline]
/// Create new seed /// Create new seed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment