From 3098eb8544014a560f92277aaef989d238c2382f Mon Sep 17 00:00:00 2001 From: Simon Wicky Date: Fri, 1 Dec 2023 14:49:33 +0100 Subject: [PATCH] add config migration for clients --- .../src/client/config/old_config_v1_1_20.rs | 9 ++-- .../socks5/src/config/old_config_v1_1_20.rs | 9 ++-- .../config/disk_persistence/old_v1_1_20_2.rs | 51 +++++++++++++++++-- .../src/config/old_config_v1_1_20.rs | 9 ++-- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/clients/native/src/client/config/old_config_v1_1_20.rs b/clients/native/src/client/config/old_config_v1_1_20.rs index 7e2b5d1dc0..05368a7853 100644 --- a/clients/native/src/client/config/old_config_v1_1_20.rs +++ b/clients/native/src/client/config/old_config_v1_1_20.rs @@ -5,8 +5,9 @@ use crate::client::config::old_config_v1_1_20_2::{ ClientPathsV1_1_20_2, ConfigV1_1_20_2, SocketTypeV1_1_20_2, SocketV1_1_20_2, }; use nym_bin_common::logging::LoggingSettings; -use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths; -use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2; +use nym_client_core::config::disk_persistence::old_v1_1_20_2::{ + ClientKeysPathsV1_1_20_2, CommonClientPathsV1_1_20_2, +}; use nym_client_core::config::old_config_v1_1_20::ConfigV1_1_20 as BaseConfigV1_1_20; use nym_client_core::config::old_config_v1_1_20_2::{ ClientV1_1_20_2, ConfigV1_1_20_2 as BaseConfigV1_1_20_2, @@ -60,13 +61,11 @@ impl From for ConfigV1_1_20_2 { socket: value.socket.into(), storage_paths: ClientPathsV1_1_20_2 { common_paths: CommonClientPathsV1_1_20_2 { - keys: ClientKeysPaths { + keys: ClientKeysPathsV1_1_20_2 { private_identity_key_file: value.base.client.private_identity_key_file, public_identity_key_file: value.base.client.public_identity_key_file, private_encryption_key_file: value.base.client.private_encryption_key_file, public_encryption_key_file: value.base.client.public_encryption_key_file, - private_ecash_key_file: PathBuf::new(), - public_ecash_key_file: PathBuf::new(), gateway_shared_key_file: value.base.client.gateway_shared_key_file, ack_key_file: value.base.client.ack_key_file, }, diff --git a/clients/socks5/src/config/old_config_v1_1_20.rs b/clients/socks5/src/config/old_config_v1_1_20.rs index fb732e11d7..3628ac2bbf 100644 --- a/clients/socks5/src/config/old_config_v1_1_20.rs +++ b/clients/socks5/src/config/old_config_v1_1_20.rs @@ -5,8 +5,9 @@ use crate::config::old_config_v1_1_20_2::{ ConfigV1_1_20_2, CoreConfigV1_1_20_2, SocksClientPathsV1_1_20_2, }; use nym_bin_common::logging::LoggingSettings; -use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths; -use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2; +use nym_client_core::config::disk_persistence::old_v1_1_20_2::{ + ClientKeysPathsV1_1_20_2, CommonClientPathsV1_1_20_2, +}; use nym_client_core::config::old_config_v1_1_20::ConfigV1_1_20 as BaseConfigV1_1_20; use nym_client_core::config::old_config_v1_1_20_2::ClientV1_1_20_2; use nym_config::legacy_helpers::nym_config::MigrationNymConfig; @@ -50,13 +51,11 @@ impl From for ConfigV1_1_20_2 { }, storage_paths: SocksClientPathsV1_1_20_2 { common_paths: CommonClientPathsV1_1_20_2 { - keys: ClientKeysPaths { + keys: ClientKeysPathsV1_1_20_2 { private_identity_key_file: value.base.client.private_identity_key_file, public_identity_key_file: value.base.client.public_identity_key_file, private_encryption_key_file: value.base.client.private_encryption_key_file, public_encryption_key_file: value.base.client.public_encryption_key_file, - private_ecash_key_file: PathBuf::new(), - public_ecash_key_file: PathBuf::new(), gateway_shared_key_file: value.base.client.gateway_shared_key_file, ack_key_file: value.base.client.ack_key_file, }, diff --git a/common/client-core/src/config/disk_persistence/old_v1_1_20_2.rs b/common/client-core/src/config/disk_persistence/old_v1_1_20_2.rs index d26cf1461c..8224740e74 100644 --- a/common/client-core/src/config/disk_persistence/old_v1_1_20_2.rs +++ b/common/client-core/src/config/disk_persistence/old_v1_1_20_2.rs @@ -1,7 +1,9 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use crate::config::disk_persistence::keys_paths::ClientKeysPaths; +use crate::config::disk_persistence::keys_paths::{ + ClientKeysPaths, DEFAULT_PRIVATE_ECASH_KEY_FILENAME, DEFAULT_PUBLIC_ECASH_KEY_FILENAME, +}; use crate::config::disk_persistence::{CommonClientPaths, DEFAULT_GATEWAY_DETAILS_FILENAME}; use crate::error::ClientCoreError; use serde::{Deserialize, Serialize}; @@ -10,7 +12,7 @@ use std::path::PathBuf; #[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] #[serde(deny_unknown_fields)] pub struct CommonClientPathsV1_1_20_2 { - pub keys: ClientKeysPaths, + pub keys: ClientKeysPathsV1_1_20_2, pub credentials_database: PathBuf, pub reply_surb_database: PathBuf, } @@ -23,10 +25,53 @@ impl CommonClientPathsV1_1_20_2 { } })?; Ok(CommonClientPaths { - keys: self.keys, + keys: self.keys.upgrade_default()?, gateway_details: data_dir.join(DEFAULT_GATEWAY_DETAILS_FILENAME), credentials_database: self.credentials_database, reply_surb_database: self.reply_surb_database, }) } } +#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct ClientKeysPathsV1_1_20_2 { + /// Path to file containing private identity key. + pub private_identity_key_file: PathBuf, + + /// Path to file containing public identity key. + pub public_identity_key_file: PathBuf, + + /// Path to file containing private encryption key. + pub private_encryption_key_file: PathBuf, + + /// Path to file containing public encryption key. + pub public_encryption_key_file: PathBuf, + + /// Path to file containing shared key derived with the specified gateway that is used + /// for all communication with it. + pub gateway_shared_key_file: PathBuf, + + /// Path to file containing key used for encrypting and decrypting the content of an + /// acknowledgement so that nobody besides the client knows which packet it refers to. + pub ack_key_file: PathBuf, +} + +impl ClientKeysPathsV1_1_20_2 { + pub fn upgrade_default(self) -> Result { + let data_dir = self.gateway_shared_key_file.parent().ok_or_else(|| { + ClientCoreError::UnableToUpgradeConfigFile { + new_version: "1.1.20-2".to_string(), + } + })?; + Ok(ClientKeysPaths { + private_identity_key_file: self.private_identity_key_file, + public_identity_key_file: self.public_identity_key_file, + private_encryption_key_file: self.private_encryption_key_file, + public_encryption_key_file: self.public_encryption_key_file, + private_ecash_key_file: data_dir.join(DEFAULT_PRIVATE_ECASH_KEY_FILENAME), + public_ecash_key_file: data_dir.join(DEFAULT_PUBLIC_ECASH_KEY_FILENAME), + gateway_shared_key_file: self.gateway_shared_key_file, + ack_key_file: self.ack_key_file, + }) + } +} diff --git a/service-providers/network-requester/src/config/old_config_v1_1_20.rs b/service-providers/network-requester/src/config/old_config_v1_1_20.rs index 4c07cbfe64..38c295fef9 100644 --- a/service-providers/network-requester/src/config/old_config_v1_1_20.rs +++ b/service-providers/network-requester/src/config/old_config_v1_1_20.rs @@ -4,8 +4,9 @@ use crate::config::old_config_v1_1_20_2::{ ConfigV1_1_20_2, DebugV1_1_20_2, NetworkRequesterPathsV1_1_20_2, }; -use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths; -use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2; +use nym_client_core::config::disk_persistence::old_v1_1_20_2::{ + ClientKeysPathsV1_1_20_2, CommonClientPathsV1_1_20_2, +}; use nym_client_core::config::old_config_v1_1_20::ConfigV1_1_20 as BaseConfigV1_1_20; use nym_client_core::config::old_config_v1_1_20_2::{ ClientV1_1_20_2, ConfigV1_1_20_2 as BaseClientConfigV1_1_20_2, @@ -47,13 +48,11 @@ impl From for ConfigV1_1_20_2 { network_requester: Default::default(), storage_paths: NetworkRequesterPathsV1_1_20_2 { common_paths: CommonClientPathsV1_1_20_2 { - keys: ClientKeysPaths { + keys: ClientKeysPathsV1_1_20_2 { private_identity_key_file: value.base.client.private_identity_key_file, public_identity_key_file: value.base.client.public_identity_key_file, private_encryption_key_file: value.base.client.private_encryption_key_file, public_encryption_key_file: value.base.client.public_encryption_key_file, - private_ecash_key_file: PathBuf::new(), - public_ecash_key_file: PathBuf::new(), gateway_shared_key_file: value.base.client.gateway_shared_key_file, ack_key_file: value.base.client.ack_key_file, },