Skip to content

Commit

Permalink
Add command line argument for signature verification key
Browse files Browse the repository at this point in the history
  • Loading branch information
s-westphal committed Dec 18, 2024
1 parent 1b24df4 commit 67a701d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/rrg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ features = [
"Win32_Foundation",
"Win32_Storage_FileSystem",
]

[dependencies.ed25519-dalek]
version = "2.1.1"
features = [
"rand_core",
]

[dependencies.hex]
version = "0.4.3"
15 changes: 15 additions & 0 deletions crates/rrg/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ pub struct Args {
arg_name="PATH",
description="whether to log to a file")]
pub log_to_file: Option<std::path::PathBuf>,

/// The public key for verfying signed commands.
#[argh(option,
long="command-verification-key",
arg_name="KEY",
description="verification key for signed commands",
from_str_fn(parse_verfication_key))]
pub command_verification_key: Option<ed25519_dalek::VerifyingKey>,
}

/// Parses command-line arguments.
Expand All @@ -66,3 +74,10 @@ pub fn from_env_args() -> Args {
fn parse_duration(value: &str) -> Result<Duration, String> {
humantime::parse_duration(value).map_err(|error| error.to_string())
}

/// Parses a ed25519 verification key from hex data given as string to a `VerifyingKey` object.
fn parse_verfication_key(key: &str) -> Result<ed25519_dalek::VerifyingKey, String> {
let bytes = hex::decode(key).map_err(|error| error.to_string())?;
ed25519_dalek::VerifyingKey::try_from(&bytes[..])
.map_err(|error| error.to_string())
}
1 change: 1 addition & 0 deletions crates/rrg/src/session/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl FakeSession {
pub fn new() -> FakeSession {
FakeSession::with_args(crate::args::Args {
heartbeat_rate: std::time::Duration::from_secs(0),
command_verification_key: Some(ed25519_dalek::SigningKey::generate(&mut rand::rngs::OsRng).verifying_key()),
verbosity: log::LevelFilter::Debug,
log_to_stdout: false,
log_to_file: None,
Expand Down

0 comments on commit 67a701d

Please sign in to comment.