arti-client: Use a default keystore config if `experimental-api` is disabled.

The `experimental-api` was only meant to apply to the use of the
unstable `ArtiNativeKeystoreConfig` in the Arti config.
`experimental-api` was _not_ supposed to be used for enabling/disabling
the keystore (that's what the `enabled` flag is for).
This commit is contained in:
Gabriela Moldovan 2023-07-18 14:06:58 +01:00
parent b4bf421c11
commit f18e773332
No known key found for this signature in database
GPG Key ID: 3946E0ADE72BAC99
2 changed files with 17 additions and 20 deletions

View File

@ -600,30 +600,27 @@ impl<R: Runtime> TorClient<R> {
HsClientConnector::new(runtime.clone(), circpool, config, housekeeping)?
};
let keymgr = if let Some(keystore) = config.storage.keystore() {
let keystore = config.storage.keystore();
// If enabled is true or set to "auto", initialize the keystore
//
// In this case "auto" means true, because experimental-api is enabled
// (otherwise, config.storage.keystore() would've returned None).
let keymgr = if keystore.enabled.as_bool().unwrap_or(true) {
let mut stores: Vec<Box<dyn Keystore>> = vec![];
// TODO HSS: `expand_keystore_dir` shouldn't be escaping into a crate API boundary.
// The keystore_dir should probably be expanded at `build()` time.
let key_store_dir = keystore.expand_keystore_dir()?;
let permissions = config.storage.permissions();
// If enabled is true or set to "auto", initialize the keystore
//
// In this case "auto" means true, because experimental-api is enabled
// (otherwise, config.storage.keystore() would've returned None).
if keystore.enabled.as_bool().unwrap_or(true) {
let mut stores: Vec<Box<dyn Keystore>> = vec![];
let arti_store =
ArtiNativeKeystore::from_path_and_mistrust(&key_store_dir, permissions)?;
info!("Using keystore from {key_store_dir:?}");
stores.push(Box::new(arti_store));
let arti_store =
ArtiNativeKeystore::from_path_and_mistrust(&key_store_dir, permissions)?;
info!("Using keystore from {key_store_dir:?}");
stores.push(Box::new(arti_store));
// TODO hs: add support for the C Tor key store
Some(Arc::new(KeyMgr::new(stores)))
} else {
info!("Running without a keystore");
None
}
// TODO hs: add support for the C Tor key store
Some(Arc::new(KeyMgr::new(stores)))
} else {
info!("Running without a keystore");
None
};

View File

@ -222,15 +222,15 @@ impl StorageConfig {
}
/// Return the keystore config
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn keystore(&self) -> Option<&ArtiNativeKeystoreConfig> {
pub(crate) fn keystore(&self) -> ArtiNativeKeystoreConfig {
#[cfg(feature = "experimental-api")]
{
Some(&self.keystore)
self.keystore.clone()
}
#[cfg(not(feature = "experimental-api"))]
{
None
Default::default()
}
}
/// Return the FS permissions to use for state and cache directories.