/**
 *   Copyright  :  www.aposoft.cn
 */
package cn.aposoft.tutorial.http.https.usage;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
import org.apache.http.util.EntityUtils;

import cn.aposoft.tutorial.http.https.HttpsTools;

/**
 * @author LiuJian
 * @date 2017年4月4日
 * 
 */
public class AposoftCnDefault {
    public static void main(String[] args)
            throws IOException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException {
        TrustStrategy trustStrategy = new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                for (X509Certificate cert : chain) {
                    HttpsTools.visitCertificate(cert);
                }
                return false;
            }
            // startcom_certification_authority
        };
        SSLContext sslContext = null;
        sslContext = SSLContexts.custom()//
                // .loadTrustMaterial(new File("jssecacerts"),
                // "changeit".toCharArray(), null)//
                .loadTrustMaterial(new File("jssecacerts"), "changeit".toCharArray(), trustStrategy) //
                .build();
        try (CloseableHttpClient client = HttpClients.custom()//
                .setSSLContext(sslContext) //
                .build()) {
            HttpGet httpGet = new HttpGet("https://www.aposoft.cn/");
            // HttpGet httpGet = new HttpGet("https://www.startssl.com/");
            try (CloseableHttpResponse resp = client.execute(httpGet)) {
                String respText = EntityUtils.toString(resp.getEntity(), StandardCharsets.UTF_8);
                System.out.println();
            }
        }
    }
}

@@ -413,41 +413,207 @@
 e;%0D%0A
-%0D%0Aimport javax.net.ssl.SSLContext
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0Aimport javax.net.ssl.HostnameVerifier;%0D%0Aimport javax.net.ssl.SSLContext;%0D%0Aimport javax.net.ssl.SSLSocket;%0D%0Aimport javax.net.ssl.SSLSocketFactory
 ;%0D%0A%0D
@@ -719,24 +719,85 @@
 s.HttpGet;%0D%0A
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;%0D%0A
 import org.a
@@ -1056,26 +1056,48 @@
 p.https.
-HttpsTools
+verifier.DefaultHostnameVerifier
 ;%0D%0A%0D%0A/**
@@ -1341,32 +1341,89 @@
 cateException %7B%0D
+%0A%0D%0A        System.setProperty(%22javax.net.debug%22, %22ssl%22);%0D
 %0A        TrustSt
@@ -1616,16 +1616,19 @@
         
+ //
  for (X5
@@ -1670,27 +1670,26 @@
             
-   
+//
  HttpsTools.
@@ -1720,32 +1720,35 @@
 %0A               
+ //
  %7D%0D%0A            
@@ -2172,24 +2172,1337 @@
  .build();%0D%0A
+        String%5B%5D allProtocols = null;%0D%0A        String%5B%5D supportedCipherSuites = null;%0D%0A        SSLSocketFactory sslFactory = (SSLSocketFactory) sslContext.getSocketFactory();%0D%0A        List%3CString%3E enabledProtocols = new ArrayList%3C%3E();%0D%0A        try (SSLSocket sslSocket = (SSLSocket) sslFactory.createSocket();) %7B%0D%0A            allProtocols = sslSocket.getSupportedProtocols();%0D%0A            supportedCipherSuites = sslFactory.getSupportedCipherSuites();%0D%0A%0D%0A            for (final String protocol : allProtocols) %7B%0D%0A                if (!protocol.startsWith(%22SSL%22)) %7B%0D%0A                    enabledProtocols.add(protocol);%0D%0A                %7D%0D%0A            %7D%0D%0A            System.out.println(%22ENABLED+PROTOCOLS:%22 + enabledProtocols);%0D%0A        %7D%0D%0A        // cn.aposoft.tutorial.http.https.verifier%0D%0A        HostnameVerifier hostNameVerifier = new DefaultHostnameVerifier();%0D%0A        SSLConnectionSocketFactory sslSocketFactory;%0D%0A        if (allProtocols == null %7C%7C supportedCipherSuites == null) %7B%0D%0A            sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostNameVerifier);%0D%0A        %7D else %7B%0D%0A            sslSocketFactory = new SSLConnectionSocketFactory(sslContext, enabledProtocols.toArray(new String%5BenabledProtocols.size()%5D),%0D%0A                    supportedCipherSuites, hostNameVerifier);%0D%0A        %7D%0D%0A
         try 
@@ -3598,24 +3598,82 @@
 ontext) //%0D%0A
+                .setSSLSocketFactory(sslSocketFactory)%0D%0A%0D%0A
             
@@ -3754,16 +3754,21 @@
 osoft.cn
+:8443
 /%22);%0D%0A  
@@ -4049,16 +4049,24 @@
 println(
+respText
 );%0D%0A    

添加标准的 enable protocols