5
5
//! This provider is backed by a crypto Trusted Service deployed in TrustZone
6
6
use super :: mbed_crypto:: key_management as mbed_crypto_key_management;
7
7
use crate :: authenticators:: ApplicationName ;
8
- use crate :: key_info_managers:: KeyTriple ;
9
- use crate :: key_info_managers:: ManageKeyInfo ;
8
+ use crate :: key_info_managers:: { self , KeyTriple , ManageKeyInfo } ;
10
9
use crate :: providers:: Provide ;
11
10
use context:: Context ;
12
11
use derivative:: Derivative ;
13
12
use log:: { error, trace} ;
14
13
use parsec_interface:: operations:: list_providers:: ProviderInfo ;
15
14
use parsec_interface:: operations:: {
16
- psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key, psa_sign_hash ,
17
- psa_verify_hash,
15
+ list_keys , psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key,
16
+ psa_sign_hash , psa_verify_hash,
18
17
} ;
19
- use parsec_interface:: requests:: { Opcode , ProviderID , Result } ;
18
+ use parsec_interface:: requests:: { Opcode , ProviderID , ResponseStatus , Result } ;
20
19
use psa_crypto:: types:: key;
21
20
use std:: collections:: HashSet ;
21
+ use std:: ops:: Deref ;
22
22
use std:: sync:: {
23
23
atomic:: { AtomicU32 , Ordering } ,
24
24
Arc , RwLock ,
@@ -29,13 +29,19 @@ mod asym_sign;
29
29
mod context;
30
30
mod key_management;
31
31
32
- const SUPPORTED_OPCODES : [ Opcode ; 2 ] = [ Opcode :: PsaDestroyKey , Opcode :: PsaGenerateKey ] ;
32
+ const SUPPORTED_OPCODES : [ Opcode ; 6 ] = [
33
+ Opcode :: PsaDestroyKey ,
34
+ Opcode :: PsaGenerateKey ,
35
+ Opcode :: PsaSignHash ,
36
+ Opcode :: PsaVerifyHash ,
37
+ Opcode :: PsaImportKey ,
38
+ Opcode :: PsaExportPublicKey ,
39
+ ] ;
33
40
34
41
/// Trusted Service provider structure
35
42
///
36
- /// Currently the provider only supports volatile keys due to limitations in the stack
37
- /// underneath us. Therefore none of the key information is persisted, being kept instead
38
- /// in a map for fast access.
43
+ /// Operations for this provider are serviced through an IPC interface that leads
44
+ /// to a Secure World implementation of PSA Crypto.
39
45
#[ derive( Derivative ) ]
40
46
#[ derivative( Debug ) ]
41
47
pub struct Provider {
@@ -53,7 +59,7 @@ pub struct Provider {
53
59
}
54
60
55
61
impl Provider {
56
- /// Creates and initialise a new instance of Provider.
62
+ /// Creates and initialises a new instance of Provider.
57
63
fn new (
58
64
key_info_store : Arc < RwLock < dyn ManageKeyInfo + Send + Sync > > ,
59
65
) -> anyhow:: Result < Provider > {
@@ -64,14 +70,14 @@ impl Provider {
64
70
} ;
65
71
let mut max_key_id: key:: psa_key_id_t = key:: PSA_KEY_ID_USER_MIN ;
66
72
{
67
- // The local scope allows to drop store_handle and local_ids_handle in order to return
73
+ // The local scope allows dropping store_handle and local_ids_handle in order to return
68
74
// the ts_provider.
69
75
let mut store_handle = ts_provider
70
76
. key_info_store
71
77
. write ( )
72
78
. expect ( "Key store lock poisoned" ) ;
73
79
let mut to_remove: Vec < KeyTriple > = Vec :: new ( ) ;
74
- // Go through all TrustedServiceProvider key triple to key info mappings and check if they are still
80
+ // Go through all TrustedServiceProvider key triples to key info mappings and check if they are still
75
81
// present.
76
82
// Delete those who are not present and add to the local_store the ones present.
77
83
match store_handle. get_all ( ProviderID :: TrustedService ) {
@@ -129,6 +135,25 @@ impl Provide for Provider {
129
135
} , SUPPORTED_OPCODES . iter ( ) . copied ( ) . collect ( ) ) )
130
136
}
131
137
138
+ fn list_keys (
139
+ & self ,
140
+ app_name : ApplicationName ,
141
+ _op : list_keys:: Operation ,
142
+ ) -> Result < list_keys:: Result > {
143
+ let store_handle = self . key_info_store . read ( ) . expect ( "Key store lock poisoned" ) ;
144
+ Ok ( list_keys:: Result {
145
+ keys : key_info_managers:: list_keys (
146
+ store_handle. deref ( ) ,
147
+ & app_name,
148
+ ProviderID :: TrustedService ,
149
+ )
150
+ . map_err ( |e| {
151
+ format_error ! ( "Error occurred when fetching key information" , e) ;
152
+ ResponseStatus :: KeyInfoManagerError
153
+ } ) ?,
154
+ } )
155
+ }
156
+
132
157
fn psa_generate_key (
133
158
& self ,
134
159
app_name : ApplicationName ,
0 commit comments