31 * @bug 7106773
32 * @summary 512 bits RSA key cannot work with SHA384 and SHA512
33 *
34 * SunJSSE does not support dynamic system properties, no way to re-use
35 * system properties in samevm/agentvm mode.
36 * @run main/othervm ShortRSAKey512 PKIX
37 * @run main/othervm ShortRSAKey512 SunX509
38 */
39
40 import java.net.*;
41 import java.util.*;
42 import java.io.*;
43 import javax.net.ssl.*;
44 import java.security.Security;
45 import java.security.KeyStore;
46 import java.security.KeyFactory;
47 import java.security.cert.Certificate;
48 import java.security.cert.CertificateFactory;
49 import java.security.spec.*;
50 import java.security.interfaces.*;
51 import sun.misc.BASE64Decoder;
52
53
54 public class ShortRSAKey512 {
55
56 /*
57 * =============================================================
58 * Set the various variables needed for the tests, then
59 * specify what tests to run on each side.
60 */
61
62 /*
63 * Should we run the client or server in a separate thread?
64 * Both sides can throw exceptions, but do you have a preference
65 * as to which side should be the main thread.
66 */
67 static boolean separateServerThread = false;
68
69 /*
70 * Where do we find the keystores?
71 */
212 CertificateFactory cf = CertificateFactory.getInstance("X.509");
213
214 // create a key store
215 KeyStore ks = KeyStore.getInstance("JKS");
216 ks.load(null, null);
217
218 // import the trused cert
219 Certificate trusedCert = null;
220 ByteArrayInputStream is = null;
221 if (trustedCertStr != null) {
222 is = new ByteArrayInputStream(trustedCertStr.getBytes());
223 trusedCert = cf.generateCertificate(is);
224 is.close();
225
226 ks.setCertificateEntry("RSA Export Signer", trusedCert);
227 }
228
229 if (keyCertStr != null) {
230 // generate the private key.
231 PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
232 new BASE64Decoder().decodeBuffer(keySpecStr));
233 KeyFactory kf = KeyFactory.getInstance("RSA");
234 RSAPrivateKey priKey =
235 (RSAPrivateKey)kf.generatePrivate(priKeySpec);
236
237 // generate certificate chain
238 is = new ByteArrayInputStream(keyCertStr.getBytes());
239 Certificate keyCert = cf.generateCertificate(is);
240 is.close();
241
242 Certificate[] chain = null;
243 if (trusedCert != null) {
244 chain = new Certificate[2];
245 chain[0] = keyCert;
246 chain[1] = trusedCert;
247 } else {
248 chain = new Certificate[1];
249 chain[0] = keyCert;
250 }
251
252 // import the key entry.
|
31 * @bug 7106773
32 * @summary 512 bits RSA key cannot work with SHA384 and SHA512
33 *
34 * SunJSSE does not support dynamic system properties, no way to re-use
35 * system properties in samevm/agentvm mode.
36 * @run main/othervm ShortRSAKey512 PKIX
37 * @run main/othervm ShortRSAKey512 SunX509
38 */
39
40 import java.net.*;
41 import java.util.*;
42 import java.io.*;
43 import javax.net.ssl.*;
44 import java.security.Security;
45 import java.security.KeyStore;
46 import java.security.KeyFactory;
47 import java.security.cert.Certificate;
48 import java.security.cert.CertificateFactory;
49 import java.security.spec.*;
50 import java.security.interfaces.*;
51 import java.util.Base64;
52
53
54 public class ShortRSAKey512 {
55
56 /*
57 * =============================================================
58 * Set the various variables needed for the tests, then
59 * specify what tests to run on each side.
60 */
61
62 /*
63 * Should we run the client or server in a separate thread?
64 * Both sides can throw exceptions, but do you have a preference
65 * as to which side should be the main thread.
66 */
67 static boolean separateServerThread = false;
68
69 /*
70 * Where do we find the keystores?
71 */
212 CertificateFactory cf = CertificateFactory.getInstance("X.509");
213
214 // create a key store
215 KeyStore ks = KeyStore.getInstance("JKS");
216 ks.load(null, null);
217
218 // import the trused cert
219 Certificate trusedCert = null;
220 ByteArrayInputStream is = null;
221 if (trustedCertStr != null) {
222 is = new ByteArrayInputStream(trustedCertStr.getBytes());
223 trusedCert = cf.generateCertificate(is);
224 is.close();
225
226 ks.setCertificateEntry("RSA Export Signer", trusedCert);
227 }
228
229 if (keyCertStr != null) {
230 // generate the private key.
231 PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
232 Base64.getMimeDecoder().decode(keySpecStr));
233 KeyFactory kf = KeyFactory.getInstance("RSA");
234 RSAPrivateKey priKey =
235 (RSAPrivateKey)kf.generatePrivate(priKeySpec);
236
237 // generate certificate chain
238 is = new ByteArrayInputStream(keyCertStr.getBytes());
239 Certificate keyCert = cf.generateCertificate(is);
240 is.close();
241
242 Certificate[] chain = null;
243 if (trusedCert != null) {
244 chain = new Certificate[2];
245 chain[0] = keyCert;
246 chain[1] = trusedCert;
247 } else {
248 chain = new Certificate[1];
249 chain[0] = keyCert;
250 }
251
252 // import the key entry.
|