如何在Java中使用TLSV1或SSLV3进行第一次握手(Client Hello)? [英] how to use TLSV1 or SSLV3 for first handshake(Client Hello) in Java?

查看:2201
本文介绍了如何在Java中使用TLSV1或SSLV3进行第一次握手(Client Hello)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下代码时,为什么第一次握手是SSLv2,而不是TLSv1或SSLv3?

When I execute the following code, why is the first handshake SSLv2, not TLSv1 or SSLv3?

如何在Java中使用TLSV1或SSLV3进行首次握手?

How to use TLSV1 or SSLV3 for first handshake in Java?

String host = "www.google.com";
String url = "/adsense/?sourceid=aso&subid=ZH_CN-ET-AS-ADSBY6&medium=link&hl=zh_CN";
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
SSLContext.setDefault(ctx);
SSLSocketFactory factory = ctx.getSocketFactory();
Socket socket = factory.createSocket(host, 443);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write("GET " + url + " HTTP/1.0");
out.flush();
out.close();
in.close();


推荐答案

对于TLSv1:
启动客户端jvm with

For TLSv1: Starting the client jvm with

-Dhttps.protocols="TLSv1" 

或使用

System.setProperty("https.protocols", "TLSv1");

为我解决了这个问题。

这篇关于如何在Java中使用TLSV1或SSLV3进行第一次握手(Client Hello)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