diff --git a/src/api.rs b/src/api.rs index 0aa59dce6db..40824a1ab61 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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 @@ -150,6 +155,9 @@ pub mod request { Delete: - key: KeyId + Clear: + - key: KeyId + DeleteAllKeys: - location: Location @@ -383,6 +391,9 @@ pub mod reply { Delete: - success: bool + Clear: + - success: bool + DeleteAllKeys: - count: usize diff --git a/src/client.rs b/src/client.rs index ce0b950b479..1ff8c1a498d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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 }) diff --git a/src/service.rs b/src/service.rs index ecbdbf16abc..668639f1221 100644 --- a/src/service.rs +++ b/src/service.rs @@ -225,6 +225,11 @@ impl ServiceResources

{ 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 } )) diff --git a/src/store/keystore.rs b/src/store/keystore.rs index 4241ec5337a..5a9d722a17a 100644 --- a/src/store/keystore.rs +++ b/src/store/keystore.rs @@ -52,6 +52,7 @@ pub trait Keystore { /// Return Header of key, if it exists fn key_info(&self, secrecy: key::Secrecy, id: &KeyId) -> Option; fn delete_key(&self, id: &KeyId) -> bool; + fn clear_key(&self, id: &KeyId) -> bool; fn delete_all(&self, location: Location) -> Result; fn load_key( &self, @@ -152,6 +153,10 @@ impl Keystore for ClientKeystore { }) } + 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 {