JDK与HTTPS各版本对应关系
IBMJDK 支持 TLS12
-Dcom.ibm.jsse2.overrideDefaultTLS=true
-Dcom.ibm.jsse2.overrideDefaultProtocol=TLSv12
#使用工具测试
D:\JDK\IBMJDK1.8_Win\bin>java.exe HTTPSClient baidu.com
HTTP/1.1 302 Moved Temporarily
Server: bfe/1.0.8.18
Date: Wed, 26 Aug 2020 05:58:37 GMT
Content-Type: text/html
Content-Length: 161
Connection: close
Location: http://www.baidu.com/error.html
Set-Cookie: __bsi=14235882381431070594_00_218_N_N_0_0303_C02F_N_N_N_0; expires=Wed, 26-Aug-20 05:58:42 GMT; domain=www.baidu.com; path=/
302 Found302 Found
IBMJDK1.6-Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.2 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr ClientHello
2020-8-26 14:01:35 java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
IBMJSSE2 to send SCSV Cipher Suite on initial ClientHello
*** ClientHello, TLSv1
IBMJDK1.8_Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.1 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello
*** ClientHello, TLSv1.1
IBMJDK1.8_Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.2 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello
*** ClientHello, TLSv1.2
IBMJDK1.8_Win\bin>java.exe -Dhttps.protocols=TLSv1.1 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello
*** ClientHello, TLSv1.2
import java.net.*;
import java.io.*;
import java.security.*;
import javax.net.ssl.*;
public class HTTPSClient {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java HTTPSClient host");
return;
}
int port = 443; // default https port
String host = args[0];
try{
//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
Writer out = new OutputStreamWriter(socket.getOutputStream());
// https requires the full URL in the GET line
out.write("GET / HTTP/1.0\\r\\\n");
out.write("\\r\\n");
out.flush();
// read response
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
int c;
while ((c = in.read()) != -1) {
System.out.write(c);
}
out.close();
in.close();
socket.close();
}catch (IOException e) {
System.err.println(e);
}
}
}