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

Added SQLiteKeyInfoManager Storage & Retrieval Functionality. #508

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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