Skip to content

Commit b3682a9

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

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
use std::borrow::Cow;
88

9-
use anyhow::{Context, anyhow, bail};
9+
use anyhow::{Context, bail};
1010
use camino::Utf8PathBuf;
11+
use hex;
1112
use mas_jose::jwk::{JsonWebKey, JsonWebKeySet};
1213
use mas_keystore::{Encrypter, Keystore, PrivateKey};
1314
use rand::{
@@ -185,9 +186,15 @@ impl SecretsConfig {
185186
// Read the encryption secret either embedded in the config file or on disk
186187
match self.encryption {
187188
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-
}),
189+
Encryption::File(ref path) => {
190+
let mut bytes = [0; 32];
191+
let content = tokio::fs::read(path).await?;
192+
hex::decode_to_slice(content, &mut bytes).context(
193+
"Content of `encryption_file` must contain hex characters \
194+
encoding exactly 32 bytes",
195+
)?;
196+
Ok(bytes)
197+
}
191198
}
192199
}
193200
}

0 commit comments

Comments
 (0)