Add a key store to avoid storing secrets in the store

This commit is contained in:
Julien Cretin
2022-06-29 11:55:02 +02:00
parent 667c269552
commit d793a992d3
9 changed files with 172 additions and 77 deletions

3
src/env/mod.rs vendored
View File

@@ -15,6 +15,7 @@
use crate::api::connection::HidConnection;
use crate::api::customization::Customization;
use crate::api::firmware_protection::FirmwareProtection;
use crate::api::key_store::KeyStore;
use crate::api::upgrade_storage::UpgradeStorage;
use crate::api::user_presence::UserPresence;
use persistent_store::{Storage, Store};
@@ -29,6 +30,7 @@ pub trait Env {
type Rng: Rng256;
type UserPresence: UserPresence;
type Storage: Storage;
type KeyStore: KeyStore;
type UpgradeStorage: UpgradeStorage;
type FirmwareProtection: FirmwareProtection;
type Write: core::fmt::Write;
@@ -38,6 +40,7 @@ pub trait Env {
fn rng(&mut self) -> &mut Self::Rng;
fn user_presence(&mut self) -> &mut Self::UserPresence;
fn store(&mut self) -> &mut Store<Self::Storage>;
fn key_store(&mut self) -> &mut Self::KeyStore;
/// Returns the upgrade storage instance.
///

5
src/env/test/mod.rs vendored
View File

@@ -151,6 +151,7 @@ impl Env for TestEnv {
type Rng = TestRng256;
type UserPresence = TestUserPresence;
type Storage = BufferStorage;
type KeyStore = Self;
type UpgradeStorage = BufferUpgradeStorage;
type FirmwareProtection = Self;
type Write = TestWrite;
@@ -169,6 +170,10 @@ impl Env for TestEnv {
&mut self.store
}
fn key_store(&mut self) -> &mut Self {
self
}
fn upgrade_storage(&mut self) -> Option<&mut Self::UpgradeStorage> {
self.upgrade_storage.as_mut()
}

5
src/env/tock/mod.rs vendored
View File

@@ -197,6 +197,7 @@ impl Env for TockEnv {
type Rng = TockRng256;
type UserPresence = Self;
type Storage = TockStorage;
type KeyStore = Self;
type UpgradeStorage = TockUpgradeStorage;
type FirmwareProtection = Self;
type Write = Console;
@@ -215,6 +216,10 @@ impl Env for TockEnv {
&mut self.store
}
fn key_store(&mut self) -> &mut Self {
self
}
fn upgrade_storage(&mut self) -> Option<&mut Self::UpgradeStorage> {
self.upgrade_storage.as_mut()
}