1 /* |
1 /* |
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
25 * @test |
25 * @test |
26 * @bug 4856966 |
26 * @bug 4856966 |
27 * @summary Test KeyFactory of the new RSA provider |
27 * @summary Test KeyFactory of the new RSA provider |
28 * @author Andreas Sterbenz |
28 * @author Andreas Sterbenz |
29 * @library .. |
29 * @library .. |
|
30 * @run main/othervm TestKeyFactory |
|
31 * @run main/othervm TestKeyFactory sm rsakeys.ks.policy |
30 */ |
32 */ |
31 |
33 |
32 import java.io.*; |
34 import java.io.*; |
33 import java.util.*; |
35 import java.util.*; |
34 |
36 |
35 import java.security.*; |
37 import java.security.*; |
36 import java.security.interfaces.*; |
|
37 import java.security.spec.*; |
38 import java.security.spec.*; |
38 |
39 |
39 public class TestKeyFactory extends PKCS11Test { |
40 public class TestKeyFactory extends PKCS11Test { |
40 |
41 |
41 private final static String BASE = System.getProperty("test.src", "."); |
|
42 |
|
43 private static final char[] password = "test12".toCharArray(); |
42 private static final char[] password = "test12".toCharArray(); |
44 |
43 |
45 static KeyStore getKeyStore() throws Exception { |
44 static KeyStore getKeyStore() throws Exception { |
46 InputStream in = new FileInputStream(new File(BASE, "rsakeys.ks")); |
45 KeyStore ks; |
47 KeyStore ks = KeyStore.getInstance("JKS"); |
46 try (InputStream in = new FileInputStream(new File(BASE, "rsakeys.ks"))) { |
48 ks.load(in, password); |
47 ks = KeyStore.getInstance("JKS"); |
49 in.close(); |
48 ks.load(in, password); |
|
49 } |
50 return ks; |
50 return ks; |
51 } |
51 } |
52 |
52 |
53 /** |
53 /** |
54 * Test that key1 (reference key) and key2 (key to be tested) are |
54 * Test that key1 (reference key) and key2 (key to be tested) are |
126 testPrivate(kf, (PrivateKey)key); |
126 testPrivate(kf, (PrivateKey)key); |
127 } |
127 } |
128 } |
128 } |
129 |
129 |
130 public static void main(String[] args) throws Exception { |
130 public static void main(String[] args) throws Exception { |
131 main(new TestKeyFactory()); |
131 main(new TestKeyFactory(), args); |
132 } |
132 } |
133 |
133 |
|
134 @Override |
134 public void main(Provider p) throws Exception { |
135 public void main(Provider p) throws Exception { |
135 long start = System.currentTimeMillis(); |
136 long start = System.currentTimeMillis(); |
136 KeyStore ks = getKeyStore(); |
137 KeyStore ks = getKeyStore(); |
137 KeyFactory kf = KeyFactory.getInstance("RSA", p); |
138 KeyFactory kf = KeyFactory.getInstance("RSA", p); |
138 for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) { |
139 for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) { |