36 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1.2
37 * @run main/othervm DisabledShortRSAKeys PKIX TLSv1.1
38 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1.1
39 * @run main/othervm DisabledShortRSAKeys PKIX TLSv1
40 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1
41 * @run main/othervm DisabledShortRSAKeys PKIX SSLv3
42 * @run main/othervm DisabledShortRSAKeys SunX509 SSLv3
43 */
44
45 import java.net.*;
46 import java.util.*;
47 import java.io.*;
48 import javax.net.ssl.*;
49 import java.security.Security;
50 import java.security.KeyStore;
51 import java.security.KeyFactory;
52 import java.security.cert.Certificate;
53 import java.security.cert.CertificateFactory;
54 import java.security.spec.*;
55 import java.security.interfaces.*;
56 import sun.misc.BASE64Decoder;
57
58
59 public class DisabledShortRSAKeys {
60
61 /*
62 * =============================================================
63 * Set the various variables needed for the tests, then
64 * specify what tests to run on each side.
65 */
66
67 /*
68 * Should we run the client or server in a separate thread?
69 * Both sides can throw exceptions, but do you have a preference
70 * as to which side should be the main thread.
71 */
72 static boolean separateServerThread = true;
73
74 /*
75 * Where do we find the keystores?
76 */
227 CertificateFactory cf = CertificateFactory.getInstance("X.509");
228
229 // create a key store
230 KeyStore ks = KeyStore.getInstance("JKS");
231 ks.load(null, null);
232
233 // import the trused cert
234 Certificate trusedCert = null;
235 ByteArrayInputStream is = null;
236 if (trustedCertStr != null) {
237 is = new ByteArrayInputStream(trustedCertStr.getBytes());
238 trusedCert = cf.generateCertificate(is);
239 is.close();
240
241 ks.setCertificateEntry("RSA Export Signer", trusedCert);
242 }
243
244 if (keyCertStr != null) {
245 // generate the private key.
246 PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
247 new BASE64Decoder().decodeBuffer(keySpecStr));
248 KeyFactory kf = KeyFactory.getInstance("RSA");
249 RSAPrivateKey priKey =
250 (RSAPrivateKey)kf.generatePrivate(priKeySpec);
251
252 // generate certificate chain
253 is = new ByteArrayInputStream(keyCertStr.getBytes());
254 Certificate keyCert = cf.generateCertificate(is);
255 is.close();
256
257 Certificate[] chain = null;
258 if (trusedCert != null) {
259 chain = new Certificate[2];
260 chain[0] = keyCert;
261 chain[1] = trusedCert;
262 } else {
263 chain = new Certificate[1];
264 chain[0] = keyCert;
265 }
266
267 // import the key entry.
|
36 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1.2
37 * @run main/othervm DisabledShortRSAKeys PKIX TLSv1.1
38 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1.1
39 * @run main/othervm DisabledShortRSAKeys PKIX TLSv1
40 * @run main/othervm DisabledShortRSAKeys SunX509 TLSv1
41 * @run main/othervm DisabledShortRSAKeys PKIX SSLv3
42 * @run main/othervm DisabledShortRSAKeys SunX509 SSLv3
43 */
44
45 import java.net.*;
46 import java.util.*;
47 import java.io.*;
48 import javax.net.ssl.*;
49 import java.security.Security;
50 import java.security.KeyStore;
51 import java.security.KeyFactory;
52 import java.security.cert.Certificate;
53 import java.security.cert.CertificateFactory;
54 import java.security.spec.*;
55 import java.security.interfaces.*;
56 import java.util.Base64;
57
58
59 public class DisabledShortRSAKeys {
60
61 /*
62 * =============================================================
63 * Set the various variables needed for the tests, then
64 * specify what tests to run on each side.
65 */
66
67 /*
68 * Should we run the client or server in a separate thread?
69 * Both sides can throw exceptions, but do you have a preference
70 * as to which side should be the main thread.
71 */
72 static boolean separateServerThread = true;
73
74 /*
75 * Where do we find the keystores?
76 */
227 CertificateFactory cf = CertificateFactory.getInstance("X.509");
228
229 // create a key store
230 KeyStore ks = KeyStore.getInstance("JKS");
231 ks.load(null, null);
232
233 // import the trused cert
234 Certificate trusedCert = null;
235 ByteArrayInputStream is = null;
236 if (trustedCertStr != null) {
237 is = new ByteArrayInputStream(trustedCertStr.getBytes());
238 trusedCert = cf.generateCertificate(is);
239 is.close();
240
241 ks.setCertificateEntry("RSA Export Signer", trusedCert);
242 }
243
244 if (keyCertStr != null) {
245 // generate the private key.
246 PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
247 Base64.getMimeDecoder().decode(keySpecStr));
248 KeyFactory kf = KeyFactory.getInstance("RSA");
249 RSAPrivateKey priKey =
250 (RSAPrivateKey)kf.generatePrivate(priKeySpec);
251
252 // generate certificate chain
253 is = new ByteArrayInputStream(keyCertStr.getBytes());
254 Certificate keyCert = cf.generateCertificate(is);
255 is.close();
256
257 Certificate[] chain = null;
258 if (trusedCert != null) {
259 chain = new Certificate[2];
260 chain[0] = keyCert;
261 chain[1] = trusedCert;
262 } else {
263 chain = new Certificate[1];
264 chain[0] = keyCert;
265 }
266
267 // import the key entry.
|