mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
sign-image: enable kernel image signing
Previously we only supported signing the loader. This also adds the kernel as a thing that can be signed. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
fcbc901df8
commit
aaa4407e21
1 changed files with 52 additions and 23 deletions
|
|
@ -7,7 +7,7 @@ use ring::signature::Ed25519KeyPair;
|
||||||
const DEVKEY_PATH: &str = "devkey/dev.key";
|
const DEVKEY_PATH: &str = "devkey/dev.key";
|
||||||
const LOADER_VERSION: u32 = 1;
|
const LOADER_VERSION: u32 = 1;
|
||||||
|
|
||||||
fn loader_sign<S, T>(
|
fn image_sign<S, T>(
|
||||||
input: &S,
|
input: &S,
|
||||||
output: &T,
|
output: &T,
|
||||||
private_key: &pem::Pem,
|
private_key: &pem::Pem,
|
||||||
|
|
@ -100,6 +100,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("kernel-key")
|
Arg::with_name("kernel-key")
|
||||||
|
.long("kernel-key")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("kernel signing key")
|
.help("kernel signing key")
|
||||||
|
|
@ -108,11 +109,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("loader-output")
|
Arg::with_name("loader-output")
|
||||||
|
.long("loader-output")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
|
||||||
.value_name("loader output image")
|
.value_name("loader output image")
|
||||||
.help("loader output image")
|
.help("loader output image"),
|
||||||
.default_value("target/riscv32imac-unknown-none-elf/release/loader.bin"),
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("kernel-output")
|
||||||
|
.long("kernel-output")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("kernel output image")
|
||||||
|
.help("kernel output image"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("defile").help(
|
Arg::with_name("defile").help(
|
||||||
|
|
@ -121,27 +128,49 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let loader_key = matches
|
// Sign the loader, if an output file was specified
|
||||||
.value_of("loader-key")
|
if let Some(loader_output) = matches.value_of("loader-output") {
|
||||||
.expect("no loader key specified");
|
let loader_key = matches
|
||||||
let loader_output = matches
|
.value_of("loader-key")
|
||||||
.value_of("loader-output")
|
.expect("no loader key specified");
|
||||||
.expect("no output specified");
|
let loader_image = matches
|
||||||
let loader_image = matches
|
.value_of("loader-image")
|
||||||
.value_of("loader-image")
|
.expect("no loader image specified");
|
||||||
.expect("no loader image specified");
|
|
||||||
|
|
||||||
let loader_pkey = load_pem(loader_key)?;
|
let loader_pkey = load_pem(loader_key)?;
|
||||||
if loader_pkey.tag != "PRIVATE KEY" {
|
if loader_pkey.tag != "PRIVATE KEY" {
|
||||||
println!("Loader key was a {}, not a PRIVATE KEY", loader_pkey.tag);
|
println!("Loader key was a {}, not a PRIVATE KEY", loader_pkey.tag);
|
||||||
Err("invalid pkey type")?;
|
Err("invalid loader private key type")?;
|
||||||
|
}
|
||||||
|
println!("Signing loader");
|
||||||
|
image_sign(
|
||||||
|
&loader_image,
|
||||||
|
&loader_output,
|
||||||
|
&loader_pkey,
|
||||||
|
matches.is_present("defile"),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
loader_sign(
|
if let Some(kernel_output) = matches.value_of("kernel-output") {
|
||||||
&loader_image,
|
let kernel_key = matches
|
||||||
&loader_output,
|
.value_of("kernel-key")
|
||||||
&loader_pkey,
|
.expect("no kernel key specified");
|
||||||
matches.is_present("defile"),
|
let kernel_image = matches
|
||||||
)?;
|
.value_of("kernel-image")
|
||||||
|
.expect("no kernel image specified");
|
||||||
|
|
||||||
|
let kernel_pkey = load_pem(kernel_key)?;
|
||||||
|
if kernel_pkey.tag != "PRIVATE KEY" {
|
||||||
|
println!("Kernel key was a {}, not a PRIVATE KEY", kernel_pkey.tag);
|
||||||
|
Err("invalid kernel private key type")?;
|
||||||
|
}
|
||||||
|
println!("Signing kernel");
|
||||||
|
image_sign(
|
||||||
|
&kernel_image,
|
||||||
|
&kernel_output,
|
||||||
|
&kernel_pkey,
|
||||||
|
matches.is_present("defile"),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue