I know that there have been a question asked about enabling TLS 1.2 in Java 6 but I have not found a proper solution.
I have tried also with a BouncyCastle provider, but no luck there...
I have managed to get it to work, following some other site's help with the code:
package testTLS12;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.security.SecureRandom;
import org.bouncycastle.tls.CertificateRequest;
import org.bouncycastle.tls.DefaultTlsClient;
import org.bouncycastle.tls.TlsAuthentication;
import org.bouncycastle.tls.TlsClientProtocol;
import org.bouncycastle.tls.TlsCredentials;
import org.bouncycastle.tls.TlsServerCertificate;
import org.bouncycastle.tls.crypto.TlsCrypto;
import org.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto;
public class TestHttpClient {
public static void main(String[] args) throws Exception {
SecureRandom secureRandom = new SecureRandom();
Socket socket = new Socket(InetAddress.getByName("tls-v1-2.badssl.com"), 1012);
TlsClientProtocol protocol = new TlsClientProtocol(socket.getInputStream(), socket.getOutputStream());
TlsCrypto crypto = new BcTlsCrypto(secureRandom);
DefaultTlsClient client = new DefaultTlsClient(crypto) {
public TlsAuthentication getAuthentication() throws IOException {
return new TlsAuthentication() {
@Override
public TlsCredentials getClientCredentials(CertificateRequest var1) throws IOException {
return null;
}
@Override
public void notifyServerCertificate(TlsServerCertificate var1) throws IOException {
}
};
}
};
protocol.connect(client);
OutputStream output = protocol.getOutputStream();
output.write("GET / HTTP/1.1\r\n".getBytes("UTF-8"));
output.write("Host: www.google.com\r\n".getBytes("UTF-8"));
output.write("Connection: close\r\n".getBytes("UTF-8")); // So the server will close socket immediately.
output.write("\r\n".getBytes("UTF-8")); // HTTP1.1 requirement: last line must be empty line.
output.flush();
InputStream input = protocol.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
socket.close();
}
}
but it is a custom socket manipulation etc. I am not able to enable whole JRE with TLS1.2 - meaning that every library like JSoup or similar, that uses SSLSocketFactory should be also able to use TLS1.2
Using "paid" version of JRE is not an option. Paid version I mean everything over Java 6u45. https://www.oracle.com/java/technologies/oracle-java-archive-downloads.html - Current update releases for JDK 6 and JDK 7 are available for support customers.
Upgrade to Java 8 is also not an option.
I have tried the class TSLSocketConnectionFactory
from How to use TLS 1.2 in Java 6 but no luck...
Has anyone made it to the working code?