Skip to content

Commit f1937ff

Browse files
committed
Treat content of encryption_file as hex-encoded
Signed-off-by: Kai A. Hiller <[email protected]>
1 parent fbee4bf commit f1937ff

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Cargo.lock

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

crates/config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ anyhow.workspace = true
1919
camino = { workspace = true, features = ["serde1"] }
2020
chrono.workspace = true
2121
figment.workspace = true
22+
hex.workspace = true
2223
ipnetwork = { version = "0.20.0", features = ["serde", "schemars"] }
2324
lettre.workspace = true
2425
schemars.workspace = true

crates/config/src/sections/secrets.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use std::borrow::Cow;
88

9-
use anyhow::{Context, anyhow, bail};
9+
use anyhow::{Context, bail};
1010
use camino::Utf8PathBuf;
1111
use mas_jose::jwk::{JsonWebKey, JsonWebKeySet};
1212
use mas_keystore::{Encrypter, Keystore, PrivateKey};
@@ -185,9 +185,15 @@ impl SecretsConfig {
185185
// Read the encryption secret either embedded in the config file or on disk
186186
match self.encryption {
187187
Encryption::Value(encryption) => Ok(encryption),
188-
Encryption::File(ref path) => tokio::fs::read(path).await?.try_into().map_err(|_| {
189-
anyhow!("Content of `encryption_file` must be exactly 32 bytes long.")
190-
}),
188+
Encryption::File(ref path) => {
189+
let mut bytes = [0; 32];
190+
let content = tokio::fs::read(path).await?;
191+
hex::decode_to_slice(content, &mut bytes).context(
192+
"Content of `encryption_file` must contain hex characters \
193+
encoding exactly 32 bytes",
194+
)?;
195+
Ok(bytes)
196+
}
191197
}
192198
}
193199
}

0 commit comments

Comments
 (0)