< prev index next >

test/jdk/sun/security/tools/keytool/KeyToolTest.java

Print this page
rev 59383 : [mq]: final


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6251120 8231950 8242151
  27  * @summary Testing keytool
  28  *
  29  * Run through autotest.sh and manualtest.sh
  30  *
  31  * Testing non-PKCS11 keystores:
  32  *       echo | java -Dfile KeyToolTest
  33  *
  34  * Testing NSS PKCS11 keystores:
  35  *       # testing NSS
  36  *       # make sure the NSS db files are in current directory and writable
  37  *       echo | java -Dnss -Dnss.lib=/path/to/libsoftokn3.so KeyToolTest
  38  *
  39  * Testing Solaris Cryptography Framework PKCS11 keystores:
  40  *       # make sure you've already run pktool and set test12 as pin
  41  *       echo | java -Dsolaris KeyToolTest
  42  *
  43  * ATTENTION:
  44  * Exception in thread "main" java.security.ProviderException:
  45  *   sun.security.pkcs11.wrapper.PKCS11Exception: CKR_KEY_SIZE_RANGE
  46  *       at sun.security.pkcs11.P11Signature.engineSign(P11Signature.java:420)
  47  *       ...
  48  * Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_KEY_SIZE_RANGE
  49  *       at sun.security.pkcs11.wrapper.PKCS11.C_SignFinal(Native Method)
  50  *       at sun.security.pkcs11.P11Signature.engineSign(P11Signature.java:391)
  51  *       ...
  52  * been observed. Possibly a Solaris bug
  53  *
  54  * ATTENTION:
  55  * NSS PKCS11 config file are changed, DSA not supported now.
  56  *
  57  * @library /test/lib
  58  * @modules java.base/sun.security.tools.keytool
  59  *          java.base/sun.security.util
  60  *          java.base/sun.security.x509
  61  * @run main/othervm/timeout=600 -Dfile KeyToolTest
  62  */


  89 
  90     static final String NSS_P11_ARG =
  91             "-keystore NONE -storetype PKCS11 -providerName SunPKCS11-nss " +
  92             "-addprovider SunPKCS11 " +
  93             "-providerArg p11-nss.txt ";
  94     // Use -providerClass here, to confirm it still works for SunPKCS11.
  95     static final String NSS_SRC_P11_ARG =
  96             "-srckeystore NONE -srcstoretype PKCS11 " +
  97             "-srcproviderName SunPKCS11-nss " +
  98             "-providerClass sun.security.pkcs11.SunPKCS11 " +
  99             "-providerArg p11-nss.txt ";
 100     static final String NZZ_P11_ARG =
 101             "-keystore NONE -storetype PKCS11 -providerName SunPKCS11-nzz " +
 102             "-addprovider SunPKCS11 " +
 103             "-providerArg p11-nzz.txt ";
 104     static final String NZZ_SRC_P11_ARG =
 105             "-srckeystore NONE -srcstoretype PKCS11 " +
 106             "-srcproviderName SunPKCS11-nzz " +
 107             "-addprovider SunPKCS11 " +
 108             "-providerArg p11-nzz.txt ";
 109     static final String SUN_P11_ARG = "-keystore NONE -storetype PKCS11 ";
 110     static final String SUN_SRC_P11_ARG =
 111             "-srckeystore NONE -srcstoretype PKCS11 ";
 112 
 113     String p11Arg, srcP11Arg;
 114 
 115     /** Creates a new instance of KeyToolTest */
 116     KeyToolTest() {
 117         // so that there is "Warning" and not translated into other language
 118         Locale.setDefault(Locale.US);
 119     }
 120 
 121     /**
 122      * Helper, removes a file
 123      */
 124     void remove(String filename) {
 125         if (debug) {
 126             System.err.println("Removing " + filename);
 127         }
 128         try{
 129             FileUtils.deleteFileIfExistsWithRetry(Paths.get(filename));
 130         }catch(IOException e) {
 131             throw new RuntimeException("Error deleting " + filename, e);


1841                 if (testEC) t.v3extTest("EC");
1842             }
1843 
1844             if (System.getProperty("nss") != null) {
1845                 t.srcP11Arg = NSS_SRC_P11_ARG;
1846                 t.p11Arg = NSS_P11_ARG;
1847 
1848                 t.testPKCS11();
1849 
1850                 // FAIL:
1851                 // 1. we still don't have srcprovidername yet
1852                 // 2. cannot store privatekey into NSS keystore
1853                 //    java.security.KeyStoreException: sun.security.pkcs11
1854                 //      .wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE.
1855                 //t.testPKCS11ImportKeyStore();
1856 
1857                 t.i18nPKCS11Test();
1858                 //FAIL: currently PKCS11-NSS does not support
1859                 // 2 NSS KeyStores to be loaded at the same time
1860                 //t.sszzTest();
1861             }
1862 
1863             if (System.getProperty("solaris") != null) {
1864                 // For Solaris Cryptography Framework
1865                 t.srcP11Arg = SUN_SRC_P11_ARG;
1866                 t.p11Arg = SUN_P11_ARG;
1867                 t.testPKCS11();
1868                 t.testPKCS11ImportKeyStore();
1869                 t.i18nPKCS11Test();
1870             }
1871 
1872             System.out.println("Test pass!!!");
1873         } finally {
1874             // restore the reserved locale
1875             Locale.setDefault(reservedLocale);
1876         }
1877     }
1878 }
1879 
1880 class TestException extends Exception {
1881     public TestException(String e) {
1882         super(e);
1883     }
1884 }
1885 
1886 /**
1887  * HumanInputStream tries to act like a human sitting in front of a computer
1888  * terminal typing on the keyboard while the keytool program is running.
1889  *




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6251120 8231950 8242151
  27  * @summary Testing keytool
  28  *
  29  * Run through autotest.sh and manualtest.sh
  30  *
  31  * Testing non-PKCS11 keystores:
  32  *       echo | java -Dfile KeyToolTest
  33  *
  34  * Testing NSS PKCS11 keystores:
  35  *       # testing NSS
  36  *       # make sure the NSS db files are in current directory and writable
  37  *       echo | java -Dnss -Dnss.lib=/path/to/libsoftokn3.so KeyToolTest
  38  *




  39  * ATTENTION:
  40  * Exception in thread "main" java.security.ProviderException:
  41  *   sun.security.pkcs11.wrapper.PKCS11Exception: CKR_KEY_SIZE_RANGE
  42  *       at sun.security.pkcs11.P11Signature.engineSign(P11Signature.java:420)
  43  *       ...
  44  * Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_KEY_SIZE_RANGE
  45  *       at sun.security.pkcs11.wrapper.PKCS11.C_SignFinal(Native Method)
  46  *       at sun.security.pkcs11.P11Signature.engineSign(P11Signature.java:391)
  47  *       ...
  48  * been observed. Possibly a Solaris bug
  49  *
  50  * ATTENTION:
  51  * NSS PKCS11 config file are changed, DSA not supported now.
  52  *
  53  * @library /test/lib
  54  * @modules java.base/sun.security.tools.keytool
  55  *          java.base/sun.security.util
  56  *          java.base/sun.security.x509
  57  * @run main/othervm/timeout=600 -Dfile KeyToolTest
  58  */


  85 
  86     static final String NSS_P11_ARG =
  87             "-keystore NONE -storetype PKCS11 -providerName SunPKCS11-nss " +
  88             "-addprovider SunPKCS11 " +
  89             "-providerArg p11-nss.txt ";
  90     // Use -providerClass here, to confirm it still works for SunPKCS11.
  91     static final String NSS_SRC_P11_ARG =
  92             "-srckeystore NONE -srcstoretype PKCS11 " +
  93             "-srcproviderName SunPKCS11-nss " +
  94             "-providerClass sun.security.pkcs11.SunPKCS11 " +
  95             "-providerArg p11-nss.txt ";
  96     static final String NZZ_P11_ARG =
  97             "-keystore NONE -storetype PKCS11 -providerName SunPKCS11-nzz " +
  98             "-addprovider SunPKCS11 " +
  99             "-providerArg p11-nzz.txt ";
 100     static final String NZZ_SRC_P11_ARG =
 101             "-srckeystore NONE -srcstoretype PKCS11 " +
 102             "-srcproviderName SunPKCS11-nzz " +
 103             "-addprovider SunPKCS11 " +
 104             "-providerArg p11-nzz.txt ";



 105 
 106     String p11Arg, srcP11Arg;
 107 
 108     /** Creates a new instance of KeyToolTest */
 109     KeyToolTest() {
 110         // so that there is "Warning" and not translated into other language
 111         Locale.setDefault(Locale.US);
 112     }
 113 
 114     /**
 115      * Helper, removes a file
 116      */
 117     void remove(String filename) {
 118         if (debug) {
 119             System.err.println("Removing " + filename);
 120         }
 121         try{
 122             FileUtils.deleteFileIfExistsWithRetry(Paths.get(filename));
 123         }catch(IOException e) {
 124             throw new RuntimeException("Error deleting " + filename, e);


1834                 if (testEC) t.v3extTest("EC");
1835             }
1836 
1837             if (System.getProperty("nss") != null) {
1838                 t.srcP11Arg = NSS_SRC_P11_ARG;
1839                 t.p11Arg = NSS_P11_ARG;
1840 
1841                 t.testPKCS11();
1842 
1843                 // FAIL:
1844                 // 1. we still don't have srcprovidername yet
1845                 // 2. cannot store privatekey into NSS keystore
1846                 //    java.security.KeyStoreException: sun.security.pkcs11
1847                 //      .wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE.
1848                 //t.testPKCS11ImportKeyStore();
1849 
1850                 t.i18nPKCS11Test();
1851                 //FAIL: currently PKCS11-NSS does not support
1852                 // 2 NSS KeyStores to be loaded at the same time
1853                 //t.sszzTest();









1854             }
1855 
1856             System.out.println("Test pass!!!");
1857         } finally {
1858             // restore the reserved locale
1859             Locale.setDefault(reservedLocale);
1860         }
1861     }
1862 }
1863 
1864 class TestException extends Exception {
1865     public TestException(String e) {
1866         super(e);
1867     }
1868 }
1869 
1870 /**
1871  * HumanInputStream tries to act like a human sitting in front of a computer
1872  * terminal typing on the keyboard while the keytool program is running.
1873  *


< prev index next >