-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCiphers.java
More file actions
59 lines (49 loc) · 2.14 KB
/
getCiphers.java
File metadata and controls
59 lines (49 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.security.NoSuchAlgorithmException;
import java.security.KeyManagementException;
import javax.net.ssl.SSLContext;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class SSLContextWrapper implements AutoCloseable {
private final SSLContext sslContext;
public SSLContextWrapper(String protocol) throws NoSuchAlgorithmException, KeyManagementException {
this.sslContext = SSLContext.getInstance(protocol);
this.sslContext.init(null, null, null);
}
public SSLContext getSSLContext() {
return sslContext;
}
@Override
public void close() throws Exception {
// You might want to add cleanup logic here if needed
}
}
public class getCiphers {
public static void main(String[] args) {
try {
// Use try-with-resources with SSLContextWrapper
try (final SSLContextWrapper sslContextWrapper = new SSLContextWrapper("TLS")) {
final SSLContext sslContext = sslContextWrapper.getSSLContext();
// Rest of your code for retrieving and printing protocols and ciphers
final List<String> supportedProtocols = Arrays.asList(sslContext.getSupportedSSLParameters().getProtocols());
final List<String> supportedCipherSuites = Arrays.asList(sslContext.getSupportedSSLParameters().getCipherSuites());
Collections.sort(supportedProtocols);
Collections.sort(supportedCipherSuites);
System.out.println("Supported TLS Protocols:");
for (String protocol : supportedProtocols) {
System.out.println(protocol);
}
System.out.println();
System.out.println("Supported Cipher Suites:");
for (String cipher : supportedCipherSuites) {
System.out.println(cipher);
}
}
} catch (NoSuchAlgorithmException | KeyManagementException e) {
// Handle exceptions, maybe print an error message
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}