Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add revocation support for hashes #13

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/criticaltrust/src/keys/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub enum KeyRole {
Packages,
/// `redirects` key role, used to sign dynamic server redirects.
Redirects,
/// `revocation` key role, used to sign revoked content hashes.
Revocation,
/// `root` key role, used to sign other keys.
Root,
#[serde(other)]
Expand Down
15 changes: 15 additions & 0 deletions crates/criticaltrust/src/manifests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::keys::{KeyRole, PublicKey};
use crate::signatures::{Signable, SignedPayload};
use serde::de::Error as _;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

/// Typed representation of a manifest version number.
///
Expand Down Expand Up @@ -154,12 +155,26 @@ pub struct PackageFile {
pub needs_proxy: bool,
}

// Revocations

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct RevocationInfo {
pub revoked_content_sha256: Vec<String>,
pub expires_at: OffsetDateTime,
}

impl Signable for RevocationInfo {
const SIGNED_BY_ROLE: KeyRole = KeyRole::Revocation;
}

// Keys

#[derive(Debug, Serialize, Deserialize)]
pub struct KeysManifest {
pub version: ManifestVersion<1>,
pub keys: Vec<SignedPayload<PublicKey>>,
pub revoked_signatures: SignedPayload<RevocationInfo>,
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions crates/mock-download-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ criticaltrust = { path = "../criticaltrust" }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
tiny_http = { version = "0.12.0", default-features = false, features = ["rustls"] }
time = { version = "0.3.7", features = ["std", "serde", "serde-well-known"] }
9 changes: 8 additions & 1 deletion crates/mock-download-server/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

use crate::Serialize;
use crate::{AuthenticationToken, Data};
use criticaltrust::manifests::ManifestVersion;
use criticaltrust::manifests::{ManifestVersion, RevocationInfo};
use criticaltrust::signatures::SignedPayload;
use time::{Duration, OffsetDateTime};
use tiny_http::{Header, Method, Request, Response, ResponseBox, StatusCode};

pub(crate) fn handle_request(data: &Data, req: &Request) -> ResponseBox {
Expand Down Expand Up @@ -39,6 +41,11 @@ fn handle_v1_keys(data: &Data) -> Result<Resp, Resp> {
Ok(Resp::json(&criticaltrust::manifests::KeysManifest {
version: ManifestVersion,
keys: data.keys.clone(),
revoked_signatures: SignedPayload::new(&RevocationInfo {
revoked_content_sha256: Vec::new(),
expires_at: OffsetDateTime::now_utc() + Duration::days(99),
})
.unwrap(),
}))
}

Expand Down
9 changes: 8 additions & 1 deletion crates/mock-download-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ mod server;

pub use crate::server::MockServer;
use criticaltrust::keys::PublicKey;
use criticaltrust::manifests::ReleaseManifest;
use criticaltrust::manifests::{ReleaseManifest, RevocationInfo};
use criticaltrust::signatures::SignedPayload;
use serde::Serialize;
use std::borrow::Cow;
use std::collections::HashMap;
use time::{Duration, OffsetDateTime};

#[derive(Serialize, Clone)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -23,6 +24,7 @@ pub struct AuthenticationToken {
pub struct Data {
pub tokens: HashMap<String, AuthenticationToken>,
pub keys: Vec<SignedPayload<PublicKey>>,
pub revoked_signatures: SignedPayload<RevocationInfo>,
pub release_manifests: HashMap<(String, String), ReleaseManifest>,
}

Expand All @@ -31,6 +33,11 @@ pub fn new() -> Builder {
data: Data {
tokens: HashMap::new(),
keys: Vec::new(),
revoked_signatures: SignedPayload::new(&RevocationInfo {
revoked_content_sha256: Vec::new(),
expires_at: OffsetDateTime::now_utc() + Duration::days(99),
})
.unwrap(),
release_manifests: HashMap::new(),
},
}
Expand Down
Loading