1
1
// Copyright 2019 Contributors to the Parsec project.
2
2
// 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
4
4
//!
5
5
//! The path where the mappings should be stored is configurable. Because of possible data races,
6
6
//! there should not be two instances of this manager pointing to the same mapping folder at a time.
12
12
//! example, for operating systems having a limit of 255 characters for filenames (Unix systems),
13
13
//! names will be limited to 188 bytes of UTF-8 characters.
14
14
//! 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 } ;
16
16
use crate :: authenticators:: ApplicationName ;
17
17
use log:: { error, info} ;
18
18
use parsec_interface:: requests:: ProviderID ;
@@ -27,7 +27,7 @@ use std::path::PathBuf;
27
27
pub const DEFAULT_MAPPINGS_PATH : & str = "./mappings" ;
28
28
29
29
#[ derive( Debug ) ]
30
- pub struct OnDiskKeyIDManager {
30
+ pub struct OnDiskKeyInfoManager {
31
31
/// Internal mapping, used for non-modifying operations.
32
32
key_store : HashMap < KeyTriple , KeyInfo > ,
33
33
/// 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>> {
145
145
. collect ( ) )
146
146
}
147
147
148
- /// Filesystem-based `KeyIdManager `
148
+ /// Filesystem-based `KeyInfoManager `
149
149
///
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
151
151
/// the filesystem to ensure security of the mappings.
152
- impl OnDiskKeyIDManager {
152
+ impl OnDiskKeyInfoManager {
153
153
/// Creates an instance of the on-disk manager from the mapping files. This function will
154
154
/// create the mappings directory if it does not already exist.
155
155
/// The mappings folder is composed of three levels: two levels of directory and one level
@@ -178,7 +178,7 @@ impl OnDiskKeyIDManager {
178
178
/// # Errors
179
179
///
180
180
/// 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 > {
182
182
let mut key_store = HashMap :: new ( ) ;
183
183
184
184
// Will ignore if the mappings directory already exists.
@@ -217,7 +217,7 @@ impl OnDiskKeyIDManager {
217
217
}
218
218
}
219
219
220
- Ok ( OnDiskKeyIDManager {
220
+ Ok ( OnDiskKeyInfoManager {
221
221
key_store,
222
222
mappings_dir_path,
223
223
} )
@@ -262,7 +262,7 @@ impl OnDiskKeyIDManager {
262
262
}
263
263
}
264
264
265
- impl ManageKeyIDs for OnDiskKeyIDManager {
265
+ impl ManageKeyInfo for OnDiskKeyInfoManager {
266
266
fn get ( & self , key_triple : & KeyTriple ) -> Result < Option < & KeyInfo > , String > {
267
267
// An Option<&Vec<u8>> can not automatically coerce to an Option<&[u8]>, it needs to be
268
268
// done by hand.
@@ -309,25 +309,25 @@ impl ManageKeyIDs for OnDiskKeyIDManager {
309
309
}
310
310
311
311
#[ derive( Debug , Default ) ]
312
- pub struct OnDiskKeyIDManagerBuilder {
312
+ pub struct OnDiskKeyInfoManagerBuilder {
313
313
mappings_dir_path : Option < PathBuf > ,
314
314
}
315
315
316
- impl OnDiskKeyIDManagerBuilder {
317
- pub fn new ( ) -> OnDiskKeyIDManagerBuilder {
318
- OnDiskKeyIDManagerBuilder {
316
+ impl OnDiskKeyInfoManagerBuilder {
317
+ pub fn new ( ) -> OnDiskKeyInfoManagerBuilder {
318
+ OnDiskKeyInfoManagerBuilder {
319
319
mappings_dir_path : None ,
320
320
}
321
321
}
322
322
323
- pub fn with_mappings_dir_path ( mut self , path : PathBuf ) -> OnDiskKeyIDManagerBuilder {
323
+ pub fn with_mappings_dir_path ( mut self , path : PathBuf ) -> OnDiskKeyInfoManagerBuilder {
324
324
self . mappings_dir_path = Some ( path) ;
325
325
326
326
self
327
327
}
328
328
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 ( || {
331
331
error ! ( "Mappings directory path is missing" ) ;
332
332
Error :: new ( ErrorKind :: InvalidData , "mappings directory path is missing" )
333
333
} ) ?)
@@ -336,8 +336,8 @@ impl OnDiskKeyIDManagerBuilder {
336
336
337
337
#[ cfg( test) ]
338
338
mod test {
339
- use super :: super :: { KeyInfo , KeyTriple , ManageKeyIDs } ;
340
- use super :: OnDiskKeyIDManager ;
339
+ use super :: super :: { KeyInfo , KeyTriple , ManageKeyInfo } ;
340
+ use super :: OnDiskKeyInfoManager ;
341
341
use crate :: authenticators:: ApplicationName ;
342
342
use parsec_interface:: operations:: psa_algorithm:: { Algorithm , AsymmetricSignature , Hash } ;
343
343
use parsec_interface:: operations:: psa_key_attributes:: {
@@ -381,11 +381,11 @@ mod test {
381
381
}
382
382
383
383
#[ 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 ( ) ;
387
387
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 ( ) ) ;
389
389
let key_info = test_key_info ( ) ;
390
390
391
391
assert ! ( manager. get( & key_triple) . unwrap( ) . is_none( ) ) ;
@@ -409,7 +409,7 @@ mod test {
409
409
#[ test]
410
410
fn insert_remove_key ( ) {
411
411
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 ( ) ;
413
413
414
414
let key_triple = new_key_triple ( "insert_remove_key" . to_string ( ) ) ;
415
415
let key_info = test_key_info ( ) ;
@@ -423,7 +423,7 @@ mod test {
423
423
#[ test]
424
424
fn remove_unexisting_key ( ) {
425
425
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 ( ) ;
427
427
428
428
let key_triple = new_key_triple ( "remove_unexisting_key" . to_string ( ) ) ;
429
429
assert_eq ! ( manager. remove( & key_triple) . unwrap( ) , None ) ;
@@ -433,7 +433,7 @@ mod test {
433
433
#[ test]
434
434
fn exists ( ) {
435
435
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 ( ) ;
437
437
438
438
let key_triple = new_key_triple ( "exists" . to_string ( ) ) ;
439
439
let key_info = test_key_info ( ) ;
@@ -451,7 +451,7 @@ mod test {
451
451
#[ test]
452
452
fn insert_overwrites ( ) {
453
453
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 ( ) ;
455
455
456
456
let key_triple = new_key_triple ( "insert_overwrites" . to_string ( ) ) ;
457
457
let key_info_1 = test_key_info ( ) ;
@@ -479,7 +479,7 @@ mod test {
479
479
#[ test]
480
480
fn big_names_ascii ( ) {
481
481
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 ( ) ;
483
483
484
484
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 ( ) ) ;
485
485
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 {
497
497
#[ test]
498
498
fn big_names_emoticons ( ) {
499
499
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 ( ) ;
501
501
502
502
let big_app_name_emoticons = ApplicationName :: new ( "๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ" . to_string ( ) ) ;
503
503
let big_key_name_emoticons = "๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ" . to_string ( ) ;
@@ -541,7 +541,7 @@ mod test {
541
541
attributes : test_key_attributes ( ) ,
542
542
} ;
543
543
{
544
- let mut manager = OnDiskKeyIDManager :: new ( path. clone ( ) ) . unwrap ( ) ;
544
+ let mut manager = OnDiskKeyInfoManager :: new ( path. clone ( ) ) . unwrap ( ) ;
545
545
546
546
let _ = manager
547
547
. insert ( key_triple1. clone ( ) , key_info1. clone ( ) )
@@ -555,7 +555,7 @@ mod test {
555
555
}
556
556
// The local hashmap is dropped when leaving the inner scope.
557
557
{
558
- let mut manager = OnDiskKeyIDManager :: new ( path. clone ( ) ) . unwrap ( ) ;
558
+ let mut manager = OnDiskKeyInfoManager :: new ( path. clone ( ) ) . unwrap ( ) ;
559
559
560
560
assert_eq ! ( manager. remove( & key_triple1) . unwrap( ) . unwrap( ) , key_info1) ;
561
561
assert_eq ! ( manager. remove( & key_triple2) . unwrap( ) . unwrap( ) , key_info2) ;
0 commit comments