Skip to content

Commit

Permalink
Add zeroize
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Nov 12, 2024
1 parent a9f9fbb commit 6ea7f82
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions nym-vpn-core/Cargo.lock

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

1 change: 1 addition & 0 deletions nym-vpn-core/crates/nym-vpnd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tracing-appender.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing.workspace = true
url.workspace = true
zeroize.workspace = true

# Nym monorepo
nym-bandwidth-controller.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use nym_vpn_api_client::{
types::GatewayMinPerformance,
};
use nym_vpn_lib::gateway_directory::{EntryPoint, ExitPoint, GatewayClient, GatewayType};
use zeroize::Zeroizing;

use crate::{
service::{
Expand Down Expand Up @@ -134,7 +135,7 @@ impl CommandInterfaceConnectionHandler {

pub(crate) async fn handle_store_account(
&self,
account: String,
account: Zeroizing<String>,
) -> Result<Result<(), AccountError>, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::StoreAccount, account)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use nym_vpn_proto::{
ResetDeviceIdentityResponse, SetNetworkRequest, SetNetworkResponse, StatusRequest,
StatusResponse, StoreAccountRequest, StoreAccountResponse,
};
use zeroize::Zeroizing;

use super::{
connection_handler::CommandInterfaceConnectionHandler,
Expand Down Expand Up @@ -423,7 +424,7 @@ impl NymVpnd for CommandInterface {
&self,
request: tonic::Request<StoreAccountRequest>,
) -> Result<tonic::Response<StoreAccountResponse>, tonic::Status> {
let account = request.into_inner().mnemonic;
let account = Zeroizing::new(request.into_inner().mnemonic);

let result = CommandInterfaceConnectionHandler::new(self.vpn_command_tx.clone())
.handle_store_account(account)
Expand Down
10 changes: 7 additions & 3 deletions nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use nym_vpn_lib::{
},
MixnetClientConfig, NodeIdentity, Recipient,
};
use zeroize::Zeroizing;

use crate::config::GlobalConfigFile;

Expand Down Expand Up @@ -105,7 +106,7 @@ pub enum VpnServiceCommand {
),
Disconnect(oneshot::Sender<Result<(), VpnServiceDisconnectError>>, ()),
Status(oneshot::Sender<VpnServiceStatus>, ()),
StoreAccount(oneshot::Sender<Result<(), AccountError>>, String),
StoreAccount(oneshot::Sender<Result<(), AccountError>>, Zeroizing<String>),
IsAccountStored(oneshot::Sender<Result<bool, AccountError>>, ()),
RemoveAccount(oneshot::Sender<Result<(), AccountError>>, ()),
GetAccountIdentity(oneshot::Sender<Result<String, AccountError>>, ()),
Expand Down Expand Up @@ -890,11 +891,14 @@ where
self.network_env.feature_flags.clone()
}

async fn handle_store_account(&mut self, account: String) -> Result<(), AccountError> {
async fn handle_store_account(
&mut self,
account: Zeroizing<String>,
) -> Result<(), AccountError> {
self.storage
.lock()
.await
.store_mnemonic(Mnemonic::parse(&account)?)
.store_mnemonic(Mnemonic::parse::<&str>(account.as_ref())?)
.await
.map_err(|err| AccountError::FailedToStoreAccount {
source: Box::new(err),
Expand Down

0 comments on commit 6ea7f82

Please sign in to comment.