22// SPDX-License-Identifier: Apache-2.0
33mod common;
44
5- use crate :: common:: { get_pkcs11, SO_PIN , USER_PIN } ;
5+ use crate :: common:: { get_pkcs11, is_softhsm , SO_PIN , USER_PIN } ;
66use common:: init_pins;
77use cryptoki:: context:: Function ;
88use cryptoki:: error:: { Error , RvError } ;
@@ -411,7 +411,11 @@ fn import_export() -> TestResult {
411411fn get_token_info ( ) -> TestResult {
412412 let ( pkcs11, slot) = init_pins ( ) ;
413413 let info = pkcs11. get_token_info ( slot) ?;
414- assert_eq ! ( "SoftHSM project" , info. manufacturer_id( ) ) ;
414+ if is_softhsm ( ) {
415+ assert_eq ! ( "SoftHSM project" , info. manufacturer_id( ) ) ;
416+ } else {
417+ assert_eq ! ( "Kryoptic Project" , info. manufacturer_id( ) ) ;
418+ }
415419
416420 Ok ( ( ) )
417421}
@@ -698,9 +702,15 @@ fn get_info_test() -> TestResult {
698702 let ( pkcs11, _) = init_pins ( ) ;
699703 let info = pkcs11. get_library_info ( ) ?;
700704
701- assert_eq ! ( info. cryptoki_version( ) . major( ) , 2 ) ;
702- assert_eq ! ( info. cryptoki_version( ) . minor( ) , 40 ) ;
703- assert_eq ! ( info. manufacturer_id( ) , String :: from( "SoftHSM" ) ) ;
705+ if is_softhsm ( ) {
706+ assert_eq ! ( info. cryptoki_version( ) . major( ) , 2 ) ;
707+ assert_eq ! ( info. cryptoki_version( ) . minor( ) , 40 ) ;
708+ assert_eq ! ( info. manufacturer_id( ) , String :: from( "SoftHSM" ) ) ;
709+ } else {
710+ assert_eq ! ( info. cryptoki_version( ) . major( ) , 3 ) ;
711+ assert_eq ! ( info. cryptoki_version( ) . minor( ) , 0 ) ;
712+ assert_eq ! ( info. manufacturer_id( ) , String :: from( "Kryoptic" ) ) ;
713+ }
704714 Ok ( ( ) )
705715}
706716
@@ -712,7 +722,12 @@ fn get_slot_info_test() -> TestResult {
712722 assert ! ( slot_info. token_present( ) ) ;
713723 assert ! ( !slot_info. hardware_slot( ) ) ;
714724 assert ! ( !slot_info. removable_device( ) ) ;
715- assert_eq ! ( slot_info. manufacturer_id( ) , String :: from( "SoftHSM project" ) ) ;
725+ let manufacturer = if is_softhsm ( ) {
726+ String :: from ( "SoftHSM project" )
727+ } else {
728+ String :: from ( "Kryoptic" )
729+ } ;
730+ assert_eq ! ( slot_info. manufacturer_id( ) , manufacturer) ;
716731 Ok ( ( ) )
717732}
718733
@@ -1273,9 +1288,13 @@ fn sha256_digest() -> TestResult {
12731288
12741289#[ test]
12751290#[ serial]
1276- // Currently empty AAD crashes SoftHSM, see: https://github.com/opendnssec/SoftHSMv2/issues/605
1277- #[ ignore]
12781291fn aes_gcm_no_aad ( ) -> TestResult {
1292+ // Currently empty AAD crashes SoftHSM, see: https://github.com/opendnssec/SoftHSMv2/issues/605
1293+ if is_softhsm ( ) {
1294+ /* return Ignore(); */
1295+ return Ok ( ( ) ) ;
1296+ }
1297+
12791298 // Encrypt two blocks of zeros with AES-128-GCM
12801299 let key = vec ! [ 0 ; 16 ] ;
12811300 let mut iv = [ 0 ; 12 ] ;
@@ -1370,8 +1389,13 @@ fn rsa_pkcs_oaep_empty() -> TestResult {
13701389
13711390#[ test]
13721391#[ serial]
1373- #[ ignore] // it's not clear why the test with data specified fails
13741392fn rsa_pkcs_oaep_with_data ( ) -> TestResult {
1393+ /* SoftHSM does not support additional OAEP Source */
1394+ if is_softhsm ( ) {
1395+ /* return Ignore(); */
1396+ return Ok ( ( ) ) ;
1397+ }
1398+
13751399 let ( pkcs11, slot) = init_pins ( ) ;
13761400 let session = pkcs11. open_rw_session ( slot) ?;
13771401 session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
@@ -1404,11 +1428,16 @@ fn rsa_pkcs_oaep_with_data() -> TestResult {
14041428#[ test]
14051429#[ serial]
14061430fn get_slot_event ( ) -> TestResult {
1407- // Not implemented in SoftHSMv2
1408- // https://github.com/opendnssec/SoftHSMv2/issues/370
14091431 let ( pkcs11, _slot) = init_pins ( ) ;
1410- let event = pkcs11. get_slot_event ( ) ?;
1411- assert_eq ! ( None , event) ;
1432+ if is_softhsm ( ) {
1433+ // Not implemented in SoftHSMv2
1434+ // https://github.com/opendnssec/SoftHSMv2/issues/370
1435+ let event = pkcs11. get_slot_event ( ) ?;
1436+ assert_eq ! ( None , event) ;
1437+ } else {
1438+ // Not implemented in Kryoptic
1439+ pkcs11. get_slot_event ( ) . unwrap_err ( ) ;
1440+ }
14121441 Ok ( ( ) )
14131442}
14141443
0 commit comments