@@ -4,7 +4,7 @@ use super::{utils, KeyPairType, Pkcs11Provider, ReadWriteSession, Session};
4
4
use crate :: authenticators:: ApplicationName ;
5
5
use crate :: key_info_managers:: KeyTriple ;
6
6
use log:: { error, info, trace} ;
7
- use parsec_interface:: operations:: psa_key_attributes:: Type ;
7
+ use parsec_interface:: operations:: psa_key_attributes:: { Id , Lifetime , Type } ;
8
8
use parsec_interface:: operations:: {
9
9
psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key,
10
10
} ;
@@ -62,6 +62,42 @@ impl Pkcs11Provider {
62
62
}
63
63
}
64
64
}
65
+
66
+ pub ( super ) fn move_pub_key_to_psa_crypto ( & self , key_triple : & KeyTriple ) -> Result < Id > {
67
+ info ! ( "Attempting to export public key" ) ;
68
+ let export_operation = psa_export_public_key:: Operation {
69
+ key_name : key_triple. key_name ( ) . to_owned ( ) ,
70
+ } ;
71
+ let psa_export_public_key:: Result { data } =
72
+ self . psa_export_public_key_internal ( key_triple. app_name ( ) . clone ( ) , export_operation) ?;
73
+
74
+ info ! ( "Importing public key into PSA Crypto" ) ;
75
+ let ( _, mut attributes) = self . get_key_info ( key_triple) ?;
76
+ attributes. lifetime = Lifetime :: Volatile ;
77
+ attributes. key_type = match attributes. key_type {
78
+ Type :: RsaKeyPair | Type :: RsaPublicKey => Type :: RsaPublicKey ,
79
+ Type :: EccKeyPair { curve_family } | Type :: EccPublicKey { curve_family } => {
80
+ Type :: EccPublicKey { curve_family }
81
+ }
82
+ Type :: DhKeyPair { group_family } | Type :: DhPublicKey { group_family } => {
83
+ Type :: DhPublicKey { group_family }
84
+ }
85
+ _ => return Err ( ResponseStatus :: PsaErrorInvalidArgument ) ,
86
+ } ;
87
+ let id = psa_crypto:: operations:: key_management:: import ( attributes, None , & data) ?;
88
+
89
+ Ok ( id)
90
+ }
91
+
92
+ pub ( super ) fn remove_psa_crypto_pub_key ( & self , pub_key_id : Id ) -> Result < ( ) > {
93
+ info ! ( "Removing public key stored in PSA." ) ;
94
+ unsafe { psa_crypto:: operations:: key_management:: destroy ( pub_key_id) } . map_err ( |e| {
95
+ error ! ( "Failed to remove public key from PSA Crypto." ) ;
96
+ e
97
+ } ) ?;
98
+ Ok ( ( ) )
99
+ }
100
+
65
101
pub ( super ) fn psa_generate_key_internal (
66
102
& self ,
67
103
app_name : ApplicationName ,
0 commit comments