@@ -74,3 +74,56 @@ fn list_providers() {
7474 ]
7575 ) ;
7676}
77+
78+ #[ cfg( feature = "pkcs11-provider" ) ]
79+ #[ test]
80+ fn pkcs11_verify_software ( ) {
81+ use sha2:: { Digest , Sha256 } ;
82+ set_config ( "pkcs11_software.toml" ) ;
83+ reload_service ( ) ;
84+
85+ let mut client = TestClient :: new ( ) ;
86+ let key_name = String :: from ( "pkcs11_verify_software" ) ;
87+
88+ let mut hasher = Sha256 :: new ( ) ;
89+ hasher. update ( b"Bob wrote this message." ) ;
90+ let hash = hasher. finalize ( ) . to_vec ( ) ;
91+
92+ client. generate_rsa_sign_key ( key_name. clone ( ) ) . unwrap ( ) ;
93+
94+ let signature = client
95+ . sign_with_rsa_sha256 ( key_name. clone ( ) , hash. clone ( ) )
96+ . unwrap ( ) ;
97+ client
98+ . verify_with_rsa_sha256 ( key_name, hash, signature)
99+ . unwrap ( ) ;
100+ }
101+
102+ #[ cfg( feature = "pkcs11-provider" ) ]
103+ #[ test]
104+ fn pkcs11_encrypt_software ( ) {
105+ set_config ( "pkcs11_software.toml" ) ;
106+ reload_service ( ) ;
107+
108+ let mut client = TestClient :: new ( ) ;
109+ let key_name = String :: from ( "pkcs11_verify_software" ) ;
110+ let plaintext_msg = [
111+ 0x69 , 0x3E , 0xDB , 0x1B , 0x22 , 0x79 , 0x03 , 0xF4 , 0xC0 , 0xBF , 0xD6 , 0x91 , 0x76 , 0x37 , 0x84 ,
112+ 0xA2 , 0x94 , 0x8E , 0x92 , 0x50 , 0x35 , 0xC2 , 0x8C , 0x5C , 0x3C , 0xCA , 0xFE , 0x18 , 0xE8 , 0x81 ,
113+ 0x37 , 0x78 ,
114+ ] ;
115+ client
116+ . generate_rsa_encryption_keys_rsaoaep_sha1 ( key_name. clone ( ) )
117+ . unwrap ( ) ;
118+ let ciphertext = client
119+ . asymmetric_encrypt_message_with_rsaoaep_sha1 (
120+ key_name. clone ( ) ,
121+ plaintext_msg. to_vec ( ) ,
122+ vec ! [ ] ,
123+ )
124+ . unwrap ( ) ;
125+ let plaintext = client
126+ . asymmetric_decrypt_message_with_rsaoaep_sha1 ( key_name, ciphertext, vec ! [ ] )
127+ . unwrap ( ) ;
128+ assert_eq ! ( & plaintext_msg[ ..] , & plaintext[ ..] ) ;
129+ }
0 commit comments