From c4734d11fc970e05f9c75d14a452037322adcd24 Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 23 Nov 2022 15:30:24 +0100 Subject: [PATCH] lanzatool.crypto: remove --- rust/lanzatool/Cargo.lock | 36 +----------------------- rust/lanzatool/Cargo.toml | 3 +- rust/lanzatool/src/cli.rs | 52 +---------------------------------- rust/lanzatool/src/crypto.rs | 22 --------------- rust/lanzatool/src/esp.rs | 2 +- rust/lanzatool/src/install.rs | 2 +- rust/lanzatool/src/main.rs | 1 - 7 files changed, 5 insertions(+), 113 deletions(-) delete mode 100644 rust/lanzatool/src/crypto.rs diff --git a/rust/lanzatool/Cargo.lock b/rust/lanzatool/Cargo.lock index 7c9205e..264395c 100644 --- a/rust/lanzatool/Cargo.lock +++ b/rust/lanzatool/Cargo.lock @@ -68,33 +68,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "ct-codecs" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3b7eb4404b8195a9abb6356f4ac07d8ba267045c8d6d220ac4dc992e6cc75df" - -[[package]] -name = "ed25519-compact" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f2d21333b679bbbac680b3eb45c86937e42f69277028f4e97b599b80b86c253" -dependencies = [ - "ct-codecs", - "getrandom", -] - -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "goblin" version = "0.6.0" @@ -128,12 +101,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] -name = "lanztool" +name = "lanzatool" version = "0.1.0" dependencies = [ "anyhow", "clap", - "ed25519-compact", "goblin", "serde", "serde_json", @@ -309,12 +281,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.3.9" diff --git a/rust/lanzatool/Cargo.toml b/rust/lanzatool/Cargo.toml index 0f2e7cb..7d7fa71 100644 --- a/rust/lanzatool/Cargo.toml +++ b/rust/lanzatool/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lanztool" +name = "lanzatool" version = "0.1.0" edition = "2021" @@ -8,7 +8,6 @@ edition = "2021" [dependencies] anyhow = "1.0.66" clap = { version = "4.0.26", features = ["derive"] } -ed25519-compact = "2.0.2" goblin = "0.6.0" serde = { version = "1.0.147", features = ["derive"] } serde_json = "1.0.89" diff --git a/rust/lanzatool/src/cli.rs b/rust/lanzatool/src/cli.rs index f643861..2338ea9 100644 --- a/rust/lanzatool/src/cli.rs +++ b/rust/lanzatool/src/cli.rs @@ -1,10 +1,9 @@ -use std::fs; use std::path::{Path, PathBuf}; use anyhow::Result; use clap::{Parser, Subcommand}; -use crate::{crypto, install}; +use crate::install; #[derive(Parser)] pub struct Cli { @@ -14,12 +13,6 @@ pub struct Cli { #[derive(Subcommand)] pub enum Commands { - /// Generate key pair - Generate, - /// Sign - Sign { file: PathBuf, private_key: PathBuf }, - /// Sign - Verify { file: PathBuf, public_key: PathBuf }, Install { public_key: PathBuf, bootspec: PathBuf, @@ -35,9 +28,6 @@ impl Cli { impl Commands { pub fn call(self) -> Result<()> { match self { - Commands::Generate => generate(), - Commands::Sign { file, private_key } => sign(&file, &private_key), - Commands::Verify { file, public_key } => verify(&file, &public_key), Commands::Install { public_key, bootspec, @@ -46,46 +36,6 @@ impl Commands { } } -fn generate() -> Result<()> { - let key_pair = crypto::generate_key(); - - fs::write("public_key.pem", key_pair.pk.to_pem())?; - fs::write("private_key.pem", key_pair.sk.to_pem())?; - - Ok(()) -} - -fn sign(file: &Path, private_key: &Path) -> Result<()> { - let message = fs::read(file)?; - let private_key = fs::read_to_string(private_key)?; - - let signature = crypto::sign(&message, &private_key)?; - - let file_path = with_extension(file, ".sig"); - fs::write(file_path, signature.as_slice())?; - - Ok(()) -} - -fn verify(file: &Path, public_key: &Path) -> Result<()> { - let message = fs::read(file)?; - - let signature_path = with_extension(file, ".sig"); - let signature = fs::read(signature_path)?; - - let public_key = fs::read_to_string(public_key)?; - - crypto::verify(&message, &signature, &public_key)?; - - Ok(()) -} - -fn with_extension(path: &Path, extension: &str) -> PathBuf { - let mut file_path = path.to_path_buf().into_os_string(); - file_path.push(extension); - PathBuf::from(file_path) -} - fn install(public_key: &Path, bootspec: &Path) -> Result<()> { let lanzaboote_bin = std::env::var("LANZABOOTE")?; install::install(public_key, bootspec, Path::new(&lanzaboote_bin)) diff --git a/rust/lanzatool/src/crypto.rs b/rust/lanzatool/src/crypto.rs deleted file mode 100644 index 6433c1f..0000000 --- a/rust/lanzatool/src/crypto.rs +++ /dev/null @@ -1,22 +0,0 @@ -use anyhow::Result; -use ed25519_compact::{KeyPair, Noise, PublicKey, SecretKey, Seed, Signature}; - -pub fn generate_key() -> KeyPair { - KeyPair::from_seed(Seed::default()) -} - -pub fn sign(message: &[u8], private_key: &str) -> Result { - let private_key = SecretKey::from_pem(private_key)?; - let signature = private_key.sign(message, Some(Noise::generate())); - - Ok(signature) -} - -pub fn verify(message: &[u8], signature: &[u8], public_key: &str) -> Result<()> { - let signature = Signature::from_slice(signature)?; - let public_key = PublicKey::from_pem(public_key)?; - - public_key.verify(message, &signature)?; - - Ok(()) -} diff --git a/rust/lanzatool/src/esp.rs b/rust/lanzatool/src/esp.rs index ba4f8b9..3112225 100644 --- a/rust/lanzatool/src/esp.rs +++ b/rust/lanzatool/src/esp.rs @@ -15,7 +15,7 @@ impl EspPaths { Self { esp: esp.to_owned(), nixos: esp_nixos.clone(), - kernel: esp_nixos.join("EFI/nixos"), + kernel: esp_nixos.join("kernel"), initrd: esp_nixos.join("initrd"), } } diff --git a/rust/lanzatool/src/install.rs b/rust/lanzatool/src/install.rs index 33a91a4..9f55cb6 100644 --- a/rust/lanzatool/src/install.rs +++ b/rust/lanzatool/src/install.rs @@ -32,7 +32,7 @@ pub fn install(_: &Path, bootspec: &Path, lanzaboote_bin: &Path) -> Result<()> { Ok(()) } -fn install_systemd_boot(bootctl: &Path, esp: &Path) -> Result<()> { +fn _install_systemd_boot(bootctl: &Path, esp: &Path) -> Result<()> { let args = vec![ String::from("install"), String::from("--path"), diff --git a/rust/lanzatool/src/main.rs b/rust/lanzatool/src/main.rs index cc00d27..e600556 100644 --- a/rust/lanzatool/src/main.rs +++ b/rust/lanzatool/src/main.rs @@ -1,6 +1,5 @@ mod bootspec; mod cli; -mod crypto; mod esp; mod install; mod stub;