SSL和TLS之间的区别及其在Java中的使用 [英] Difference between SSL and TLS and their usage in Java

查看:405
本文介绍了SSL和TLS之间的区别及其在Java中的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我正在设置的Java客户端和服务器之间建立SSL或TLS连接。

I am trying to establish an SSL or TLS connection between a Java client and server I am setting up.

我一直在使用 SSLContext .getInstance(SSL)构建 SSLContext ,并且它有效。

I have been using SSLContext.getInstance("SSL") to build the SSLContext, and it worked.

我想知道<$ h $ => http://docs.oracle.com/javase/7/docs/api中协议参数的用途是什么/javax/net/ssl/SSLContext.html#getInstance%28java.lang.String%29\">SSLContext.getInstance(String protocol)

I would like to know what the purpose of the protocol parameter is in SSLContext.getInstance(String protocol).

特别是,使用 SSLContext.getInstance(SSL) SSLContext.getInstance之间会发生什么变化(TLS)或其他可能的值?

In particular, what changes between using SSLContext.getInstance("SSL") and SSLContext.getInstance("TLS"), or other possible values?

推荐答案

这是还有一个详细的答案,我写了一段时间后描述了SSL和TLS之间的区别。简而言之,TLS是SSL的继承者,TLS 1.0可以被视为SSL 3.1。

Here is a rather detailed answer that I wrote a while back describing the difference between SSL and TLS. In short, TLS is the successor of SSL, and TLS 1.0 can be considered as "SSL 3.1".

如果你看一下 JSSE参考指南,在SSLContext部分,它说:

If you look at the JSSE Reference Guide, in the SSLContext section, it says:


这些静态方法每个都返回一个实现至少
请求的安全套接字协议的实例。返回的实例也可以
实现其他协议。例如,getInstance(TLSv1)可能
返回一个实现TLSv1,TLSv1.1和TLSv1.2的实例。

These static methods each return an instance that implements at least the requested secure socket protocol. The returned instance may implement other protocols too. For example, getInstance("TLSv1") may return a instance which implements "TLSv1", "TLSv1.1" and "TLSv1.2".

标准名称文档。

特别是,如果您检查 SSLContextImpl ,你会发现它的所有 SSLContext s支持所有协议(从SSLv3使用SSLv2客户端Hello到TLS 1.2)。不同之处在于默认启用哪些协议。此外,您通常不应该依赖于此,因为其他Java实现(例如IBM JRE)的行为可能不同。

In particular, if you check the Oracle/OpenJDK 7 source code for SSLContextImpl, you'll find that all its SSLContexts support all protocols (from SSLv3 using an SSLv2 Client Hello to TLS 1.2). What differs is which protocols are enabled by default. In addition, you shouldn't rely on this in general, since other Java implementations (e.g. the IBM JRE) could behave differently.

如果您需要一组特定的协议要用于连接,你应该使用 SSLSocket SSLEngine setEnabledProtocols 方法。否则,它将使用默认值,如提供商文件

If you want a particular set of protocols to be used for a connection, you should use SSLSocket or SSLEngine's setEnabledProtocols method. Otherwise, it will use the default values, as described in the Providers documentation.

这篇关于SSL和TLS之间的区别及其在Java中的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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