Skip to content

Commit 7c7888d

Browse files
authored
Fix loading of DER-encoded key files (#4702)
2 parents 5b11d15 + 81a61e3 commit 7c7888d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/config/src/sections/secrets.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ impl KeyConfig {
149149
/// Returns the password in case any is provided.
150150
///
151151
/// If `password_file` was given, the password is read from that file.
152-
async fn password(&self) -> anyhow::Result<Option<Cow<String>>> {
152+
async fn password(&self) -> anyhow::Result<Option<Cow<[u8]>>> {
153153
Ok(match &self.password {
154-
Some(Password::File(path)) => Some(Cow::Owned(tokio::fs::read_to_string(path).await?)),
155-
Some(Password::Value(password)) => Some(Cow::Borrowed(password)),
154+
Some(Password::File(path)) => Some(Cow::Owned(tokio::fs::read(path).await?)),
155+
Some(Password::Value(password)) => Some(Cow::Borrowed(password.as_bytes())),
156156
None => None,
157157
})
158158
}
159159

160160
/// Returns the key.
161161
///
162162
/// If `key_file` was given, the key is read from that file.
163-
async fn key(&self) -> anyhow::Result<Cow<String>> {
163+
async fn key(&self) -> anyhow::Result<Cow<[u8]>> {
164164
Ok(match &self.key {
165-
Key::File(path) => Cow::Owned(tokio::fs::read_to_string(path).await?),
166-
Key::Value(key) => Cow::Borrowed(key),
165+
Key::File(path) => Cow::Owned(tokio::fs::read(path).await?),
166+
Key::Value(key) => Cow::Borrowed(key.as_bytes()),
167167
})
168168
}
169169

@@ -174,8 +174,8 @@ impl KeyConfig {
174174
let (key, password) = try_join(self.key(), self.password()).await?;
175175

176176
let private_key = match password {
177-
Some(password) => PrivateKey::load_encrypted(key.as_bytes(), password.as_bytes())?,
178-
None => PrivateKey::load(key.as_bytes())?,
177+
Some(password) => PrivateKey::load_encrypted(&key, password)?,
178+
None => PrivateKey::load(&key)?,
179179
};
180180

181181
Ok(JsonWebKey::new(private_key)

0 commit comments

Comments
 (0)