config work
This commit is contained in:
@@ -29,35 +29,55 @@ impl ProtectedStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_all(&self) -> Result<(), String> {
|
||||
// Delete all known keys
|
||||
if self.remove_user_secret_string("node_id").await? {
|
||||
debug!("deleted protected_store key 'node_id'");
|
||||
}
|
||||
if self.remove_user_secret_string("node_id_secret").await? {
|
||||
debug!("deleted protected_store key 'node_id_secret'");
|
||||
}
|
||||
if self.remove_user_secret_string("_test_key").await? {
|
||||
debug!("deleted protected_store key '_test_key'");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn init(&self) -> Result<(), String> {
|
||||
let c = self.config.get();
|
||||
let mut inner = self.inner.lock();
|
||||
if !c.protected_store.always_use_insecure_storage {
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "android")] {
|
||||
inner.keyring_manager = KeyringManager::new_secure(&c.program_name, intf::native::utils::android::get_android_globals()).ok();
|
||||
} else {
|
||||
inner.keyring_manager = KeyringManager::new_secure(&c.program_name).ok();
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
if !c.protected_store.always_use_insecure_storage {
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "android")] {
|
||||
inner.keyring_manager = KeyringManager::new_secure(&c.program_name, intf::native::utils::android::get_android_globals()).ok();
|
||||
} else {
|
||||
inner.keyring_manager = KeyringManager::new_secure(&c.program_name).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c.protected_store.always_use_insecure_storage
|
||||
|| c.protected_store.allow_insecure_fallback)
|
||||
&& inner.keyring_manager.is_none()
|
||||
{
|
||||
let insecure_fallback_directory =
|
||||
Path::new(&c.protected_store.insecure_fallback_directory);
|
||||
let insecure_keyring_file = insecure_fallback_directory
|
||||
.to_owned()
|
||||
.join("insecure_keyring");
|
||||
inner.keyring_manager = Some(
|
||||
KeyringManager::new_insecure(&c.program_name, &insecure_keyring_file)
|
||||
.map_err(map_to_string)
|
||||
.map_err(logthru_pstore!(error))?,
|
||||
);
|
||||
}
|
||||
if inner.keyring_manager.is_none() {
|
||||
return Err("Could not initialize the protected store.".to_owned());
|
||||
}
|
||||
}
|
||||
if (c.protected_store.always_use_insecure_storage
|
||||
|| c.protected_store.allow_insecure_fallback)
|
||||
&& inner.keyring_manager.is_none()
|
||||
{
|
||||
let insecure_fallback_directory =
|
||||
Path::new(&c.protected_store.insecure_fallback_directory);
|
||||
let insecure_keyring_file = insecure_fallback_directory
|
||||
.to_owned()
|
||||
.join("insecure_keyring");
|
||||
inner.keyring_manager = Some(
|
||||
KeyringManager::new_insecure(&c.program_name, &insecure_keyring_file)
|
||||
.map_err(map_to_string)
|
||||
.map_err(logthru_pstore!(error))?,
|
||||
);
|
||||
}
|
||||
if inner.keyring_manager.is_none() {
|
||||
return Err("Could not initialize the protected store.".to_owned());
|
||||
|
||||
if c.protected_store.delete {
|
||||
self.delete_all().await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@@ -27,6 +27,12 @@ impl TableStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_all(&self) -> Result<(), String> {
|
||||
// Delete all known keys
|
||||
self.delete("crypto_caches").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn init(&self) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -141,6 +141,13 @@ pub struct VeilidConfigNetwork {
|
||||
#[derive(Default, Clone)]
|
||||
pub struct VeilidConfigTableStore {
|
||||
pub directory: String,
|
||||
pub delete: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct VeilidConfigBlockStore {
|
||||
pub directory: String,
|
||||
pub delete: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@@ -148,6 +155,7 @@ pub struct VeilidConfigProtectedStore {
|
||||
pub allow_insecure_fallback: bool,
|
||||
pub always_use_insecure_storage: bool,
|
||||
pub insecure_fallback_directory: String,
|
||||
pub delete: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@@ -168,6 +176,7 @@ pub struct VeilidConfigInner {
|
||||
pub capabilities: VeilidConfigCapabilities,
|
||||
pub protected_store: VeilidConfigProtectedStore,
|
||||
pub table_store: VeilidConfigTableStore,
|
||||
pub block_store: VeilidConfigBlockStore,
|
||||
pub network: VeilidConfigNetwork,
|
||||
}
|
||||
|
||||
@@ -216,9 +225,13 @@ impl VeilidConfig {
|
||||
get_config!(inner.capabilities.protocol_connect_wss);
|
||||
get_config!(inner.capabilities.protocol_accept_wss);
|
||||
get_config!(inner.table_store.directory);
|
||||
get_config!(inner.table_store.delete);
|
||||
get_config!(inner.block_store.directory);
|
||||
get_config!(inner.block_store.delete);
|
||||
get_config!(inner.protected_store.allow_insecure_fallback);
|
||||
get_config!(inner.protected_store.always_use_insecure_storage);
|
||||
get_config!(inner.protected_store.insecure_fallback_directory);
|
||||
get_config!(inner.protected_store.delete);
|
||||
get_config!(inner.network.node_id);
|
||||
get_config!(inner.network.node_id_secret);
|
||||
get_config!(inner.network.max_connections);
|
||||
|
@@ -124,6 +124,12 @@ impl VeilidCore {
|
||||
crypto.init().await?;
|
||||
inner.crypto = Some(crypto.clone());
|
||||
|
||||
// Set up block store
|
||||
// trace!("VeilidCore::internal_startup init block store");
|
||||
// let block_store = BlockStore::new(config.clone());
|
||||
// block_store.init().await?;
|
||||
// inner.block_store = Some(block_store.clone();)
|
||||
|
||||
// Set up attachment manager
|
||||
trace!("VeilidCore::internal_startup init attachment manager");
|
||||
let cb = setup.update_callback;
|
||||
|
Reference in New Issue
Block a user