1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 import java.io.*;
25 import java.net.*;
26 import java.util.*;
27 import java.security.*;
28 import javax.net.*;
29 import javax.net.ssl.*;
30 import java.lang.reflect.*;
31
32 public class ClientAuth extends PKCS11Test {
33
34 /*
35 * =============================================================
36 * Set the various variables needed for the tests, then
37 * specify what tests to run on each side.
38 */
39
40 private static Provider provider;
41 private static final String NSS_PWD = "test12";
42 private static final String JKS_PWD = "passphrase";
43 private static final String SERVER_KS = "server.keystore";
44 private static final String TS = "truststore";
45 private static String p11config;
46
47 private static String DIR = System.getProperty("DIR");
48
49 /*
50 * Should we run the client or server in a separate thread?
206 public void main(Provider p) throws Exception {
207 // SSL RSA client auth currently needs an RSA cipher
208 // (cf. NONEwithRSA hack), which is currently not available in
209 // open builds.
210 try {
211 javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
212 } catch (GeneralSecurityException e) {
213 System.out.println("Not supported by provider, skipping");
214 return;
215 }
216
217 this.provider = p;
218
219 System.setProperty("javax.net.ssl.trustStore",
220 new File(DIR, TS).toString());
221 System.setProperty("javax.net.ssl.trustStoreType", "JKS");
222 System.setProperty("javax.net.ssl.trustStoreProvider", "SUN");
223 System.setProperty("javax.net.ssl.trustStorePassword", JKS_PWD);
224
225 // perform Security.addProvider of P11 provider
226 ProviderLoader.go(System.getProperty("CUSTOM_P11_CONFIG"));
227
228 if (debug) {
229 System.setProperty("javax.net.debug", "all");
230 }
231
232 /*
233 * Start the tests.
234 */
235 go();
236 }
237
238 Thread clientThread = null;
239 Thread serverThread = null;
240
241 /*
242 * Fork off the other side, then do your work.
243 */
244 private void go() throws Exception {
245 try {
246 if (separateServerThread) {
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 import java.io.*;
25 import java.net.*;
26 import java.util.*;
27 import java.security.*;
28 import javax.net.*;
29 import javax.net.ssl.*;
30
31 public class ClientAuth extends PKCS11Test {
32
33 /*
34 * =============================================================
35 * Set the various variables needed for the tests, then
36 * specify what tests to run on each side.
37 */
38
39 private static Provider provider;
40 private static final String NSS_PWD = "test12";
41 private static final String JKS_PWD = "passphrase";
42 private static final String SERVER_KS = "server.keystore";
43 private static final String TS = "truststore";
44 private static String p11config;
45
46 private static String DIR = System.getProperty("DIR");
47
48 /*
49 * Should we run the client or server in a separate thread?
205 public void main(Provider p) throws Exception {
206 // SSL RSA client auth currently needs an RSA cipher
207 // (cf. NONEwithRSA hack), which is currently not available in
208 // open builds.
209 try {
210 javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
211 } catch (GeneralSecurityException e) {
212 System.out.println("Not supported by provider, skipping");
213 return;
214 }
215
216 this.provider = p;
217
218 System.setProperty("javax.net.ssl.trustStore",
219 new File(DIR, TS).toString());
220 System.setProperty("javax.net.ssl.trustStoreType", "JKS");
221 System.setProperty("javax.net.ssl.trustStoreProvider", "SUN");
222 System.setProperty("javax.net.ssl.trustStorePassword", JKS_PWD);
223
224 // perform Security.addProvider of P11 provider
225 Provider p2 = p.configure(System.getProperty("CUSTOM_P11_CONFIG"));
226 if (p2 != null) {
227 Security.addProvider(p2);
228 } else {
229 throw new Exception("Error: PKCS11 provider configuration failed");
230 }
231
232 if (debug) {
233 System.setProperty("javax.net.debug", "all");
234 }
235
236 /*
237 * Start the tests.
238 */
239 go();
240 }
241
242 Thread clientThread = null;
243 Thread serverThread = null;
244
245 /*
246 * Fork off the other side, then do your work.
247 */
248 private void go() throws Exception {
249 try {
250 if (separateServerThread) {
|