Skip to content

Commit 1c04e9c

Browse files
author
Craig Ringer
committed
Sample code for JSSE / JSA jvm/jre/jdk info re SSLv3 and TLS support
1 parent eb27e46 commit 1c04e9c

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed
894 Bytes
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.security.Security;
2+
import java.security.Provider;
3+
4+
public class JSSInfo {
5+
6+
public static void main(String[] args)
7+
{
8+
/* JSA providers */
9+
Provider[] providers = Security.getProviders();
10+
System.out.println("JSA providers:");
11+
int i;
12+
for (i = 0; i < providers.length; i++)
13+
{
14+
System.out.println(" " + i + " " + providers[i].toString());
15+
}
16+
System.out.println("\n");
17+
}
18+
}
19+
20+
// vim: ts=4 sw=4 et ai
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
all: SSLContextInfo JSSInfo
2+
3+
%Info: %Info.class
4+
@echo
5+
java $(basename $< .class)
6+
7+
%.class: %.java
8+
javac $<
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)