-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLSHandshake
More file actions
33 lines (27 loc) · 1.09 KB
/
TLSHandshake
File metadata and controls
33 lines (27 loc) · 1.09 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
public class TLSHandshake {
private SSLSocket createSecureSocket(String host, int port)
throws Exception {
SSLContext context = TLSConfig.createSSLContext();
SSLSocketFactory factory = context.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
// Configurar protocolos permitidos
socket.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.3"});
// Configurar cipher suites
socket.setEnabledCipherSuites(
getSecureCipherSuites(socket.getSupportedCipherSuites())
);
return socket;
}
private String[] getSecureCipherSuites(String[] supported) {
List secure = new ArrayList<>();
for (String suite : supported) {
// Seleccionar solo cipher suites seguros
if (suite.contains("_GCM_") ||
suite.contains("_CHACHA20_") ||
suite.contains("_ECDHE_")) {
secure.add(suite);
}
}
return secure.toArray(new String[0]);
}
}