Skip to content

Commit

Permalink
Merge pull request #508 from MattDavis00/feature-sqlite-key-info-manager
Browse files Browse the repository at this point in the history
Added SQLiteKeyInfoManager Storage & Retrieval Functionality.
  • Loading branch information
ionut-arm committed Sep 1, 2021
2 parents 462c054 + 81f3f66 commit d43e9b1
Show file tree
Hide file tree
Showing 7 changed files with 688 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ tags
# Git patch files
*.patch

# Parsec key info mappings directory
# Parsec key info mappings directories
mappings/
kim-mappings/

# TPM simulator state file
NVChip
71 changes: 70 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ anyhow = "1.0.38"
rust-cryptoauthlib = { version = "0.4.0", optional = true }
spiffe = { version = "0.1.1", optional = true }
prost = { version = "0.7.0", optional = true }
rusqlite = { version = "0.25.3", features = ["bundled"] }
num-traits = "0.2.14"

[dev-dependencies]
rand = { version = "0.8.3", features = ["small_rng"] }
Expand Down
27 changes: 20 additions & 7 deletions src/key_info_managers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::sync::{Arc, RwLock};
use zeroize::Zeroize;

pub mod on_disk_manager;
pub mod sqlite_manager;

/// This structure corresponds to a unique identifier of the key. It is used internally by the Key
/// ID manager to refer to a key.
Expand Down Expand Up @@ -71,8 +72,9 @@ impl KeyIdentity {
}

/// Checks if this key belongs to a specific provider.
pub fn belongs_to_provider(&self, provider_name: String) -> bool {
*self.provider().name() == provider_name
pub fn belongs_to_provider(&self, provider_identity: &ProviderIdentity) -> bool {
self.provider().name() == provider_identity.name()
&& self.provider().uuid() == provider_identity.uuid()
}

/// Get the key name
Expand Down Expand Up @@ -396,20 +398,31 @@ pub struct KeyInfoManagerFactory {
impl KeyInfoManagerFactory {
/// Create a KeyInfoManagerFactory
pub fn new(config: &KeyInfoManagerConfig, default_auth_type: AuthType) -> Result<Self> {
let manager = match config.manager_type {
let factory = match config.manager_type {
KeyInfoManagerType::OnDisk => {
let mut builder = on_disk_manager::OnDiskKeyInfoManagerBuilder::new();
if let Some(store_path) = &config.store_path {
builder = builder.with_mappings_dir_path(store_path.into());
}
builder = builder.with_auth_type(default_auth_type);
builder.build()?
let manager = builder.build()?;
KeyInfoManagerFactory {
key_info_manager_impl: Arc::new(RwLock::new(manager)),
}
}
KeyInfoManagerType::SQLite => {
let mut builder = sqlite_manager::SQLiteKeyInfoManagerBuilder::new();
if let Some(sqlite_db_path) = &config.sqlite_db_path {
builder = builder.with_db_path(sqlite_db_path.into());
}
let manager = builder.build()?;
KeyInfoManagerFactory {
key_info_manager_impl: Arc::new(RwLock::new(manager)),
}
}
};

Ok(KeyInfoManagerFactory {
key_info_manager_impl: Arc::new(RwLock::new(manager)),
})
Ok(factory)
}

/// Build a KeyInfoManagerClient
Expand Down

0 comments on commit d43e9b1

Please sign in to comment.