You can use the following procedure to obtain a security certificate:
import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.security.KeyStore;import java.security.MessageDigest;import java.security.cert.CertificateException;import java.security.cert.X509Certificate;import javax.net.ssl.SSLContext;import javax.net.ssl.SSLException;import javax.net.ssl.SSLSocket;import javax.net.ssl.SSLSocketFactory;import javax.net.ssl.TrustManager;import javax.net.ssl.TrustManagerFactory;import javax.net.ssl.X509TrustManager;public class InstallCert { public static void main(String[] args) throws Exception { String host; int port; char[] passphrase; if ((args.length == 1) || (args.length == 2)) { String[] c = args[0].split(":"); host = c[0]; port = (c.length == 1) ? 443 : Integer.parseInt(c[1]); String p = (args.length == 1) ? "changeit" : args[1]; passphrase = p.toCharArray(); } else { System.out .println("Usage: java InstallCert
Compile installcert. Java and execute: Java installcert hostname, for example: Java installcert test.report.com: 8443
Or, in eclipse, change the main method of the above program to add two lines.
String [] A = {"test.report.com: 8443 "};
ARGs =;
Run directly
The following information is displayed:
Loading keystore jssecacerts... opening connection to test.report.com: 8443... starting SSL handshake... no errors, certificate is already trustedserver sent 1 certificate (s): 1 Subject Cn = localhost, ou = localhost, O = Local, L = SH, St = SH, C = cn issuer Cn = localhost, ou = localhost, O = Local, L = SH, St = SH, C = cn sha1 37 14 8A 28 58 2B 3A F3 dB 42 0d 92 FD 3f F1 A6 06 13 35 21 MD5 55 69 fa 43 37 41 09 F5 67 da E2 92 27 33 EC 79 enter certificate to add to trusted keystore or 'q' to quit: [1]//// // This will pause and enter 1.1 [[version: V3 subject: Cn = localhost, ou = localhost, O = Local, L = SH, St = SH, c = cn signature algorithm: sha1withrsa, oid = 1.2.840.113549.1.1.5 key: Sun RSA public key, 1024 bit modulus: 149873530000197648968384226232142785553649803399692573942793261090630391481722183310320058253183769285146849448847313746048049814923722789854933544076336037287359367641477779694510644756797446990529822078491466388360 806777787325862581162302785602922306714668838474079290033075735325490781287260322195248343873 public exponent: 65537 validity: [from: Fri Aug 01 08:27:33 CST 2014, to: Sat Aug 01 08:27:33 CST 2015] issuer: Cn = localhost, ou = localhost, O = local, L = SH, St = SH, c = cn serialnumber: [53dadef5] algorithm: [sha1withrsa] Signature: 0000: 29 85 FC 3A 53 22 B3 BF 7b 47 ff 2a 57 94 B5 C2 )..: s "... g. * w... 0010: 1 A 04 af B6 EE 6B AC 08 49 60 7b 42 07 0a F2 23 ..... k .. I '. b... #0020: 85 8f 93 50 CD 86 5d AC 97 8d 6C DF 2C 1E 10 71... p...]... l .,.. q0030: 64 4D ed ca 06 8e 79 9C 00 A7 94 D0 5C 36 39 B3 DM .... Y ..... \ 69.0040: 32 D4 7C 40 25 A0 B7 CB B3 F8 1B A7 6a CC D4 D4 [email protected] % ....... j... 0050: 26 C7 3E 04 9A 27 8d 63 74 4B D1 5E 97 51 E0 7E &...> .. '. CTK. ^. Q .. 0060: E3 25 0d 6a 19 51 F8 D1 B5 B4 fa 23 98 41 70 D0. %. J. Q... #. ap.0070: BC 57 21 ce 75 2E 7b F3 5B 2E 13 A5 F0 27 63 2C. W !. U... [... 'C,] added certificate to keystore 'jssecacerts' using alias 'test .report.com-1'
Copy the certificate$ Java_home/JRE/lib/securityDirectory
Note: because it is static loading, You need to restart your web server to make the certificate take effect.