Skip to content

Commit 80782c0

Browse files
committed
shared: detect when it's infeasible to sign a stub parameter
This is relevant for a remote signer who relies on the existence of store paths remotely, for example.
1 parent d6161d6 commit 80782c0

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

rust/tool/shared/src/pe.rs

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl StubParameters {
6060
self.kernel_cmdline = cmdline.to_vec();
6161
self
6262
}
63+
64+
pub fn all_signables_in_store(&self) -> bool {
65+
self.lanzaboote_store_path.starts_with("/nix/store")
66+
&& self.kernel_store_path.starts_with("/nix/store")
67+
&& self.initrd_store_path.starts_with("/nix/store")
68+
}
6369
}
6470

6571
/// Performs the evil operation

rust/tool/shared/src/signature/local.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ impl LanzabooteSigner for LocalKeyPair {
3030
Ok(std::fs::read(&self.public_key)?)
3131
}
3232

33+
fn can_sign_stub(&self, _stub: &crate::pe::StubParameters) -> bool {
34+
true
35+
}
36+
3337
fn sign_and_copy(&self, from: &Path, to: &Path) -> Result<()> {
3438
let args: Vec<OsString> = vec![
3539
OsString::from("--key"),

rust/tool/shared/src/signature/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::pe::StubParameters;
55

66
pub trait LanzabooteSigner {
77
fn sign_store_path(&self, store_path: &Path) -> Result<Vec<u8>>;
8+
fn can_sign_stub(&self, stub: &StubParameters) -> bool;
89
fn build_and_sign_stub(&self, stub: &StubParameters) -> Result<Vec<u8>>;
910
fn get_public_key(&self) -> Result<Vec<u8>>;
1011

rust/tool/shared/src/signature/remote.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33
use crate::pe::StubParameters;
44

55
use super::LanzabooteSigner;
6-
use anyhow::{Context, Result};
6+
use anyhow::{bail, Context, Result};
77
use serde::{Deserialize, Serialize};
88
use ureq::{Agent, AgentBuilder};
99
use url::Url;
@@ -57,6 +57,10 @@ impl RemoteSigningServer {
5757
/// If the remote server agrees on providing that stub
5858
/// It will return it signed.
5959
fn request_signature(&self, stub_parameters: &StubParameters) -> Result<Vec<u8>> {
60+
if !stub_parameters.all_signables_in_store() {
61+
bail!("Signable stub parameters contains non-Nix store paths, the remote server cannot sign that!");
62+
}
63+
6064
let response = self
6165
.client
6266
.post(self.server_url.join("/sign-stub")?.as_str())
@@ -166,6 +170,10 @@ impl LanzabooteSigner for RemoteSigningServer {
166170
Ok(binary)
167171
}
168172

173+
fn can_sign_stub(&self, stub: &StubParameters) -> bool {
174+
stub.all_signables_in_store()
175+
}
176+
169177
fn build_and_sign_stub(&self, stub: &StubParameters) -> Result<Vec<u8>> {
170178
self.request_signature(stub)
171179
}

rust/tool/systemd/src/install.rs

+6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ impl<S: LanzabooteSigner> Installer<S> {
248248
.with_cmdline(&kernel_cmdline)
249249
.with_os_release_contents(os_release_contents.as_bytes());
250250

251+
// TODO: how should we handle those cases?
252+
if !self.signer.can_sign_stub(&parameters) {
253+
log::warn!("Signer is not able to sign this stub, skipping...");
254+
return Ok(());
255+
}
256+
251257
let lanzaboote_image = self
252258
.signer
253259
.build_and_sign_stub(&parameters)

0 commit comments

Comments
 (0)