lanzaboote/rust/lanzatool/src/cli.rs

77 lines
1.6 KiB
Rust
Raw Normal View History

2022-11-26 08:55:15 -05:00
use std::path::PathBuf;
2022-11-21 19:29:16 -05:00
2022-11-25 17:48:20 -05:00
use anyhow::{Context, Result};
2022-11-21 19:29:16 -05:00
use clap::{Parser, Subcommand};
2022-11-23 09:30:24 -05:00
use crate::install;
2022-11-26 17:19:08 -05:00
use crate::signature::KeyPair;
2022-11-21 19:29:16 -05:00
#[derive(Parser)]
pub struct Cli {
#[clap(subcommand)]
2022-11-26 08:55:15 -05:00
commands: Commands,
2022-11-21 19:29:16 -05:00
}
#[derive(Subcommand)]
2022-11-26 08:55:15 -05:00
enum Commands {
Install(InstallCommand),
}
#[derive(Parser)]
struct InstallCommand {
// Secure Boot Public Key
#[arg(long)]
public_key: PathBuf,
2022-11-24 08:12:00 -05:00
2022-11-26 08:55:15 -05:00
// Secure Boot Private Key
#[arg(long)]
private_key: PathBuf,
2022-11-24 08:12:00 -05:00
2022-11-26 08:55:15 -05:00
// Secure Boot PKI Bundle for auto enrolling key
#[arg(long)]
pki_bundle: Option<PathBuf>,
2022-11-24 08:12:00 -05:00
2022-11-26 08:55:15 -05:00
// Enable auto enrolling your keys in UEFI
// Be aware that this might irrevocably brick your device
#[arg(long, default_value = "false")]
auto_enroll: bool,
2022-11-24 08:12:00 -05:00
esp: PathBuf,
2022-11-26 08:55:15 -05:00
generations: Vec<PathBuf>,
2022-11-21 19:29:16 -05:00
}
impl Cli {
pub fn call(self) -> Result<()> {
self.commands.call()
}
}
impl Commands {
pub fn call(self) -> Result<()> {
match self {
2022-11-26 08:55:15 -05:00
Commands::Install(args) => install(args),
2022-11-21 19:29:16 -05:00
}
}
}
2022-11-26 08:55:15 -05:00
fn install(args: InstallCommand) -> Result<()> {
2022-11-25 17:48:20 -05:00
let lanzaboote_stub =
std::env::var("LANZABOOTE_STUB").context("Failed to read LANZABOOTE_STUB env variable")?;
let initrd_stub = std::env::var("LANZABOOTE_INITRD_STUB")
.context("Failed to read LANZABOOTE_INITRD_STUB env variable")?;
2022-11-24 08:12:00 -05:00
2022-11-26 17:19:08 -05:00
let key_pair = KeyPair::new(&args.public_key, &args.private_key);
2022-11-26 08:55:15 -05:00
install::Installer::new(
PathBuf::from(lanzaboote_stub),
PathBuf::from(initrd_stub),
2022-11-26 17:19:08 -05:00
key_pair,
2022-11-26 08:55:15 -05:00
args.pki_bundle,
args.auto_enroll,
args.esp,
2022-11-26 08:55:15 -05:00
args.generations,
2022-11-23 14:40:01 -05:00
)
2022-11-26 08:55:15 -05:00
.install()
2022-11-23 09:26:26 -05:00
}