Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
make com.feilong.net.ssl.TrustAnyTrustManager @deprecated fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed May 29, 2019
1 parent 3233bd2 commit 3df99e9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package com.feilong.net.ssl;

import static com.feilong.core.bean.ConvertUtil.toArray;
import static com.feilong.core.lang.ObjectUtil.defaultIfNullOrEmpty;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.apache.commons.net.util.TrustManagerUtils;

import com.feilong.net.UncheckedHttpException;

Expand Down Expand Up @@ -55,7 +57,10 @@ public static SSLContext build(String protocol){
try{
SSLContext sslContext = SSLContext.getInstance(defaultIfNullOrEmpty(protocol, SSLProtocol.TLS));

sslContext.init(null, new TrustManager[] { TrustAnyTrustManager.INSTANCE }, null);
sslContext.init(//
null,
toArray(TrustManagerUtils.getAcceptAllTrustManager()),
null);

return sslContext;
}catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.net.ssl;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.X509TrustManager;

/**
* The Class TrustAnyTrustManager.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @see "weibo4j.model.MySSLSocketFactory.TrustAnyTrustManager"
* @see org.apache.commons.net.util.TrustManagerUtils
* @deprecated pls use org.apache.commons.net.util.TrustManagerUtils#getAcceptAllTrustManager()
*/
@Deprecated
public class TrustAnyTrustManager implements X509TrustManager{

/** Static instance. */
Expand All @@ -13,14 +37,29 @@ public class TrustAnyTrustManager implements X509TrustManager{

//---------------------------------------------------------------

/*
* (non-Javadoc)
*
* @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], java.lang.String)
*/
@Override
public void checkClientTrusted(X509Certificate[] x509Certificate,String authType) throws CertificateException{
}

/*
* (non-Javadoc)
*
* @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String)
*/
@Override
public void checkServerTrusted(X509Certificate[] x509Certificate,String authType) throws CertificateException{
}

/*
* (non-Javadoc)
*
* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
*/
@Override
public X509Certificate[] getAcceptedIssuers(){
return new X509Certificate[] {};
Expand Down
6 changes: 0 additions & 6 deletions feilong-net-filetransfer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

<dependencies>

<!-- commons-net -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>

<!-- jsch 用于sftp 传输 -->
<dependency>
<groupId>com.jcraft</groupId>
Expand Down

0 comments on commit 3df99e9

Please sign in to comment.