mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -18,7 +18,7 @@ import java.security.SecureRandom;
|
||||
* <ul>
|
||||
* <li>协议(protocol),默认TLS</li>
|
||||
* <li>{@link KeyManager},默认空</li>
|
||||
* <li>{@link TrustManager},默认{@link DefaultTrustManager},即信任全部</li>
|
||||
* <li>{@link TrustManager},默认{@link TrustAnyTrustManager},即信任全部</li>
|
||||
* <li>{@link SecureRandom}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
@@ -32,7 +32,7 @@ public class SSLContextBuilder implements SSLProtocols, Builder<SSLContext> {
|
||||
|
||||
private String protocol = TLS;
|
||||
private KeyManager[] keyManagers;
|
||||
private TrustManager[] trustManagers = {DefaultTrustManager.INSTANCE};
|
||||
private TrustManager[] trustManagers = {TrustAnyTrustManager.INSTANCE};
|
||||
private SecureRandom secureRandom = new SecureRandom();
|
||||
|
||||
|
||||
|
@@ -15,23 +15,37 @@ import javax.net.ssl.TrustManager;
|
||||
public class SSLUtil {
|
||||
|
||||
/**
|
||||
* 创建{@link SSLContext},默认新人全部
|
||||
* 创建{@link SSLContext},信任全部,协议为TLS
|
||||
*
|
||||
* @param protocol SSL协议,例如TLS等
|
||||
* @return {@link SSLContext}
|
||||
* @throws IORuntimeException 包装 GeneralSecurityException异常
|
||||
*/
|
||||
public static SSLContext createTrustAnySSLContext() throws IORuntimeException {
|
||||
return createTrustAnySSLContext(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@link SSLContext},信任全部
|
||||
*
|
||||
* @param protocol SSL协议,例如TLS等,{@code null}表示默认TLS
|
||||
* @return {@link SSLContext}
|
||||
* @throws IORuntimeException 包装 GeneralSecurityException异常
|
||||
* @since 5.7.8
|
||||
*/
|
||||
public static SSLContext createSSLContext(final String protocol) throws IORuntimeException{
|
||||
return SSLContextBuilder.of().setProtocol(protocol).build();
|
||||
public static SSLContext createTrustAnySSLContext(final String protocol) throws IORuntimeException {
|
||||
return SSLContextBuilder.of()
|
||||
.setProtocol(protocol)
|
||||
// 信任所有服务端
|
||||
.setTrustManagers(new TrustManager[]{TrustAnyTrustManager.INSTANCE})
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@link SSLContext}
|
||||
*
|
||||
* @param protocol SSL协议,例如TLS等
|
||||
* @param keyManager 密钥管理器,{@code null}表示无
|
||||
* @param trustManager 信任管理器, {@code null}表示无
|
||||
* @param keyManager 密钥管理器,{@code null}表示默认
|
||||
* @param trustManager 信任管理器, {@code null}表示默认
|
||||
* @return {@link SSLContext}
|
||||
* @throws IORuntimeException 包装 GeneralSecurityException异常
|
||||
*/
|
||||
@@ -46,8 +60,8 @@ public class SSLUtil {
|
||||
* 创建和初始化{@link SSLContext}
|
||||
*
|
||||
* @param protocol SSL协议,例如TLS等
|
||||
* @param keyManagers 密钥管理器,{@code null}表示无
|
||||
* @param trustManagers 信任管理器, {@code null}表示无
|
||||
* @param keyManagers 密钥管理器,{@code null}表示默认
|
||||
* @param trustManagers 信任管理器, {@code null}表示默认
|
||||
* @return {@link SSLContext}
|
||||
* @throws IORuntimeException 包装 GeneralSecurityException异常
|
||||
*/
|
||||
|
@@ -6,19 +6,21 @@ import java.net.Socket;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* 默认信任管理器,默认信任所有客户端和服务端证书<br>
|
||||
* 继承{@link X509ExtendedTrustManager}的原因见:https://blog.csdn.net/ghaohao/article/details/79454913
|
||||
* 新任所有信任管理器,默认信任所有客户端和服务端证书<br>
|
||||
* 继承{@link X509ExtendedTrustManager}的原因见:<br>
|
||||
* https://blog.csdn.net/ghaohao/article/details/79454913
|
||||
*
|
||||
* @author Looly
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public class DefaultTrustManager extends X509ExtendedTrustManager {
|
||||
public class TrustAnyTrustManager extends X509ExtendedTrustManager {
|
||||
|
||||
/**
|
||||
* 默认的全局单例默认信任管理器,默认信任所有客户端和服务端证书
|
||||
* 全局单例信任管理器,默认信任所有客户端和服务端证书
|
||||
*
|
||||
* @since 5.7.8
|
||||
*/
|
||||
public static DefaultTrustManager INSTANCE = new DefaultTrustManager();
|
||||
public static TrustAnyTrustManager INSTANCE = new TrustAnyTrustManager();
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
Reference in New Issue
Block a user