Skip to content

Commit 009c5cd

Browse files
author
Dev Kalra
authored
[audit] Secrets appear in environment variables and command line arguments (#1201)
* accept secret as a file too * run pre-commit * address feedback
1 parent e1606a4 commit 009c5cd

File tree

7 files changed

+39
-30
lines changed

7 files changed

+39
-30
lines changed

fortuna/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
config.yaml
3+
*secret*

fortuna/Cargo.lock

Lines changed: 12 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "3.0.1"
3+
version = "3.0.2"
44
edition = "2021"
55

66
[dependencies]

fortuna/src/command/register_provider.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> {
3131

3232
// Create a new random hash chain.
3333
let random = rand::random::<[u8; 32]>();
34+
let secret = match opts.randomness.load_secret() {
35+
Ok(loaded_secret) => loaded_secret,
36+
Err(_err) => opts.randomness.secret_file.clone(),
37+
};
38+
3439
let commitment_length = opts.randomness.chain_length;
35-
let mut chain = PebbleHashChain::from_config(
36-
&opts.randomness.secret,
37-
&opts.chain_id,
38-
&random,
39-
commitment_length,
40-
)?;
40+
let mut chain =
41+
PebbleHashChain::from_config(&secret, &opts.chain_id, &random, commitment_length)?;
4142

4243
// Arguments to the contract to register our new provider.
4344
let fee_in_wei = opts.fee;

fortuna/src/command/run.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
4747
struct ApiDoc;
4848

4949
let config = Config::load(&opts.config.config)?;
50+
let secret: String;
51+
match opts.randomness.load_secret() {
52+
Ok(loaded_secret) => secret = loaded_secret,
53+
Err(_err) => secret = opts.randomness.secret_file.clone(),
54+
}
55+
5056

5157
let mut chains = HashMap::new();
5258
for (chain_id, chain_config) in &config.chains {
@@ -64,7 +70,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
6470
bincode::deserialize::<CommitmentMetadata>(&provider_info.commitment_metadata)?;
6571

6672
let hash_chain = PebbleHashChain::from_config(
67-
&opts.randomness.secret,
73+
&secret,
6874
&chain_id,
6975
&metadata.seed,
7076
metadata.chain_length,

fortuna/src/config.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ pub struct ConfigOptions {
7676
#[command(next_help_heading = "Randomness Options")]
7777
#[group(id = "Randomness")]
7878
pub struct RandomnessOptions {
79-
/// A secret used for generating new hash chains. A 64-char hex string.
79+
/// Path to file containing a secret which is a 64-char hex string.
80+
/// The secret is used for generating new hash chains
81+
/// Or the secret itself. TODO: this will be removed in another PR.
8082
#[arg(long = "secret")]
8183
#[arg(env = "FORTUNA_SECRET")]
82-
pub secret: String,
84+
pub secret_file: String,
8385

8486
/// The length of the hash chain to generate.
8587
#[arg(long = "chain-length")]
@@ -88,6 +90,12 @@ pub struct RandomnessOptions {
8890
pub chain_length: u64,
8991
}
9092

93+
impl RandomnessOptions {
94+
pub fn load_secret(&self) -> Result<String> {
95+
return Ok((fs::read_to_string(&self.secret_file))?);
96+
}
97+
}
98+
9199
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
92100
pub struct Config {
93101
pub chains: HashMap<ChainId, EthereumConfig>,

hermes/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)