|
| 1 | +import javax.net.ssl.SSLContext; |
| 2 | +import java.security.NoSuchAlgorithmException; |
| 3 | +import javax.net.ssl.SSLSocketFactory; |
| 4 | +import java.security.KeyManagementException; |
| 5 | + |
| 6 | +public class SSLContextInfo { |
| 7 | + |
| 8 | + public static void main(String[] args) |
| 9 | + { |
| 10 | + int i, c; |
| 11 | + /* Try to establish a TLSv1 SSLContext */ |
| 12 | + String[] protos = {"TLS", "TLSv1", "TLSv1.1", "SSLv3"}; |
| 13 | + System.out.println("SSLContext creation attempts:"); |
| 14 | + for (i = 0; i < protos.length; i++) { |
| 15 | + try { |
| 16 | + SSLContext ctx = SSLContext.getInstance(protos[i]); |
| 17 | + System.out.println(" " + protos[i] + " created: " + ctx.toString()); |
| 18 | + System.out.println(" Provider: " + ctx.getProvider().toString()); |
| 19 | + System.out.println(" Protocol: " + ctx.getProvider()); |
| 20 | + try { |
| 21 | + ctx.init(null, null, null); |
| 22 | + System.out.println(" SSLContext.init(): ok"); |
| 23 | + SSLSocketFactory sf = ctx.getSocketFactory(); |
| 24 | + System.out.println(" SocketFactory: created: " + sf.toString()); |
| 25 | + String[] default_ciphers = sf.getDefaultCipherSuites(); |
| 26 | + System.out.println(" Default ciphers:"); |
| 27 | + for (c = 0; c < default_ciphers.length; c++) { |
| 28 | + System.out.println(" " + default_ciphers[c]); |
| 29 | + } |
| 30 | + String[] supported_ciphers = sf.getSupportedCipherSuites(); |
| 31 | + System.out.println(" Supported ciphers:"); |
| 32 | + for (c = 0; c < supported_ciphers.length; c++) { |
| 33 | + System.out.println(" " + supported_ciphers[c]); |
| 34 | + } |
| 35 | + } catch (KeyManagementException kmx) { |
| 36 | + System.out.println(" SSLContext.init(): failed: " + kmx.toString()); |
| 37 | + } |
| 38 | + } catch (NoSuchAlgorithmException ex) { |
| 39 | + System.out.println(" " + protos[i] + " failed: " + ex.toString()); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +// vim: ts=4 sw=4 et ai |
0 commit comments