Skip to content

Commit f190fb3

Browse files
authored
Merge pull request #152 from hug-dev/key_info
Rename key ID to key info
2 parents 01078ca + eec86de commit f190fb3

File tree

18 files changed

+258
-219
lines changed

18 files changed

+258
-219
lines changed

โ€ŽCargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€ŽCargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name = "parsec"
1818
path = "src/bin/main.rs"
1919

2020
[dependencies]
21-
parsec-interface = "0.13.0"
21+
parsec-interface = "0.14.0"
2222
rand = "0.7.2"
2323
base64 = "0.10.1"
2424
uuid = "0.7.4"
@@ -45,8 +45,8 @@ picky-asn1-der = "0.2.2"
4545
picky-asn1 = "0.2.1"
4646
serde = { version = "1.0", features = ["derive"] }
4747
sha2 = "0.8.1"
48-
parsec-client = "0.1.0"
49-
parsec-interface = { version = "0.13.0", features = ["testing"] }
48+
parsec-client = "0.2.0"
49+
parsec-interface = { version = "0.14.0", features = ["testing"] }
5050

5151
[build-dependencies]
5252
bindgen = "0.50.0"

โ€Žconfig.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ listener_type = "DomainSocket"
3030
# timeout expires, the connection is dropped.
3131
timeout = 200 # in milliseconds
3232

33-
# (Required) Configuration for the components managing key IDs for providers.
33+
# (Required) Configuration for the components managing key info for providers.
3434
# Defined as an array of tables: https://github.com/toml-lang/toml#user-content-array-of-tables
3535
[[key_manager]]
36-
# (Required) Name of the key ID manager. Used to tie providers to the manager supporting them.
36+
# (Required) Name of the key info manager. Used to tie providers to the manager supporting them.
3737
name = "on-disk-manager"
3838

39-
# (Required) Type of key ID manager to be used.
39+
# (Required) Type of key info manager to be used.
4040
manager_type = "OnDisk"
4141

4242
# Path to the location where the mapping will be persisted (in this case, the filesystem path)
@@ -48,13 +48,13 @@ manager_type = "OnDisk"
4848
# (Required) Type of provider.
4949
provider_type = "MbedCrypto"
5050

51-
# (Required) Name of key ID manager that will support this provider.
52-
key_id_manager = "on-disk-manager"
51+
# (Required) Name of key info manager that will support this provider.
52+
key_info_manager = "on-disk-manager"
5353

5454
# Example of a PKCS 11 provider configuration
5555
#[[provider]]
5656
#provider_type = "Pkcs11"
57-
#key_id_manager = "on-disk-manager"
57+
#key_info_manager = "on-disk-manager"
5858
# (Required for this provider) Path to the location of the dynamic library loaded by this provider.
5959
# For the PKCS 11 provider, this library implements the PKCS 11 API on the target platform.
6060
#library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
@@ -67,7 +67,7 @@ key_id_manager = "on-disk-manager"
6767
# Example of a TPM provider configuration
6868
#[[provider]]
6969
#provider_type = "Tpm"
70-
#key_id_manager = "on-disk-manager"
70+
#key_info_manager = "on-disk-manager"
7171
# (Required) TPM TCTI device to use with this provider. Options are:
7272
# - "device": uses the TPM device on /dev/tpm0
7373
# - "mssim": uses the simulation TPM with the socket

โ€Žfuzz/config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ manager_type = "OnDisk"
1010

1111
[[provider]]
1212
provider_type = "MbedProvider"
13-
key_id_manager = "on-disk-manager"
13+
key_info_manager = "on-disk-manager"
1414

1515
[[provider]]
1616
provider_type = "TpmProvider"
17-
key_id_manager = "on-disk-manager"
17+
key_info_manager = "on-disk-manager"
1818
tcti = "mssim"
1919

2020
[[provider]]
2121
provider_type = "Pkcs11Provider"
22-
key_id_manager = "on-disk-manager"
22+
key_info_manager = "on-disk-manager"
2323
library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
2424
user_pin = "123456"
2525
# The slot_number mandatory field is going to be added by the find_slot_number.sh script

โ€Žsrc/key_id_managers/mod.rs renamed to โ€Žsrc/key_info_managers/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//! Persistent mapping between key triples and key information
44
//!
5-
//! This module declares a [`ManageKeyIDs`](https://parallaxsecond.github.io/parsec-book/parsec_service/key_id_managers.html)
5+
//! This module declares a [`ManageKeyInfo`](https://parallaxsecond.github.io/parsec-book/parsec_service/key_info_managers.html)
66
//! trait to help providers to store in a persistent manner the mapping between the name and the
77
//! information of the keys they manage. Different implementors might store this mapping using different
88
//! means but it has to be persistent.
@@ -17,14 +17,14 @@ use std::fmt;
1717
pub mod on_disk_manager;
1818

