21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8029659 |
26 * @bug 8029659 8214179 |
27 * @summary Keytool, print key algorithm of certificate or key entry |
27 * @summary Keytool, print key algorithm of certificate or key entry |
28 * @library /test/lib |
28 * @library /test/lib |
29 */ |
29 */ |
30 |
30 |
31 import jdk.test.lib.SecurityTools; |
31 import jdk.test.lib.SecurityTools; |
32 import jdk.test.lib.process.OutputAnalyzer; |
32 import jdk.test.lib.process.OutputAnalyzer; |
33 |
33 |
34 public class KeyAlg { |
34 public class KeyAlg { |
35 public static void main(String[] args) throws Exception { |
35 public static void main(String[] args) throws Exception { |
36 keytool("-genkeypair -alias ca -dname CN=CA -keyalg EC") |
36 keytool("-genkeypair -alias ca -dname CN=CA -keyalg EC"); |
37 .shouldHaveExitValue(0); |
37 keytool("-genkeypair -alias user -dname CN=User -keyalg RSA -keysize 1024"); |
38 keytool("-genkeypair -alias user -dname CN=User -keyalg RSA -keysize 1024") |
38 keytool("-certreq -alias user -file user.req"); |
39 .shouldHaveExitValue(0); |
|
40 keytool("-certreq -alias user -file user.req").shouldHaveExitValue(0); |
|
41 keytool("-gencert -alias ca -rfc -sigalg SHA1withECDSA" |
39 keytool("-gencert -alias ca -rfc -sigalg SHA1withECDSA" |
42 + " -infile user.req -outfile user.crt") |
40 + " -infile user.req -outfile user.crt"); |
43 .shouldHaveExitValue(0); |
|
44 keytool("-printcert -file user.crt") |
41 keytool("-printcert -file user.crt") |
45 .shouldHaveExitValue(0) |
|
46 .shouldMatch("Signature algorithm name:.*SHA1withECDSA") |
42 .shouldMatch("Signature algorithm name:.*SHA1withECDSA") |
47 .shouldMatch("Subject Public Key Algorithm:.*1024.*RSA"); |
43 .shouldMatch("Subject Public Key Algorithm:.*1024.*RSA"); |
|
44 keytool("-genkeypair -alias e -dname CN=e -keyalg EC -groupname brainpoolP256r1") |
|
45 .shouldContain("Generating 256 bit EC (brainpoolP256r1) key pair"); |
|
46 keytool("-genkeypair -alias f -dname CN=f -keyalg EC") |
|
47 .shouldContain("Generating 256 bit EC (secp256r1) key pair"); |
|
48 keytool("-genkeypair -alias g -dname CN=g -keyalg EC -keysize 384") |
|
49 .shouldContain("Generating 384 bit EC (secp384r1) key pair"); |
48 } |
50 } |
49 |
51 |
50 static OutputAnalyzer keytool(String s) throws Exception { |
52 static OutputAnalyzer keytool(String s) throws Exception { |
51 return SecurityTools.keytool( |
53 return SecurityTools.keytool( |
52 "-keystore ks -storepass changeit -keypass changeit " + s); |
54 "-keystore ks -storepass changeit -keypass changeit " + s) |
|
55 .shouldHaveExitValue(0); |
53 } |
56 } |
54 } |
57 } |