Skip to content

Commit 0001737

Browse files
authored
Add path validation for cert and key (#181)
1 parent a73357a commit 0001737

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

server/src/option.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,21 @@ where
168168
S: Clone + clap::Args + StorageOpt,
169169
{
170170
/// The location of TLS Cert file
171-
#[arg(long, env = "P_TLS_CERT_PATH", value_name = "path")]
171+
#[arg(
172+
long,
173+
env = "P_TLS_CERT_PATH",
174+
value_name = "path",
175+
value_parser = validation::file_path
176+
)]
172177
pub tls_cert_path: Option<PathBuf>,
173178

174179
/// The location of TLS Private Key file
175-
#[arg(long, env = "P_TLS_KEY_PATH", value_name = "path")]
180+
#[arg(
181+
long,
182+
env = "P_TLS_KEY_PATH",
183+
value_name = "path",
184+
value_parser = validation::file_path
185+
)]
176186
pub tls_key_path: Option<PathBuf>,
177187

178188
/// The address on which the http server will listen.
@@ -251,3 +261,21 @@ where
251261
"http".to_string()
252262
}
253263
}
264+
265+
pub(self) mod validation {
266+
use std::path::PathBuf;
267+
268+
pub fn file_path(s: &str) -> Result<PathBuf, String> {
269+
if s.is_empty() {
270+
return Err("empty path".to_owned());
271+
}
272+
273+
let path = PathBuf::from(s);
274+
275+
if !path.is_file() {
276+
return Err("path specified does not point to an accessible file".to_string());
277+
}
278+
279+
Ok(path)
280+
}
281+
}

0 commit comments

Comments
 (0)