test/jdk/sun/security/pkcs11/Cipher/TestKATForGCM.java
changeset 58420 35cbd86e088a
parent 57563 2116221e2dde
child 58679 9c3209ff7550
equal deleted inserted replaced
58411:cece74021580 58420:35cbd86e088a
    28  * @modules jdk.crypto.cryptoki
    28  * @modules jdk.crypto.cryptoki
    29  * @run main TestKATForGCM
    29  * @run main TestKATForGCM
    30  * @summary Known Answer Test for AES cipher with GCM mode support in
    30  * @summary Known Answer Test for AES cipher with GCM mode support in
    31  * PKCS11 provider.
    31  * PKCS11 provider.
    32  */
    32  */
    33 import java.security.*;
    33 import java.security.GeneralSecurityException;
    34 import javax.crypto.*;
    34 import java.security.Provider;
    35 import javax.crypto.spec.*;
    35 import java.util.Arrays;
    36 import java.math.*;
    36 import javax.crypto.Cipher;
    37 
    37 import javax.crypto.SecretKey;
    38 import java.util.*;
    38 import javax.crypto.spec.GCMParameterSpec;
       
    39 import javax.crypto.spec.SecretKeySpec;
    39 
    40 
    40 public class TestKATForGCM extends PKCS11Test {
    41 public class TestKATForGCM extends PKCS11Test {
    41 
    42 
    42     // Utility methods
    43     // Utility methods
    43     private static byte[] HexToBytes(String hexVal) {
    44     private static byte[] HexToBytes(String hexVal) {
   317         try {
   318         try {
   318             if (execute(testValues, c)) {
   319             if (execute(testValues, c)) {
   319                 System.out.println("Test Passed!");
   320                 System.out.println("Test Passed!");
   320             }
   321             }
   321         } catch (Exception e) {
   322         } catch (Exception e) {
   322             double ver = getNSSInfo("nss");
   323             System.out.println("Exception occured using " + p.getName() + " version " + p.getVersionStr());
   323             if (ver < 3.251d && p.getName().contains("SunPKCS11-NSS") &&
   324 
   324                 System.getProperty("os.name").equals("SunOS")) {
   325             if (isNSS(p)) {
   325                 // buggy behaviour from solaris on 11.2 OS (nss < 3.251)
   326                 double ver = getNSSInfo("nss");
   326                 System.out.println("Skipping: SunPKCS11-NSS: Old NSS: " + ver);
   327                 String osName = System.getProperty("os.name");
   327                 return; // OK
   328                 if (ver < 3.251d && osName.equals("SunOS")) {
   328             } else {
   329                     // buggy behaviour from solaris on 11.2 OS (nss < 3.251)
   329                 throw e;
   330                     System.out.println("Skipping: SunPKCS11-NSS: Old NSS: " + ver);
       
   331                     return; // OK
       
   332                 } else if (ver > 3.139 && ver < 3.15 && osName.equals("Linux")) {
       
   333                     // warn about buggy behaviour on Linux with nss 3.14
       
   334                     System.out.println("Warning: old NSS " + ver + " might be problematic, consider upgrading it");
       
   335                 }
   330             }
   336             }
       
   337             throw e;
   331         }
   338         }
   332     }
   339     }
   333 }
   340 }
   334 
   341