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

Access the keystore via a path rather than the CoreContext #29

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ generate_enums! {
DeserializeKey: 5
Encrypt: 6
Delete: 7
// Clear private data from the key
// This will not always delete all metadata from storage.
// Other backends can retain metadata required for `unwrap_key` to work properly
// and delete this metadata only once `delete` is called.
Clear: 63
DeleteAllKeys: 25
Exists: 8
// DeriveKeypair: 3
Expand Down Expand Up @@ -150,6 +155,9 @@ pub mod request {
Delete:
- key: KeyId

Clear:
- key: KeyId

DeleteAllKeys:
- location: Location

Expand Down Expand Up @@ -383,6 +391,9 @@ pub mod reply {
Delete:
- success: bool

Clear:
- success: bool

DeleteAllKeys:
- count: usize

Expand Down
12 changes: 12 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ pub trait CryptoClient: PollClient {
})
}

/// Clear private data from the key
///
/// This will not delete all metadata from storage.
/// Other backends can retain metadata required for `unwrap_key` to work properly
/// and delete this metadata only once `delete` is called.
fn clear(&mut self, key: KeyId) -> ClientResult<'_, reply::Delete, Self> {
self.request(request::Delete {
key,
// mechanism,
})
}

/// Skips deleting read-only / manufacture keys (currently, "low ID").
fn delete_all(&mut self, location: Location) -> ClientResult<'_, reply::DeleteAllKeys, Self> {
self.request(request::DeleteAllKeys { location })
Expand Down
11 changes: 8 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ impl<P: Platform> ServiceResources<P> {
ClientFilestore::new(PathBuf::from("trussed"), self.platform.store())
}

pub fn keystore(&mut self, ctx: &CoreContext) -> Result<ClientKeystore<P::S>> {
pub fn keystore(&mut self, client_id: PathBuf) -> Result<ClientKeystore<P::S>> {
self.rng()
.map(|rng| ClientKeystore::new(ctx.path.clone(), rng, self.platform.store()))
.map(|rng| ClientKeystore::new(client_id, rng, self.platform.store()))
.map_err(|_| Error::EntropyMalfunction)
}

Expand All @@ -141,7 +141,7 @@ impl<P: Platform> ServiceResources<P> {

let full_store = self.platform.store();

let keystore = &mut self.keystore(ctx)?;
let keystore = &mut self.keystore(ctx.path.clone())?;
let certstore = &mut self.certstore(ctx)?;
let counterstore = &mut self.counterstore(ctx)?;
let filestore = &mut self.filestore(ctx.path.clone());
Expand Down Expand Up @@ -225,6 +225,11 @@ impl<P: Platform> ServiceResources<P> {
Ok(Reply::Delete(reply::Delete { success } ))
},

Request::Clear(request) => {
let success = keystore.clear_key(&request.key);
Ok(Reply::Clear(reply::Clear { success } ))
},

Request::DeleteAllKeys(request) => {
let count = keystore.delete_all(request.location)?;
Ok(Reply::DeleteAllKeys(reply::DeleteAllKeys { count } ))
Expand Down
5 changes: 5 additions & 0 deletions src/store/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub trait Keystore {
/// Return Header of key, if it exists
fn key_info(&self, secrecy: key::Secrecy, id: &KeyId) -> Option<key::Info>;
fn delete_key(&self, id: &KeyId) -> bool;
fn clear_key(&self, id: &KeyId) -> bool;
fn delete_all(&self, location: Location) -> Result<usize>;
fn load_key(
&self,
Expand Down Expand Up @@ -152,6 +153,10 @@ impl<S: Store> Keystore for ClientKeystore<S> {
})
}

fn clear_key(&self, id: &KeyId) -> bool {
self.delete_key(id)
}

/// TODO: This uses the predicate "filename.len() >= 4"
/// Be more principled :)
fn delete_all(&self, location: Location) -> Result<usize> {
Expand Down