Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有HTTPUrlConnection的Tomcat SSL连接器配置_Java_Security_Tomcat_Ssl_Tls1.2 - Fatal编程技术网

Java 带有HTTPUrlConnection的Tomcat SSL连接器配置

Java 带有HTTPUrlConnection的Tomcat SSL连接器配置,java,security,tomcat,ssl,tls1.2,Java,Security,Tomcat,Ssl,Tls1.2,嗨,我有如下配置的tomcat容器: <Connector port=... connectionTimeout=... maxThreads=... scheme="https" secure="true" SSLEnabled="true" keystoreFile="path to keystore" keystorePass="pass" truststoreFile="path to truststore"

嗨,我有如下配置的tomcat容器:

<Connector 
    port=...
    connectionTimeout=...
    maxThreads=...
    scheme="https"
    secure="true"
    SSLEnabled="true"
    keystoreFile="path to keystore"
    keystorePass="pass"
    truststoreFile="path to truststore"
    truststorePass="pass to truststore"
    keyAlias=...
    clientAuth=...
    sslProtocol="TLSv1.2"
    protocol="HTTP/1.1" />
问题是我的SSLHandshake PKIX异常失败,这通常发生在由于某种原因(证书无效、非信任存储无效或没有适当的CA)导致验证失败时

调试之后,我看到我已经配置了一些默认的ssl上下文和信任存储(它不是我的信任存储)

我的问题: 1。如何实现客户端,使其从tomcat连接器获取信任存储。。。 2.我看到的是java stand art trust商店吗?从哪里得到的

我可以在HTTPSUrlConnection上设置自定义SSLContext,如下所示:

HttpURLConnection connection = null;
    StringBuilder response = new StringBuilder();
    try {
        URL url = new URL(requestURL);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setConnectTimeout(10000);
        connection.setReadTimeout(10000);

        String requestMessage = "some request";
        try (OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream())) {
            out.write(requestMessage);
        }
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

但是,我不想手动提供信任库,我想使用tomcat连接器提供的信任库

请记住,配置的密钥库用于服务器的SSL证书。您的客户端代码将从它调用的服务器接收SSL证书,并将根据您的CACERTS文件(而不是密钥库)中的受信任根证书验证该证书。Java在\jre\lib\security\CACERTS为您提供了一个预填充的CACERTS。是的,我清楚地知道,它将在信任存储区前面验证服务器证书。只是想了解是否有可能更改java的信任库并从连接器获取它。在连接器中,我配置了密钥库(用于服务器证书)和信任库。那么,tomcat连接器上的信任存储的目的是什么?它只用于相互认证吗?