Skip to content

feat: remove crypto storage backend #2172

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

Merged
merged 1 commit into from
Apr 7, 2022
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
2 changes: 0 additions & 2 deletions Cargo.lock

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

33 changes: 1 addition & 32 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use partial_struct::PartialStruct;
use std::convert::TryFrom;
use witnet_crypto::hash::HashFunction;
use witnet_data_structures::chain::{ConsensusConstants, Environment, PartialConsensusConstants};
use witnet_protected::{Protected, ProtectedString};
use witnet_protected::ProtectedString;

/// The total configuration object that contains all other, more
/// specific, configuration objects (connections, storage, etc).
Expand Down Expand Up @@ -276,15 +276,6 @@ pub struct Storage {
#[partial_struct(skip)]
#[partial_struct(serde(default))]
pub backend: StorageBackend,
/// Whether or not the information should be encrypted before
/// being stored with this password
#[partial_struct(skip)]
#[partial_struct(serde(default))]
#[partial_struct(serde(
serialize_with = "to_protected_string",
deserialize_with = "as_protected_string"
))]
pub password: Option<Protected>,
/// Path to the directory that will contain the database. Used
/// only if backend is RocksDB.
pub db_path: PathBuf,
Expand Down Expand Up @@ -707,7 +698,6 @@ impl Storage {
pub fn from_partial(config: &PartialStorage, defaults: &dyn Defaults) -> Self {
Storage {
backend: config.backend.clone(),
password: config.password.clone(),
db_path: config
.db_path
.to_owned()
Expand All @@ -719,8 +709,6 @@ impl Storage {
pub fn to_partial(&self) -> PartialStorage {
PartialStorage {
backend: self.backend.clone(),
// password should not be exported
password: None,
db_path: Some(self.db_path.clone()),
master_key_import_path: self.master_key_import_path.clone(),
}
Expand Down Expand Up @@ -1133,24 +1121,6 @@ where
})
}

fn to_protected_string<S>(val: &Option<Protected>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match val {
Some(_) => serializer.serialize_str("**** REDACTED ****"),
None => serializer.serialize_none(),
}
}

fn as_protected_string<'de, D>(deserializer: D) -> Result<Option<Protected>, D::Error>
where
D: serde::Deserializer<'de>,
{
let passwd = String::deserialize(deserializer)?;
Ok(Some(passwd.into()))
}

// https://stackoverflow.com/a/43627388
fn deserialize_one_or_many<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
where
Expand Down Expand Up @@ -1199,7 +1169,6 @@ mod tests {
fn test_storage_from_partial() {
let partial_config = PartialStorage {
backend: StorageBackend::RocksDB,
password: None, // password should not be exported
db_path: Some(PathBuf::from("other")),
master_key_import_path: None,
};
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ witnet_futures_utils = { path = "../futures_utils" }
witnet_p2p = { path = "../p2p" }
witnet_protected = { path = "../protected", features = ["with-serde"] }
witnet_rad = { path = "../rad" }
witnet_storage = { path = "../storage", features = ["rocksdb-backend", "crypto-backend"] }
witnet_storage = { path = "../storage", features = ["rocksdb-backend"] }
witnet_util = { path = "../util" }
witnet_validations = { path = "../validations" }

Expand Down
23 changes: 2 additions & 21 deletions node/src/storage_mngr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ impl Handler<Configure> for StorageManager {
"Configured {:#?} as the storage backend",
storage_conf.backend
);
if storage_conf.password.is_some() {
log::info!("Storage backend is using encryption");
}

Ok(())
}
Expand Down Expand Up @@ -301,33 +298,17 @@ impl Handler<GetBackend> for StorageManager {
}
}

macro_rules! encrypted_backend {
($backend:expr, $password_opt:expr) => {
if let Some(password) = $password_opt {
Arc::new(backends::crypto::Backend::new(password, $backend))
as Arc<dyn storage::Storage + Send + Sync>
} else {
Arc::new($backend) as Arc<dyn storage::Storage + Send + Sync>
}
};
}

/// Create storage backend according to provided config
pub fn create_appropriate_backend(
conf: &config::Storage,
) -> Result<Arc<dyn storage::Storage + Send + Sync>, failure::Error> {
let passwd = conf.password.clone();

match conf.backend {
config::StorageBackend::HashMap => Ok(encrypted_backend!(
backends::hashmap::Backend::default(),
passwd
)),
config::StorageBackend::HashMap => Ok(Arc::new(backends::hashmap::Backend::default())),
config::StorageBackend::RocksDB => {
let path = conf.db_path.as_path();

backends::rocksdb::Backend::open_default(path)
.map(|backend| encrypted_backend!(backend, passwd))
.map(|backend| -> Arc<dyn storage::Storage + Send + Sync> { Arc::new(backend) })
.map_err(|e| as_failure!(e))
}
}
Expand Down
4 changes: 0 additions & 4 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ description = "Witnet storage module that conveniently abstracts a key/value API
failure = "0.1.8"
rocksdb = { version = "0.13.0", optional = true }

witnet_crypto = { path = "../crypto", optional = true }
witnet_protected = { path = "../protected", optional = true }

[features]
rocksdb-backend = ["rocksdb"]
crypto-backend = ["witnet_crypto", "witnet_protected"]
132 changes: 0 additions & 132 deletions storage/src/backends/crypto.rs

This file was deleted.

2 changes: 0 additions & 2 deletions storage/src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! containing state for specific storage solutions (databases,
//! volatile memory, flat files, etc.).

#[cfg(feature = "crypto-backend")]
pub mod crypto;
pub mod hashmap;
pub mod nobackend;
#[cfg(feature = "rocksdb-backend")]
Expand Down