Skip to content

Commit 5d095b2

Browse files
author
Joe Ellis
committed
Add ListKeys implementation
1 parent 96acf41 commit 5d095b2

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

src/back/backend_handler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ impl BackEndHandler {
207207
trace!("list_authenticators egress");
208208
self.result_to_response(NativeResult::ListAuthenticators(result), header)
209209
}
210+
NativeOperation::ListKeys(op_list_keys) => {
211+
let result = unwrap_or_else_return!(self.provider.list_keys(op_list_keys));
212+
trace!("list_keys egress");
213+
self.result_to_response(NativeResult::ListKeys(result), header)
214+
}
210215
NativeOperation::PsaHashCompute(op_hash_compute) => {
211216
let _app_name =
212217
unwrap_or_else_return!(app_name.ok_or(ResponseStatus::NotAuthenticated));

src/providers/core_provider/mod.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use super::{KeyInfoStore, Provide};
99
use derivative::Derivative;
1010
use log::trace;
11-
use parsec_interface::operations::{list_authenticators, list_opcodes, list_providers, ping};
1211
use parsec_interface::operations::{
13-
list_authenticators::AuthenticatorInfo, list_providers::ProviderInfo,
12+
list_authenticators, list_keys, list_opcodes, list_providers, ping,
13+
};
14+
use parsec_interface::operations::{
15+
list_authenticators::AuthenticatorInfo, list_keys::KeyInfo, list_providers::ProviderInfo,
1416
};
1517
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus, Result};
1618
use std::collections::{HashMap, HashSet};
@@ -20,11 +22,12 @@ use std::sync::Arc;
2022
use uuid::Uuid;
2123
use version::{version, Version};
2224

23-
const SUPPORTED_OPCODES: [Opcode; 4] = [
25+
const SUPPORTED_OPCODES: [Opcode; 5] = [
2426
Opcode::ListProviders,
2527
Opcode::ListOpcodes,
2628
Opcode::Ping,
2729
Opcode::ListAuthenticators,
30+
Opcode::ListKeys,
2831
];
2932

3033
/// Service information provider
@@ -82,6 +85,45 @@ impl Provide for CoreProvider {
8285
})
8386
}
8487

88+
fn list_keys(&self, _op: list_keys::Operation) -> Result<list_keys::Result> {
89+
trace!("list_keys ingress");
90+
91+
let mut keys: Vec<KeyInfo> = Vec::new();
92+
for provider in &self.prov_list {
93+
let provider_id = provider.provider_id();
94+
95+
let key_info_store = match provider.get_key_info_store() {
96+
Some(key_info_store) => key_info_store,
97+
_ => continue,
98+
};
99+
100+
let key_info_store = key_info_store.read().expect("Key store lock poisoned");
101+
let key_triples = key_info_store.get_all(provider_id).map_err(|e| {
102+
format_error!("Error occurred when fetching key triples", e);
103+
ResponseStatus::KeyInfoManagerError
104+
})?;
105+
106+
for key_triple in key_triples {
107+
let key_info = key_info_store.get(key_triple).map_err(|e| {
108+
format_error!("Error occurred when fetching key info", e);
109+
ResponseStatus::KeyInfoManagerError
110+
})?;
111+
112+
let key_info = match key_info {
113+
Some(key_info) => key_info,
114+
_ => continue,
115+
};
116+
117+
keys.push(KeyInfo {
118+
provider_id,
119+
name: key_triple.key_name().to_string(),
120+
attributes: key_info.attributes,
121+
});
122+
}
123+
}
124+
Ok(list_keys::Result { keys })
125+
}
126+
85127
fn ping(&self, _op: ping::Operation) -> Result<ping::Result> {
86128
trace!("ping ingress");
87129
let result = ping::Result {

src/providers/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ impl ProviderConfig {
9393

9494
use crate::authenticators::ApplicationName;
9595
use parsec_interface::operations::{
96-
list_authenticators, list_opcodes, list_providers, ping, psa_aead_decrypt, psa_aead_encrypt,
97-
psa_asymmetric_decrypt, psa_asymmetric_encrypt, psa_destroy_key, psa_export_key,
98-
psa_export_public_key, psa_generate_key, psa_generate_random, psa_hash_compare,
96+
list_authenticators, list_keys, list_opcodes, list_providers, ping, psa_aead_decrypt,
97+
psa_aead_encrypt, psa_asymmetric_decrypt, psa_asymmetric_encrypt, psa_destroy_key,
98+
psa_export_key, psa_export_public_key, psa_generate_key, psa_generate_random, psa_hash_compare,
9999
psa_hash_compute, psa_import_key, psa_raw_key_agreement, psa_sign_hash, psa_verify_hash,
100100
};
101101
use parsec_interface::requests::{ResponseStatus, Result};
102102

103-
// If Parsec is built with no provider, this will be dead code -- suppress.
104-
#[allow(dead_code)]
105103
type KeyInfoStore = Arc<RwLock<dyn ManageKeyInfo + Send + Sync>>;
106104

107105
/// Provider interface for servicing client operations
@@ -145,6 +143,12 @@ pub trait Provide {
145143
Err(ResponseStatus::PsaErrorNotSupported)
146144
}
147145

146+
/// Lists all keys belonging to the application.
147+
fn list_keys(&self, _op: list_keys::Operation) -> Result<list_keys::Result> {
148+
trace!("list_keys ingress");
149+
Err(ResponseStatus::PsaErrorNotSupported)
150+
}
151+
148152
/// Execute a Ping operation to get the wire protocol version major and minor information.
149153
///
150154
/// # Errors

0 commit comments

Comments
 (0)