Jelajahi Sumber

加密测试6

turborao 1 bulan lalu
induk
melakukan
a45391576b

+ 23 - 1
code/base/nckd-jimin-base-helper/src/main/java/nckd/base/helper/FileSECUtils.java

@@ -11,13 +11,17 @@ import kd.bos.servicehelper.AttachmentServiceHelper;
 import kd.bos.servicehelper.BusinessDataServiceHelper;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLContextBuilder;
 import org.apache.http.conn.ssl.TrustStrategy;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContexts;
+
 import javax.net.ssl.SSLContext;
 
 import java.io.*;
@@ -87,7 +91,7 @@ public class FileSECUtils {
             post.setEntity(entity);
 
             logger.info("--------------SEC附件检查文件 buildSSLCloseableHttpClient() ----------------");
-            httpclient = buildSSLCloseableHttpClient();
+            httpclient = getHttpClient();
             logger.info("--------------SEC附件检查文件 httpclient.execute(post) ----------------");
             CloseableHttpResponse response = httpclient.execute(post);
             String result = response.getFirstHeader("data~returnFlag").getValue();
@@ -224,6 +228,24 @@ public class FileSECUtils {
     }
 
 
+    public static CloseableHttpClient getHttpClient() {
+        CloseableHttpClient httpClient = null;
+        try {
+            TrustStrategy acceptingTrustStrategy = (chain, authType) -> true;
+            SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
+            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
+            logger.info("--------------SEC附件 buildSSLCloseableHttpClient1 ----------------");
+            HttpClientBuilder clientBuilder = HttpClients.custom();
+
+            httpClient = clientBuilder.setSSLSocketFactory(sslsf).build();
+            logger.info("--------------SEC附件 buildSSLCloseableHttpClient2 ----------------");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return httpClient;
+    }
+
+
     /**
      * 根据地址获得数据的字节流并转换成大小
      * @param originalPath 文件实际地址