lanzatool.crypto: remove
This commit is contained in:
parent
4356d342a2
commit
c4734d11fc
|
@ -68,33 +68,6 @@ dependencies = [
|
||||||
"os_str_bytes",
|
"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]]
|
[[package]]
|
||||||
name = "goblin"
|
name = "goblin"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
|
@ -128,12 +101,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
|
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lanztool"
|
name = "lanzatool"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"ed25519-compact",
|
|
||||||
"goblin",
|
"goblin",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -309,12 +281,6 @@ version = "0.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
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]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lanztool"
|
name = "lanzatool"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.66"
|
anyhow = "1.0.66"
|
||||||
clap = { version = "4.0.26", features = ["derive"] }
|
clap = { version = "4.0.26", features = ["derive"] }
|
||||||
ed25519-compact = "2.0.2"
|
|
||||||
goblin = "0.6.0"
|
goblin = "0.6.0"
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.89"
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use std::fs;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
use crate::{crypto, install};
|
use crate::install;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
|
@ -14,12 +13,6 @@ pub struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
/// Generate key pair
|
|
||||||
Generate,
|
|
||||||
/// Sign
|
|
||||||
Sign { file: PathBuf, private_key: PathBuf },
|
|
||||||
/// Sign
|
|
||||||
Verify { file: PathBuf, public_key: PathBuf },
|
|
||||||
Install {
|
Install {
|
||||||
public_key: PathBuf,
|
public_key: PathBuf,
|
||||||
bootspec: PathBuf,
|
bootspec: PathBuf,
|
||||||
|
@ -35,9 +28,6 @@ impl Cli {
|
||||||
impl Commands {
|
impl Commands {
|
||||||
pub fn call(self) -> Result<()> {
|
pub fn call(self) -> Result<()> {
|
||||||
match self {
|
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 {
|
Commands::Install {
|
||||||
public_key,
|
public_key,
|
||||||
bootspec,
|
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<()> {
|
fn install(public_key: &Path, bootspec: &Path) -> Result<()> {
|
||||||
let lanzaboote_bin = std::env::var("LANZABOOTE")?;
|
let lanzaboote_bin = std::env::var("LANZABOOTE")?;
|
||||||
install::install(public_key, bootspec, Path::new(&lanzaboote_bin))
|
install::install(public_key, bootspec, Path::new(&lanzaboote_bin))
|
||||||
|
|
|
@ -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<Signature> {
|
|
||||||
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(())
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ impl EspPaths {
|
||||||
Self {
|
Self {
|
||||||
esp: esp.to_owned(),
|
esp: esp.to_owned(),
|
||||||
nixos: esp_nixos.clone(),
|
nixos: esp_nixos.clone(),
|
||||||
kernel: esp_nixos.join("EFI/nixos"),
|
kernel: esp_nixos.join("kernel"),
|
||||||
initrd: esp_nixos.join("initrd"),
|
initrd: esp_nixos.join("initrd"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn install(_: &Path, bootspec: &Path, lanzaboote_bin: &Path) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_systemd_boot(bootctl: &Path, esp: &Path) -> Result<()> {
|
fn _install_systemd_boot(bootctl: &Path, esp: &Path) -> Result<()> {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("install"),
|
String::from("install"),
|
||||||
String::from("--path"),
|
String::from("--path"),
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod bootspec;
|
mod bootspec;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod crypto;
|
|
||||||
mod esp;
|
mod esp;
|
||||||
mod install;
|
mod install;
|
||||||
mod stub;
|
mod stub;
|
||||||
|
|
Loading…
Reference in New Issue