Skip to content

Commit

Permalink
Staking keys encryption with dummy pwd for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitu33 committed Jun 22, 2022
1 parent 3a50672 commit 7e1d109
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions massa-consensus-worker/src/consensus_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ impl ConsensusWorker {
}
self.pos
.set_watched_addresses(self.staking_keys.keys().copied().collect());
self.dump_staking_keys().await;
self.dump_staking_keys().await?;
Ok(())
}
ConsensusCommand::RemoveStakingAddresses(addresses) => {
Expand All @@ -882,7 +882,7 @@ impl ConsensusWorker {
}
self.pos
.set_watched_addresses(self.staking_keys.keys().copied().collect());
self.dump_staking_keys().await;
self.dump_staking_keys().await?;
Ok(())
}
ConsensusCommand::GetStakingAddresses(response_tx) => {
Expand Down Expand Up @@ -949,24 +949,18 @@ impl ConsensusWorker {
}

/// Save the staking keys to a file
async fn dump_staking_keys(&self) {
async fn dump_staking_keys(&self) -> Result<()> {
let keys = self
.staking_keys
.iter()
.map(|(_, (_, key))| *key)
.collect::<Vec<_>>();
let json = match serde_json::to_string_pretty(&keys) {
Ok(json) => json,
Err(e) => {
warn!("Error while serializing staking keys {}", e);
return;
}
};
let json = serde_json::to_string_pretty(&keys)?;

// HERE ENCRYPT
if let Err(e) = tokio::fs::write(self.cfg.staking_keys_path.clone(), json).await {
warn!("Error while dumping staking keys {}", e);
}
let encrypted_data = encrypt("PASSWORD", json.as_bytes())?;
tokio::fs::write(self.cfg.staking_keys_path.clone(), encrypted_data).await?;
Ok(())
}

/// retrieve stats
Expand Down

0 comments on commit 7e1d109

Please sign in to comment.