1919
#[derive(Copy, Clone, Deserialize, Debug)]
20-
pub enum KeyIdManagerType {
20+
pub enum KeyInfoManagerType {
2121
OnDisk,
2222
}
2323

2424
#[derive(Deserialize, Debug)]
25-
pub struct KeyIdManagerConfig {
25+
pub struct KeyInfoManagerConfig {
2626
pub name: String,
27-
pub manager_type: KeyIdManagerType,
27+
pub manager_type: KeyInfoManagerType,
2828
pub store_path: Option<String>,
2929
}
3030

@@ -72,41 +72,41 @@ impl KeyTriple {
7272
}
7373
}
7474

75-
/// Converts the error string returned by the ManageKeyIDs methods to
76-
/// ResponseStatus::KeyIDManagerError.
75+
/// Converts the error string returned by the ManageKeyInfo methods to
76+
/// ResponseStatus::KeyInfoManagerError.
7777
pub fn to_response_status(error_string: String) -> ResponseStatus {
7878
error!(
79-
"Converting error string \"{}\" to ResponseStatus:KeyIDManagerError.",
79+
"Converting error string \"{}\" to ResponseStatus:KeyInfoManagerError.",
8080
error_string
8181
);
82-
ResponseStatus::KeyIDManagerError
82+
ResponseStatus::KeyInfoManagerError
8383
}
8484

8585
/// Management interface for key name to key info mapping
8686
///
8787
/// Interface to be implemented for persistent storage of key name -> key info mappings.
88-
pub trait ManageKeyIDs {
88+
pub trait ManageKeyInfo {
8989
/// Returns a reference to the key info corresponding to this key triple or `None` if it does not
9090
/// exist.
9191
///
9292
/// # Errors
9393
///
94-
/// Returns an error as a String if there was a problem accessing the Key ID Manager.
94+
/// Returns an error as a String if there was a problem accessing the Key Info Manager.
9595
fn get(&self, key_triple: &KeyTriple) -> Result<Option<&KeyInfo>, String>;
9696

9797
/// Returns a Vec of reference to the key triples corresponding to this provider.
9898
///
9999
/// # Errors
100100
///
101-
/// Returns an error as a String if there was a problem accessing the Key ID Manager.
101+
/// Returns an error as a String if there was a problem accessing the Key Info Manager.
102102
fn get_all(&self, provider_id: ProviderID) -> Result<Vec<&KeyTriple>, String>;
103103

104104
/// Inserts a new mapping between the key triple and the key info. If the triple already exists,
105105
/// overwrite the existing mapping and returns the old `KeyInfo`. Otherwise returns `None`.
106106
///
107107
/// # Errors
108108
///
109-
/// Returns an error as a String if there was a problem accessing the Key ID Manager.
109+
/// Returns an error as a String if there was a problem accessing the Key Info Manager.
110110
fn insert(
111111
&mut self,
112112
key_triple: KeyTriple,
@@ -118,13 +118,13 @@ pub trait ManageKeyIDs {
118118
///
119119
/// # Errors
120120
///
121-
/// Returns an error as a String if there was a problem accessing the Key ID Manager.
121+
/// Returns an error as a String if there was a problem accessing the Key Info Manager.
122122
fn remove(&mut self, key_triple: &KeyTriple) -> Result<Option<KeyInfo>, String>;
123123

124124
/// Check if a key triple mapping exists.
125125
///
126126
/// # Errors
127127
///
128-
/// Returns an error as a String if there was a problem accessing the Key ID Manager.
128+
/// Returns an error as a String if there was a problem accessing the Key Info Manager.
129129
fn exists(&self, key_triple: &KeyTriple) -> Result<bool, String>;
130130
}

โ€Žsrc/key_id_managers/on_disk_manager/mod.rs renamed to โ€Žsrc/key_info_managers/on_disk_manager/mod.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2019 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
//! A key ID manager storing key triple to key info mapping on files on disk
3+
//! A key info manager storing key triple to key info mapping on files on disk
44
//!
55
//! The path where the mappings should be stored is configurable. Because of possible data races,
66
//! there should not be two instances of this manager pointing to the same mapping folder at a time.
@@ -12,7 +12,7 @@
1212
//! example, for operating systems having a limit of 255 characters for filenames (Unix systems),
1313
//! names will be limited to 188 bytes of UTF-8 characters.
1414
//! For security reasons, only the PARSEC service should have the ability to modify these files.
15-
use super::{KeyInfo, KeyTriple, ManageKeyIDs};
15+
use super::{KeyInfo, KeyTriple, ManageKeyInfo};
1616
use crate::authenticators::ApplicationName;
1717
use log::{error, info};
1818
use parsec_interface::requests::ProviderID;
@@ -27,7 +27,7 @@ use std::path::PathBuf;
2727
pub const DEFAULT_MAPPINGS_PATH: &str = "./mappings";
2828

2929
#[derive(Debug)]
30-
pub struct OnDiskKeyIDManager {
30+
pub struct OnDiskKeyInfoManager {
3131
/// Internal mapping, used for non-modifying operations.
3232
key_store: HashMap<KeyTriple, KeyInfo>,
3333
/// Folder where all the key triple to key info mappings are saved. This folder will be created
@@ -145,11 +145,11 @@ fn list_files(path: &PathBuf) -> std::io::Result<Vec<PathBuf>> {
145145
.collect())
146146
}
147147

148-
/// Filesystem-based `KeyIdManager`
148+
/// Filesystem-based `KeyInfoManager`
149149
///
150-
/// The `OnDiskKeyIdManager` relies on access control mechanisms provided by the OS for
150+
/// The `OnDiskKeyInfoManager` relies on access control mechanisms provided by the OS for
151151
/// the filesystem to ensure security of the mappings.
152-
impl OnDiskKeyIDManager {
152+
impl OnDiskKeyInfoManager {
153153
/// Creates an instance of the on-disk manager from the mapping files. This function will
154154
/// create the mappings directory if it does not already exist.
155155
/// The mappings folder is composed of three levels: two levels of directory and one level
@@ -178,7 +178,7 @@ impl OnDiskKeyIDManager {
178178
/// # Errors
179179
///
180180
/// Returns an std::io error if the function failed reading the mapping files.
181-
fn new(mappings_dir_path: PathBuf) -> std::io::Result<OnDiskKeyIDManager> {
181+
fn new(mappings_dir_path: PathBuf) -> std::io::Result<OnDiskKeyInfoManager> {
182182
let mut key_store = HashMap::new();
183183

184184
// Will ignore if the mappings directory already exists.
@@ -217,7 +217,7 @@ impl OnDiskKeyIDManager {
217217
}
218218
}
219219

220-
Ok(OnDiskKeyIDManager {
220+
Ok(OnDiskKeyInfoManager {
221221
key_store,
222222
mappings_dir_path,
223223
})
@@ -262,7 +262,7 @@ impl OnDiskKeyIDManager {
262262
}
263263
}
264264

265-
impl ManageKeyIDs for OnDiskKeyIDManager {
265+
impl ManageKeyInfo for OnDiskKeyInfoManager {
266266
fn get(&self, key_triple: &KeyTriple) -> Result<Option<&KeyInfo>, String> {
267267
// An Option<&Vec<u8>> can not automatically coerce to an Option<&[u8]>, it needs to be
268268
// done by hand.
@@ -309,25 +309,25 @@ impl ManageKeyIDs for OnDiskKeyIDManager {
309309
}
310310

311311
#[derive(Debug, Default)]
312-
pub struct OnDiskKeyIDManagerBuilder {
312+
pub struct OnDiskKeyInfoManagerBuilder {
313313
mappings_dir_path: Option<PathBuf>,
314314
}
315315

316-
impl OnDiskKeyIDManagerBuilder {
317-
pub fn new() -> OnDiskKeyIDManagerBuilder {
318-
OnDiskKeyIDManagerBuilder {
316+
impl OnDiskKeyInfoManagerBuilder {
317+
pub fn new() -> OnDiskKeyInfoManagerBuilder {
318+
OnDiskKeyInfoManagerBuilder {
319319
mappings_dir_path: None,
320320
}
321321
}
322322

323-
pub fn with_mappings_dir_path(mut self, path: PathBuf) -> OnDiskKeyIDManagerBuilder {
323+
pub fn with_mappings_dir_path(mut self, path: PathBuf) -> OnDiskKeyInfoManagerBuilder {
324324
self.mappings_dir_path = Some(path);
325325

326326
self
327327
}
328328

329-
pub fn build(self) -> std::io::Result<OnDiskKeyIDManager> {
330-
OnDiskKeyIDManager::new(self.mappings_dir_path.ok_or_else(|| {
329+
pub fn build(self) -> std::io::Result<OnDiskKeyInfoManager> {
330+
OnDiskKeyInfoManager::new(self.mappings_dir_path.ok_or_else(|| {
331331
error!("Mappings directory path is missing");
332332
Error::new(ErrorKind::InvalidData, "mappings directory path is missing")
333333
})?)
@@ -336,8 +336,8 @@ impl OnDiskKeyIDManagerBuilder {
336336

337337
#[cfg(test)]
338338
mod test {
339-
use super::super::{KeyInfo, KeyTriple, ManageKeyIDs};
340-
use super::OnDiskKeyIDManager;
339+
use super::super::{KeyInfo, KeyTriple, ManageKeyInfo};
340+
use super::OnDiskKeyInfoManager;
341341
use crate::authenticators::ApplicationName;
342342
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash};
343343
use parsec_interface::operations::psa_key_attributes::{
@@ -381,11 +381,11 @@ mod test {
381381
}
382382

383383
#[test]
384-
fn insert_get_key_id() {
385-
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/insert_get_key_id_mappings");
386-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
384+
fn insert_get_key_info() {
385+
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/insert_get_key_info_mappings");
386+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
387387

388-
let key_triple = new_key_triple("insert_get_key_id".to_string());
388+
let key_triple = new_key_triple("insert_get_key_info".to_string());
389389
let key_info = test_key_info();
390390

391391
assert!(manager.get(&key_triple).unwrap().is_none());
@@ -409,7 +409,7 @@ mod test {
409409
#[test]
410410
fn insert_remove_key() {
411411
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/insert_remove_key_mappings");
412-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
412+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
413413

414414
let key_triple = new_key_triple("insert_remove_key".to_string());
415415
let key_info = test_key_info();
@@ -423,7 +423,7 @@ mod test {
423423
#[test]
424424
fn remove_unexisting_key() {
425425
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/remove_unexisting_key_mappings");
426-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
426+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
427427

428428
let key_triple = new_key_triple("remove_unexisting_key".to_string());
429429
assert_eq!(manager.remove(&key_triple).unwrap(), None);
@@ -433,7 +433,7 @@ mod test {
433433
#[test]
434434
fn exists() {
435435
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/exists_mappings");
436-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
436+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
437437

438438
let key_triple = new_key_triple("exists".to_string());
439439
let key_info = test_key_info();
@@ -451,7 +451,7 @@ mod test {
451451
#[test]
452452
fn insert_overwrites() {
453453
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/insert_overwrites_mappings");
454-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
454+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
455455

456456
let key_triple = new_key_triple("insert_overwrites".to_string());
457457
let key_info_1 = test_key_info();
@@ -479,7 +479,7 @@ mod test {
479479
#[test]
480480
fn big_names_ascii() {
481481
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/big_names_ascii_mappings");
482-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
482+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
483483

484484
let big_app_name_ascii = ApplicationName::new(" Lorem ipsum dolor sit amet, ei suas viris sea, deleniti repudiare te qui. Natum paulo decore ut nec, ne propriae offendit adipisci has. Eius clita legere mel at, ei vis minimum tincidunt.".to_string());
485485
let big_key_name_ascii = " Lorem ipsum dolor sit amet, ei suas viris sea, deleniti repudiare te qui. Natum paulo decore ut nec, ne propriae offendit adipisci has. Eius clita legere mel at, ei vis minimum tincidunt.".to_string();
@@ -497,7 +497,7 @@ mod test {
497497
#[test]
498498
fn big_names_emoticons() {
499499
let path = PathBuf::from(env!("OUT_DIR").to_owned() + "/big_names_emoticons_mappings");
500-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
500+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
501501

502502
let big_app_name_emoticons = ApplicationName::new("๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ".to_string());
503503
let big_key_name_emoticons = "๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ".to_string();
@@ -541,7 +541,7 @@ mod test {
541541
attributes: test_key_attributes(),
542542
};
543543
{
544-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
544+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
545545

546546
let _ = manager
547547
.insert(key_triple1.clone(), key_info1.clone())
@@ -555,7 +555,7 @@ mod test {
555555
}
556556
// The local hashmap is dropped when leaving the inner scope.
557557
{
558-
let mut manager = OnDiskKeyIDManager::new(path.clone()).unwrap();
558+
let mut manager = OnDiskKeyInfoManager::new(path.clone()).unwrap();
559559

560560
assert_eq!(manager.remove(&key_triple1).unwrap().unwrap(), key_info1);
561561
assert_eq!(manager.remove(&key_triple2).unwrap().unwrap(), key_info2);

0 commit comments

Comments
ย (0)