removing dead code + extra docs
This commit is contained in:
@@ -201,29 +201,7 @@ pub struct KeyManager {
|
||||
ack_key: Arc<AckKey>,
|
||||
}
|
||||
|
||||
// The expected flow of a KeyManager "lifetime" is as follows:
|
||||
/*
|
||||
1. ::new() is called during client-init
|
||||
2. after gateway registration is completed [in init] ::insert_gateway_shared_key() is called
|
||||
3. ::store_keys() is called before init finishes execution.
|
||||
4. ::load_keys() is called at the beginning of each subsequent client-run
|
||||
5. [not implemented] ::rotate_keys() is called periodically during client-run I presume?
|
||||
*/
|
||||
|
||||
impl KeyManager {
|
||||
// /// Creates new instance of a [`KeyManager`]
|
||||
// pub fn new<R>(rng: &mut R) -> Self
|
||||
// where
|
||||
// R: RngCore + CryptoRng,
|
||||
// {
|
||||
// KeyManager {
|
||||
// identity_keypair: Arc::new(identity::KeyPair::new(rng)),
|
||||
// encryption_keypair: Arc::new(encryption::KeyPair::new(rng)),
|
||||
// gateway_shared_key: None,
|
||||
// ack_key: Arc::new(AckKey::new(rng)),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn from_keys(
|
||||
id_keypair: identity::KeyPair,
|
||||
enc_keypair: encryption::KeyPair,
|
||||
@@ -246,162 +224,35 @@ impl KeyManager {
|
||||
store.store_keys(self).await
|
||||
}
|
||||
|
||||
//
|
||||
// /// Loads previously stored client keys from the disk.
|
||||
// fn load_client_keys(client_pathfinder: &ClientKeyPathfinder) -> io::Result<Self> {
|
||||
// let identity_keypair: identity::KeyPair =
|
||||
// nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
|
||||
// client_pathfinder.private_identity_key().to_owned(),
|
||||
// client_pathfinder.public_identity_key().to_owned(),
|
||||
// ))?;
|
||||
// let encryption_keypair: encryption::KeyPair =
|
||||
// nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
|
||||
// client_pathfinder.private_encryption_key().to_owned(),
|
||||
// client_pathfinder.public_encryption_key().to_owned(),
|
||||
// ))?;
|
||||
//
|
||||
// let ack_key: AckKey = nym_pemstore::load_key(client_pathfinder.ack_key())?;
|
||||
//
|
||||
// Ok(KeyManager {
|
||||
// identity_keypair: Arc::new(identity_keypair),
|
||||
// encryption_keypair: Arc::new(encryption_keypair),
|
||||
// gateway_shared_key: None,
|
||||
// ack_key: Arc::new(ack_key),
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// /// Loads previously stored keys from the disk. Fails if not all, including the shared gateway
|
||||
// /// key, is available.
|
||||
// pub fn load_keys_from_disk(client_pathfinder: &ClientKeyPathfinder) -> io::Result<Self> {
|
||||
// let mut key_manager = Self::load_client_keys(client_pathfinder)?;
|
||||
//
|
||||
// let gateway_shared_key: SharedKeys =
|
||||
// nym_pemstore::load_key(client_pathfinder.gateway_shared_key())?;
|
||||
//
|
||||
// key_manager.gateway_shared_key = Some(Arc::new(gateway_shared_key));
|
||||
//
|
||||
// Ok(key_manager)
|
||||
// }
|
||||
//
|
||||
// /// Loads previously stored keys from the disk. Fails if client keys are not available, but the
|
||||
// /// shared gateway key is optional.
|
||||
// pub fn load_keys_from_disk_but_gateway_is_optional(
|
||||
// client_pathfinder: &ClientKeyPathfinder,
|
||||
// ) -> io::Result<Self> {
|
||||
// let mut key_manager = Self::load_client_keys(client_pathfinder)?;
|
||||
//
|
||||
// let gateway_shared_key: Result<SharedKeys, io::Error> =
|
||||
// nym_pemstore::load_key(client_pathfinder.gateway_shared_key());
|
||||
//
|
||||
// // It's ok if the gateway key was not found
|
||||
// let gateway_shared_key = match gateway_shared_key {
|
||||
// Err(err) if err.kind() == io::ErrorKind::NotFound => Ok(None),
|
||||
// Err(err) => Err(err),
|
||||
// Ok(key) => Ok(Some(key)),
|
||||
// }?;
|
||||
//
|
||||
// key_manager.gateway_shared_key = gateway_shared_key.map(Arc::new);
|
||||
//
|
||||
// Ok(key_manager)
|
||||
// }
|
||||
//
|
||||
// /// Stores all available keys on the disk.
|
||||
// // While perhaps there is no much point in storing the `AckKey` on the disk,
|
||||
// // it is done so for the consistency sake so that you wouldn't require an rng instance
|
||||
// // during `load_keys` to generate the said key.
|
||||
// pub fn store_keys_on_disk(&self, client_pathfinder: &ClientKeyPathfinder) -> io::Result<()> {
|
||||
// nym_pemstore::store_keypair(
|
||||
// self.identity_keypair.as_ref(),
|
||||
// &nym_pemstore::KeyPairPath::new(
|
||||
// client_pathfinder.private_identity_key().to_owned(),
|
||||
// client_pathfinder.public_identity_key().to_owned(),
|
||||
// ),
|
||||
// )?;
|
||||
// nym_pemstore::store_keypair(
|
||||
// self.encryption_keypair.as_ref(),
|
||||
// &nym_pemstore::KeyPairPath::new(
|
||||
// client_pathfinder.private_encryption_key().to_owned(),
|
||||
// client_pathfinder.public_encryption_key().to_owned(),
|
||||
// ),
|
||||
// )?;
|
||||
//
|
||||
// nym_pemstore::store_key(self.ack_key.as_ref(), client_pathfinder.ack_key())?;
|
||||
//
|
||||
// match self.gateway_shared_key.as_ref() {
|
||||
// None => debug!("No gateway shared key available to store!"),
|
||||
// Some(gate_key) => {
|
||||
// nym_pemstore::store_key(gate_key.as_ref(), client_pathfinder.gateway_shared_key())?
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// pub fn store_gateway_key_on_disk(
|
||||
// &self,
|
||||
// client_pathfinder: &ClientKeyPathfinder,
|
||||
// ) -> io::Result<()> {
|
||||
// match self.gateway_shared_key.as_ref() {
|
||||
// None => {
|
||||
// return Err(io::Error::new(
|
||||
// io::ErrorKind::Other,
|
||||
// "trying to store a non-existing key",
|
||||
// ))
|
||||
// }
|
||||
// Some(gate_key) => {
|
||||
// nym_pemstore::store_key(gate_key.as_ref(), client_pathfinder.gateway_shared_key())?
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
/// Overwrite the existing identity keypair
|
||||
#[deprecated]
|
||||
pub fn set_identity_keypair(&mut self, id_keypair: identity::KeyPair) {
|
||||
self.identity_keypair = Arc::new(id_keypair);
|
||||
}
|
||||
|
||||
/// Gets an atomically reference counted pointer to [`identity::KeyPair`].
|
||||
pub fn identity_keypair(&self) -> Arc<identity::KeyPair> {
|
||||
Arc::clone(&self.identity_keypair)
|
||||
}
|
||||
|
||||
/// Overwrite the existing encryption keypair
|
||||
#[deprecated]
|
||||
pub fn set_encryption_keypair(&mut self, enc_keypair: encryption::KeyPair) {
|
||||
self.encryption_keypair = Arc::new(enc_keypair);
|
||||
}
|
||||
|
||||
/// Gets an atomically reference counted pointer to [`encryption::KeyPair`].
|
||||
pub fn encryption_keypair(&self) -> Arc<encryption::KeyPair> {
|
||||
Arc::clone(&self.encryption_keypair)
|
||||
}
|
||||
|
||||
/// Overwrite the existing ack key
|
||||
#[deprecated]
|
||||
pub fn set_ack_key(&mut self, ack_key: AckKey) {
|
||||
self.ack_key = Arc::new(ack_key);
|
||||
}
|
||||
|
||||
/// Gets an atomically reference counted pointer to [`AckKey`].
|
||||
pub fn ack_key(&self) -> Arc<AckKey> {
|
||||
Arc::clone(&self.ack_key)
|
||||
}
|
||||
|
||||
// /// After shared key with the gateway is derived, puts its ownership to this instance of a [`KeyManager`].
|
||||
// pub fn insert_gateway_shared_key(&mut self, gateway_shared_key: Arc<SharedKeys>) {
|
||||
// self.gateway_shared_key = Some(gateway_shared_key)
|
||||
// }
|
||||
|
||||
/// Gets an atomically reference counted pointer to [`SharedKey`].
|
||||
pub fn gateway_shared_key(&self) -> Arc<SharedKeys> {
|
||||
Arc::clone(&self.gateway_shared_key)
|
||||
}
|
||||
|
||||
// pub fn is_gateway_key_set(&self) -> bool {
|
||||
// self.gateway_shared_key.is_some()
|
||||
// }
|
||||
pub fn remove_gateway_key(self) -> KeyManagerBuilder {
|
||||
if Arc::strong_count(&self.gateway_shared_key) > 1 {
|
||||
panic!("attempted to remove gateway key whilst still holding multiple references!")
|
||||
}
|
||||
KeyManagerBuilder {
|
||||
identity_keypair: self.identity_keypair,
|
||||
encryption_keypair: self.encryption_keypair,
|
||||
ack_key: self.ack_key,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn _assert_keys_zeroize_on_drop() {
|
||||
|
||||
@@ -33,14 +33,12 @@
|
||||
mod client;
|
||||
mod config;
|
||||
mod connection_state;
|
||||
mod keys;
|
||||
mod native_client;
|
||||
mod paths;
|
||||
mod socks5_client;
|
||||
|
||||
pub use client::{DisconnectedMixnetClient, IncludedSurbs, MixnetClientBuilder};
|
||||
pub use config::Config;
|
||||
pub use keys::{Keys, KeysArc};
|
||||
pub use config::{Config, KeyMode};
|
||||
pub use native_client::MixnetClient;
|
||||
pub use native_client::MixnetClientSender;
|
||||
pub use nym_client_core::{
|
||||
@@ -69,5 +67,5 @@ pub use nym_sphinx::{
|
||||
receiver::ReconstructedMessage,
|
||||
};
|
||||
pub use nym_topology::{provider_trait::TopologyProvider, NymTopology};
|
||||
pub use paths::{GatewayKeyMode, KeyMode, StoragePaths};
|
||||
pub use paths::StoragePaths;
|
||||
pub use socks5_client::Socks5MixnetClient;
|
||||
|
||||
@@ -42,18 +42,18 @@ const DEFAULT_NUMBER_OF_SURBS: u32 = 5;
|
||||
pub struct MixnetClientBuilder<S: MixnetClientStorage = Ephemeral> {
|
||||
config: Config,
|
||||
storage_paths: Option<StoragePaths>,
|
||||
// keys: Option<Keys>,
|
||||
gateway_config: Option<GatewayEndpointConfig>,
|
||||
socks5_config: Option<Socks5>,
|
||||
custom_topology_provider: Option<Box<dyn TopologyProvider>>,
|
||||
|
||||
// TODO: change that
|
||||
gateway_endpoint_path: Option<PathBuf>,
|
||||
// TODO: incorporate it properly into `MixnetClientStorage` (I will need it in wasm anyway)
|
||||
gateway_endpoint_config_path: Option<PathBuf>,
|
||||
|
||||
storage: S,
|
||||
}
|
||||
|
||||
impl MixnetClientBuilder<Ephemeral> {
|
||||
/// Creates a client builder with ephemeral storage.
|
||||
#[must_use]
|
||||
pub fn new_ephemeral() -> Self {
|
||||
MixnetClientBuilder {
|
||||
@@ -80,7 +80,7 @@ impl MixnetClientBuilder<OnDiskPersistent> {
|
||||
storage: storage_paths
|
||||
.initialise_default_persistent_storage()
|
||||
.await?,
|
||||
gateway_endpoint_path: Some(storage_paths.gateway_endpoint_config),
|
||||
gateway_endpoint_config_path: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ where
|
||||
S::ReplyStore: Send + Sync,
|
||||
<S::KeyStore as KeyStore>::StorageError: Send + Sync,
|
||||
{
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Creates a client builder with the provided client storage implementation.
|
||||
#[must_use]
|
||||
pub fn new_with_storage(storage: S) -> MixnetClientBuilder<S> {
|
||||
MixnetClientBuilder {
|
||||
@@ -102,12 +102,12 @@ where
|
||||
gateway_config: None,
|
||||
socks5_config: None,
|
||||
custom_topology_provider: None,
|
||||
gateway_endpoint_path: None,
|
||||
gateway_endpoint_config_path: None,
|
||||
storage,
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Change the underlying storage implementation.
|
||||
#[must_use]
|
||||
pub fn set_storage<T: MixnetClientStorage>(self, storage: T) -> MixnetClientBuilder<T> {
|
||||
MixnetClientBuilder {
|
||||
@@ -116,12 +116,12 @@ where
|
||||
gateway_config: self.gateway_config,
|
||||
socks5_config: self.socks5_config,
|
||||
custom_topology_provider: self.custom_topology_provider,
|
||||
gateway_endpoint_path: self.gateway_endpoint_path,
|
||||
gateway_endpoint_config_path: self.gateway_endpoint_config_path,
|
||||
storage,
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Change the underlying storage of this builder to use default implementation of on-disk persistence.
|
||||
#[must_use]
|
||||
pub fn set_default_storage(
|
||||
self,
|
||||
@@ -182,6 +182,12 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Use specified file for storing gateway configuration.
|
||||
pub fn gateway_endpoint_config_path<P: AsRef<Path>>(mut self, path: P) -> Self {
|
||||
self.gateway_endpoint_config_path = Some(path.as_ref().to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Construct a [`DisconnectedMixnetClient`] from the setup specified.
|
||||
pub async fn build(self) -> Result<DisconnectedMixnetClient<S>> {
|
||||
let mut client = DisconnectedMixnetClient::new(
|
||||
@@ -189,14 +195,10 @@ where
|
||||
self.socks5_config,
|
||||
self.storage,
|
||||
self.custom_topology_provider,
|
||||
self.gateway_endpoint_path,
|
||||
self.gateway_endpoint_config_path,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// if let Some(keys) = self.keys {
|
||||
// client.set_keys(keys);
|
||||
// }
|
||||
|
||||
// If we have a gateway config, we can move the client into a registered state. This will
|
||||
// fail if no gateway key is set.
|
||||
if let Some(gateway_config) = self.gateway_config {
|
||||
@@ -222,29 +224,27 @@ where
|
||||
/// Socks5 configuration
|
||||
socks5_config: Option<Socks5>,
|
||||
|
||||
// /// Paths for client keys, including identity, encryption, ack and shared gateway keys.
|
||||
// storage_paths: Option<StoragePaths>,
|
||||
/// The client can be in one of multiple states, depending on how it is created and if it's
|
||||
/// connected to the mixnet.
|
||||
state: BuilderState,
|
||||
|
||||
// TODO: refactor storages
|
||||
// TODO: refactor storages and combine everything into a single struct
|
||||
/// Controller of bandwidth credentials that the mixnet client can use to connect
|
||||
bandwidth_controller: Option<BandwidthController<Client<QueryNyxdClient>, S::CredentialStore>>,
|
||||
|
||||
/// The storage backend for reply-SURBs
|
||||
reply_storage_backend: S::ReplyStore,
|
||||
|
||||
/// The storage backend for cryptographic keys
|
||||
key_store: S::KeyStore,
|
||||
|
||||
/// Keys handled by the client
|
||||
managed_keys: ManagedKeys,
|
||||
|
||||
// TODO: change that
|
||||
gateway_endpoint_path: Option<PathBuf>,
|
||||
// TODO: incorporate it properly into `MixnetClientStorage` (I will need it in wasm anyway)
|
||||
/// Path to optionally persist gateway configuration. Note that it's required if one were to use persistent keys.
|
||||
gateway_endpoint_config_path: Option<PathBuf>,
|
||||
|
||||
// /// Underlying storage specification to be used by the client.
|
||||
// storage: S,
|
||||
/// Alternative provider of network topology used for constructing sphinx packets.
|
||||
custom_topology_provider: Option<Box<dyn TopologyProvider>>,
|
||||
}
|
||||
@@ -257,13 +257,6 @@ where
|
||||
S::ReplyStore: Send + Sync,
|
||||
<S::KeyStore as KeyStore>::StorageError: Send + Sync,
|
||||
{
|
||||
// /// Attempts to load previously generated cryptographic keys from the underlying storage.
|
||||
// /// In case of failure, new set of keys will be generated.
|
||||
// async fn initial_key_setup(key_store: &S::KeyStore) -> ManagedKeys {
|
||||
// let mut rng = thread_rng();
|
||||
// ManagedKeys::load_or_generate(&mut rng, &key_store).await
|
||||
// }
|
||||
|
||||
/// Create a new mixnet client in a disconnected state. The default configuration,
|
||||
/// creates a new mainnet client with ephemeral keys stored in RAM, which will be discarded at
|
||||
/// application close.
|
||||
@@ -276,10 +269,7 @@ where
|
||||
socks5_config: Option<Socks5>,
|
||||
storage: S,
|
||||
custom_topology_provider: Option<Box<dyn TopologyProvider>>,
|
||||
|
||||
// TODO: change that
|
||||
gateway_endpoint_path: Option<PathBuf>,
|
||||
// gateway_config: &Option<GatewayEndpointConfig>,
|
||||
gateway_endpoint_config_path: Option<PathBuf>,
|
||||
) -> Result<DisconnectedMixnetClient<S>> {
|
||||
let (key_store, reply_storage_backend, credential_store) = storage.into_split();
|
||||
|
||||
@@ -294,27 +284,19 @@ where
|
||||
None
|
||||
};
|
||||
|
||||
// // The reply storage backend is generic, and can be set by the caller/instantiator
|
||||
// let reply_storage_backend = B::new(&config.debug_config, reply_surb_database_path)
|
||||
// .await
|
||||
// .map_err(|err| Error::ReplyStorageError {
|
||||
// source: Box::new(err),
|
||||
// })?;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let managed_keys = ManagedKeys::load_or_generate(&mut rng, &key_store).await;
|
||||
|
||||
Ok(DisconnectedMixnetClient {
|
||||
config,
|
||||
socks5_config,
|
||||
// storage_paths: None,
|
||||
state: BuilderState::New,
|
||||
reply_storage_backend,
|
||||
key_store,
|
||||
bandwidth_controller,
|
||||
custom_topology_provider,
|
||||
managed_keys,
|
||||
gateway_endpoint_path,
|
||||
gateway_endpoint_config_path,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -335,22 +317,13 @@ where
|
||||
matches!(self.managed_keys, ManagedKeys::FullyDerived(..))
|
||||
}
|
||||
|
||||
// /// Sets the keys of this [`MixnetClientBuilder`].
|
||||
// fn set_keys(&mut self, keys: Keys) {
|
||||
// self.key_manager.set_identity_keypair(keys.identity_keypair);
|
||||
// self.key_manager
|
||||
// .set_encryption_keypair(keys.encryption_keypair);
|
||||
// self.key_manager.set_ack_key(keys.ack_key);
|
||||
//
|
||||
// self.key_manager
|
||||
// .insert_gateway_shared_key(Arc::new(keys.gateway_shared_key));
|
||||
// }
|
||||
//
|
||||
// /// Returns the keys of this [`DisconnectedMixnetClient<B>`]. Client keys are always available
|
||||
// /// since if none are specified at creation time, new random ones are generated.
|
||||
// pub fn get_keys(&self) -> KeysArc {
|
||||
// KeysArc::from(&self.key_manager)
|
||||
// }
|
||||
fn remove_gateway_key(&mut self) {
|
||||
assert!(self.has_gateway_key());
|
||||
let ManagedKeys::FullyDerived(keys) = std::mem::replace(&mut self.managed_keys, ManagedKeys::Invalidated) else {
|
||||
unreachable!()
|
||||
};
|
||||
self.managed_keys = ManagedKeys::Initial(keys.remove_gateway_key())
|
||||
}
|
||||
|
||||
/// Sets the gateway endpoint of this [`MixnetClientBuilder`].
|
||||
///
|
||||
@@ -474,13 +447,17 @@ where
|
||||
if matches!(self.state, BuilderState::New) {
|
||||
let already_registered = self.has_gateway_key();
|
||||
if already_registered {
|
||||
if let Some(gateway_endpoint_path) = self.gateway_endpoint_path.clone() {
|
||||
if let Some(gateway_endpoint_path) = self.gateway_endpoint_config_path.clone() {
|
||||
self.read_gateway_endpoint_config(gateway_endpoint_path)?;
|
||||
} else if !self.config.key_mode.is_keep() {
|
||||
// if we don't have gateway configuration available and we're not keeping the keys,
|
||||
// purge them
|
||||
self.remove_gateway_key();
|
||||
}
|
||||
} else {
|
||||
// TODO: that is redundant since the base client will perform gateway registration
|
||||
self.register_and_authenticate_gateway().await?;
|
||||
if let Some(gateway_endpoint_path) = &self.gateway_endpoint_path {
|
||||
if let Some(gateway_endpoint_path) = &self.gateway_endpoint_config_path {
|
||||
self.write_gateway_endpoint_config(gateway_endpoint_path)?;
|
||||
}
|
||||
}
|
||||
@@ -536,7 +513,7 @@ where
|
||||
/// async fn main() {
|
||||
/// let receiving_client = mixnet::MixnetClient::connect_new().await.unwrap();
|
||||
/// let socks5_config = mixnet::Socks5::new(receiving_client.nym_address().to_string());
|
||||
/// let client = mixnet::MixnetClientBuilder::new()
|
||||
/// let client = mixnet::MixnetClientBuilder::new_ephemeral()
|
||||
/// .socks5_config(socks5_config)
|
||||
/// .build()
|
||||
/// .await
|
||||
@@ -604,7 +581,7 @@ where
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let client = mixnet::MixnetClientBuilder::new()
|
||||
/// let client = mixnet::MixnetClientBuilder::new_ephemeral()
|
||||
/// .build()
|
||||
/// .await
|
||||
/// .unwrap();
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
use nym_client_core::config::DebugConfig;
|
||||
use nym_network_defaults::NymNetworkDetails;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub enum KeyMode {
|
||||
/// Use existing key files if they exists, otherwise create new ones.
|
||||
#[default]
|
||||
Keep,
|
||||
/// Create new keys, overwriting any potential previously existing keys.
|
||||
Overwrite,
|
||||
}
|
||||
|
||||
impl KeyMode {
|
||||
pub(crate) fn is_keep(&self) -> bool {
|
||||
matches!(self, KeyMode::Keep)
|
||||
}
|
||||
}
|
||||
|
||||
/// Config struct for [`crate::mixnet::MixnetClient`]
|
||||
#[derive(Default)]
|
||||
pub struct Config {
|
||||
/// If the user has explicitly specified a gateway.
|
||||
pub user_chosen_gateway: Option<String>,
|
||||
|
||||
/// Determines how to handle existing key files found.
|
||||
pub key_mode: KeyMode,
|
||||
|
||||
/// The details of the network we're using. It defaults to the mainnet network.
|
||||
pub network_details: NymNetworkDetails,
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use nym_client_core::client::key_manager::KeyManager;
|
||||
use nym_crypto::asymmetric::{encryption, identity};
|
||||
use nym_gateway_requests::registration::handshake::SharedKeys;
|
||||
use nym_sphinx::acknowledgements::AckKey;
|
||||
|
||||
/// The set of keys used by the client. Identity, encryption and ack keys are generated at creating
|
||||
/// unless specified to loaded from storage or somehow explictly specified. The gateway shared key
|
||||
/// is generated when registering with a gateway.
|
||||
pub struct Keys {
|
||||
/// The identity key of the client.
|
||||
pub identity_keypair: identity::KeyPair,
|
||||
/// The encryption key of the client.
|
||||
pub encryption_keypair: encryption::KeyPair,
|
||||
/// The ack key used by the client.
|
||||
pub ack_key: AckKey,
|
||||
|
||||
/// The gateway shared key that is obtained after registering with a gateway.
|
||||
pub gateway_shared_key: SharedKeys,
|
||||
}
|
||||
|
||||
/// The set of keys used by the client, but where each key is stored in an [`std::sync::Arc`] for
|
||||
/// easy cloning.
|
||||
pub struct KeysArc {
|
||||
/// The identity key of the client.
|
||||
pub identity_keypair: Arc<identity::KeyPair>,
|
||||
/// The encryption key of the client.
|
||||
pub encryption_keypair: Arc<encryption::KeyPair>,
|
||||
/// The ack key used by the client.
|
||||
pub ack_key: Arc<AckKey>,
|
||||
|
||||
/// The gateway shared key that is obtained after registering with a gateway.
|
||||
pub gateway_shared_key: Arc<SharedKeys>,
|
||||
}
|
||||
|
||||
impl From<Keys> for KeyManager {
|
||||
fn from(keys: Keys) -> Self {
|
||||
KeyManager::from_keys(
|
||||
keys.identity_keypair,
|
||||
keys.encryption_keypair,
|
||||
keys.gateway_shared_key,
|
||||
keys.ack_key,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keys> for KeysArc {
|
||||
fn from(keys: Keys) -> Self {
|
||||
KeysArc {
|
||||
identity_keypair: keys.identity_keypair.into(),
|
||||
encryption_keypair: keys.encryption_keypair.into(),
|
||||
ack_key: keys.ack_key.into(),
|
||||
gateway_shared_key: keys.gateway_shared_key.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&KeyManager> for KeysArc {
|
||||
fn from(key_manager: &KeyManager) -> Self {
|
||||
KeysArc {
|
||||
identity_keypair: key_manager.identity_keypair(),
|
||||
encryption_keypair: key_manager.encryption_keypair(),
|
||||
ack_key: key_manager.ack_key(),
|
||||
gateway_shared_key: key_manager.gateway_shared_key(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,46 +10,19 @@ use nym_client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
|
||||
use nym_credential_storage::persistent_storage::PersistentStorage as PersistentCredentialStorage;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum KeyMode {
|
||||
/// Use existing key files if they exists, otherwise create new ones.
|
||||
Keep,
|
||||
/// Create new keys, overwriting any potential previously existing keys.
|
||||
Overwrite,
|
||||
}
|
||||
|
||||
impl KeyMode {
|
||||
pub(crate) fn is_keep(&self) -> bool {
|
||||
matches!(self, KeyMode::Keep)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum GatewayKeyMode {
|
||||
/// Keep shared gateway key if found, otherwise create a new one.
|
||||
Keep,
|
||||
/// Create a new shared key and overwrite any potential existing one.
|
||||
Overwrite,
|
||||
}
|
||||
|
||||
impl GatewayKeyMode {
|
||||
pub(crate) fn is_keep(&self) -> bool {
|
||||
matches!(self, GatewayKeyMode::Keep)
|
||||
}
|
||||
}
|
||||
|
||||
/// Set of storage paths that the client will use if it is setup to persist keys, credentials, and
|
||||
/// reply-SURBs.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StoragePaths {
|
||||
// /// Determines how to handle existing key files found.
|
||||
// pub operating_mode: KeyMode,
|
||||
/// Client private identity key
|
||||
pub private_identity: PathBuf,
|
||||
|
||||
/// Client public identity key
|
||||
pub public_identity: PathBuf,
|
||||
|
||||
/// Client private encryption key
|
||||
pub private_encryption: PathBuf,
|
||||
|
||||
/// Client public encryption key
|
||||
pub public_encryption: PathBuf,
|
||||
|
||||
@@ -59,9 +32,6 @@ pub struct StoragePaths {
|
||||
/// Key setup after authenticating with a gateway
|
||||
pub gateway_shared_key: PathBuf,
|
||||
|
||||
/// The key isn't much use without knowing which entity it refers to.
|
||||
pub gateway_endpoint_config: PathBuf,
|
||||
|
||||
/// The database containing credentials
|
||||
pub credential_database_path: PathBuf,
|
||||
|
||||
@@ -76,28 +46,24 @@ impl StoragePaths {
|
||||
///
|
||||
/// This function will return an error if it is passed a path to an existing file instead of a
|
||||
/// directory.
|
||||
pub fn new_from_dir(operating_mode: KeyMode, dir: &Path) -> Result<Self> {
|
||||
pub fn new_from_dir(dir: &Path) -> Result<Self> {
|
||||
if dir.is_file() {
|
||||
return Err(Error::ExpectedDirectory(dir.to_owned()));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
// These filenames were chosen to match the ones we use in `nym-client`. Consider
|
||||
// changing the defaults
|
||||
// operating_mode,
|
||||
private_identity: dir.join("private_identity.pem"),
|
||||
public_identity: dir.join("public_identity.pem"),
|
||||
private_encryption: dir.join("private_encryption.pem"),
|
||||
public_encryption: dir.join("public_encryption.pem"),
|
||||
ack_key: dir.join("ack_key.pem"),
|
||||
gateway_shared_key: dir.join("gateway_shared.pem"),
|
||||
gateway_endpoint_config: dir.join("gateway_endpoint_config.toml"),
|
||||
credential_database_path: dir.join("db.sqlite"),
|
||||
reply_surb_database_path: dir.join("persistent_reply_store.sqlite"),
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Instantiates default full client storage backend with default configuration.
|
||||
pub async fn initialise_default_persistent_storage(
|
||||
&self,
|
||||
) -> Result<storage::OnDiskPersistent, Error> {
|
||||
@@ -108,7 +74,7 @@ impl StoragePaths {
|
||||
))
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Instantiates default full client storage backend with the provided configuration.
|
||||
pub async fn initialise_persistent_storage(
|
||||
&self,
|
||||
config: &config::DebugConfig,
|
||||
@@ -121,7 +87,7 @@ impl StoragePaths {
|
||||
))
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Instantiates default coconut credential storage.
|
||||
pub async fn persistent_credential_storage(
|
||||
&self,
|
||||
) -> Result<PersistentCredentialStorage, Error> {
|
||||
@@ -132,11 +98,12 @@ impl StoragePaths {
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Instantiates default reply surb storage backend with default configuration.
|
||||
pub async fn default_persistent_fs_reply_backend(&self) -> Result<fs_backend::Backend, Error> {
|
||||
self.persistent_fs_reply_backend(&Default::default()).await
|
||||
}
|
||||
|
||||
/// Instantiates default reply surb storage backend with the provided metadata config.
|
||||
pub async fn persistent_fs_reply_backend(
|
||||
&self,
|
||||
surb_config: &config::ReplySurbs,
|
||||
@@ -148,13 +115,12 @@ impl StoragePaths {
|
||||
.await?)
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
/// Instantiates default persistent key storage.
|
||||
pub fn on_disk_key_storage_spec(&self) -> OnDiskKeys {
|
||||
OnDiskKeys::new(self.client_key_pathfinder())
|
||||
}
|
||||
|
||||
#[deprecated(note = "add docs")]
|
||||
pub fn client_key_pathfinder(&self) -> ClientKeyPathfinder {
|
||||
fn client_key_pathfinder(&self) -> ClientKeyPathfinder {
|
||||
ClientKeyPathfinder {
|
||||
identity_private_key: self.private_identity.clone(),
|
||||
identity_public_key: self.public_identity.clone(),
|
||||
@@ -175,14 +141,12 @@ impl From<StoragePaths> for ClientKeyPathfinder {
|
||||
impl<T> From<&nym_client_core::config::Config<T>> for StoragePaths {
|
||||
fn from(value: &nym_client_core::config::Config<T>) -> Self {
|
||||
Self {
|
||||
// operating_mode: KeyMode::Keep,
|
||||
private_identity: value.get_private_identity_key_file(),
|
||||
public_identity: value.get_public_identity_key_file(),
|
||||
private_encryption: value.get_private_encryption_key_file(),
|
||||
public_encryption: value.get_public_encryption_key_file(),
|
||||
ack_key: value.get_ack_key_file(),
|
||||
gateway_shared_key: value.get_gateway_shared_key_file(),
|
||||
gateway_endpoint_config: Default::default(),
|
||||
credential_database_path: value.get_database_path(),
|
||||
reply_surb_database_path: value.get_reply_surb_database_path(),
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Socks5MixnetClient {
|
||||
///
|
||||
/// ```
|
||||
pub async fn connect_new<S: Into<String>>(provider_mix_address: S) -> Result<Self> {
|
||||
MixnetClientBuilder::new()
|
||||
MixnetClientBuilder::new_ephemeral()
|
||||
.socks5_config(Socks5::new(provider_mix_address))
|
||||
.build()
|
||||
.await?
|
||||
|
||||
Reference in New Issue
Block a user