mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-18 08:06:22 +00:00
StoragManager: track SecurityCoordinator changes
- break dependency loop with kata-security-interface - use new kata_security_* wrappers Change-Id: I65b98a406f18c82354e5425b37612789d4ab340d GitOrigin-RevId: 5744715a439a5305ead57a99eacc1108b5d10750
This commit is contained in:
@@ -7,5 +7,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cstr_core = "0.2.3"
|
||||
kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" }
|
||||
postcard = { version = "0.7", features = ["alloc"], default-features = false }
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
use core::str;
|
||||
use cstr_core::CString;
|
||||
use kata_security_interface::SecurityRequestError;
|
||||
use postcard;
|
||||
|
||||
// TODO(sleffler): temp constraint on value part of key-value pairs
|
||||
@@ -28,22 +27,6 @@ pub enum StorageError {
|
||||
DeleteFailed,
|
||||
}
|
||||
|
||||
impl From<SecurityRequestError> for StorageError {
|
||||
fn from(err: SecurityRequestError) -> StorageError {
|
||||
match err {
|
||||
SecurityRequestError::SreBundleNotFound => StorageError::BundleNotFound,
|
||||
SecurityRequestError::SreKeyNotFound => StorageError::KeyNotFound,
|
||||
SecurityRequestError::SreValueInvalid => StorageError::ValueInvalid,
|
||||
SecurityRequestError::SreKeyInvalid => StorageError::KeyInvalid,
|
||||
SecurityRequestError::SreSerializeFailed => StorageError::SerializeFailed,
|
||||
SecurityRequestError::SreReadFailed => StorageError::ReadFailed,
|
||||
SecurityRequestError::SreWriteFailed => StorageError::WriteFailed,
|
||||
SecurityRequestError::SreDeleteFailed => StorageError::DeleteFailed,
|
||||
_ => StorageError::UnknownSecurityError, // NB: cannot happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<postcard::Error> for StorageError {
|
||||
fn from(_err: postcard::Error) -> StorageError {
|
||||
StorageError::SerializeFailed
|
||||
|
@@ -2,12 +2,9 @@
|
||||
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
use kata_security_interface::kata_security_request;
|
||||
use kata_security_interface::DeleteKeyRequest;
|
||||
use kata_security_interface::ReadKeyRequest;
|
||||
use kata_security_interface::SecurityRequest;
|
||||
use kata_security_interface::WriteKeyRequest;
|
||||
use kata_security_interface::SECURITY_REPLY_DATA_SIZE;
|
||||
use kata_security_interface::kata_security_delete_key;
|
||||
use kata_security_interface::kata_security_read_key;
|
||||
use kata_security_interface::kata_security_write_key;
|
||||
use kata_storage_interface::StorageError;
|
||||
use kata_storage_interface::StorageManagerInterface;
|
||||
use kata_storage_interface::{KeyValueData, KEY_VALUE_DATA_SIZE};
|
||||
@@ -21,20 +18,9 @@ impl StorageManagerInterface for KataStorageManager {
|
||||
fn read(&self, bundle_id: &str, key: &str) -> Result<KeyValueData, StorageError> {
|
||||
trace!("read bundle_id:{} key:{}", bundle_id, key);
|
||||
|
||||
// Send request to Security Core via SecurityCoordinator
|
||||
let result = &mut [0u8; SECURITY_REPLY_DATA_SIZE];
|
||||
kata_security_request(
|
||||
SecurityRequest::SrReadKey,
|
||||
&ReadKeyRequest {
|
||||
bundle_id: bundle_id,
|
||||
key: key,
|
||||
},
|
||||
result,
|
||||
)?;
|
||||
// NB: must copy into KeyValueData for now
|
||||
let mut keyval = [0u8; KEY_VALUE_DATA_SIZE];
|
||||
keyval.copy_from_slice(&result[..KEY_VALUE_DATA_SIZE]);
|
||||
Ok(keyval)
|
||||
Ok(kata_security_read_key(bundle_id, key, &mut keyval).map(|_| keyval)?)
|
||||
}
|
||||
fn write(&self, bundle_id: &str, key: &str, value: &[u8]) -> Result<(), StorageError> {
|
||||
trace!(
|
||||
@@ -44,32 +30,11 @@ impl StorageManagerInterface for KataStorageManager {
|
||||
value
|
||||
);
|
||||
|
||||
// Send request to Security Core via SecurityCoordinator
|
||||
let result = &mut [0u8; SECURITY_REPLY_DATA_SIZE];
|
||||
kata_security_request(
|
||||
SecurityRequest::SrWriteKey,
|
||||
&WriteKeyRequest {
|
||||
bundle_id: bundle_id,
|
||||
key: key,
|
||||
value: value,
|
||||
},
|
||||
result,
|
||||
)?;
|
||||
Ok(())
|
||||
Ok(kata_security_write_key(bundle_id, key, value)?)
|
||||
}
|
||||
fn delete(&self, bundle_id: &str, key: &str) -> Result<(), StorageError> {
|
||||
trace!("delete bundle_id:{} key:{}", bundle_id, key);
|
||||
|
||||
// Send request to Security Core via SecurityCoordinator
|
||||
let result = &mut [0u8; SECURITY_REPLY_DATA_SIZE];
|
||||
kata_security_request(
|
||||
SecurityRequest::SrDeleteKey,
|
||||
&DeleteKeyRequest {
|
||||
bundle_id: bundle_id,
|
||||
key: key,
|
||||
},
|
||||
result,
|
||||
)?;
|
||||
Ok(())
|
||||
Ok(kata_security_delete_key(bundle_id, key)?)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user