Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.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 web应用程序的SSLContext_Java_Jsp_Ssl Certificate_X509_Private Key - Fatal编程技术网

用于java web应用程序的SSLContext

用于java web应用程序的SSLContext,java,jsp,ssl-certificate,x509,private-key,Java,Jsp,Ssl Certificate,X509,Private Key,在我的桌面java应用程序中,有一个类使用客户端证书通过HTTPS连接与其他系统连接。此连接的一部分是SSLContext,它接收KeyManager[]和TrustManager[],以实现用户证书和trsut存储,从而获得远程服务器的handshack。此类使用Windows存储库获取计算机上可用的证书列表,以便用户可以选择正确的证书进行连接。问题是,我正在将此应用程序迁移到一个云web服务器(tomcat),而获取证书的过程则完全不同。使用tomcat,我可以将用户转发到https页面,该

在我的桌面java应用程序中,有一个类使用客户端证书通过HTTPS连接与其他系统连接。此连接的一部分是SSLContext,它接收KeyManager[]和TrustManager[],以实现用户证书和trsut存储,从而获得远程服务器的handshack。此类使用Windows存储库获取计算机上可用的证书列表,以便用户可以选择正确的证书进行连接。问题是,我正在将此应用程序迁移到一个云web服务器(tomcat),而获取证书的过程则完全不同。使用tomcat,我可以将用户转发到https页面,该页面请求CA颁发的有效证书。一旦用户访问该页面,浏览器会弹出一个窗口,其中包含机器上可用的证书,因此用户可以选择一个。我现在的问题是创建此SSLContext一次,通过浏览器身份验证,我只能获得用户选择的x509证书,但没有私钥。我的问题是。我是否缺少获取证书私钥的内容?我知道windows存储库不共享私钥,但当从桌面应用程序调用此过程时,至少是“resume或header”(RSAPrivateKey[size=2048位,type=Exchange,container={提供了密钥的个数,但仍然有效。但是通过浏览器,我无法获取此信息。或者是否有其他方法可以仅使用x509证书创建KeyManager[],而不提供私钥

下面是创建与服务器连接的一段代码

// create the connection
SocketFactoryDinamico socketFactory = new SocketFactoryDinamico(X509certificate, PrivateKey);
socketFactory.setFileCacerts(getClass().getResourceAsStream("cacerts"));

KeyManager[] keyManagers = socketFactory.createKeyManagers();
TrustManager[] trustManagers = socketFactory.createTrustManagers();

SSLContext sslc = SSLContext.getInstance("TLS");
sslc.init(keyManagers, trustManagers, null);

HttpsURLConnection.setDefaultSSLSocketFactory(sslc.getSocketFactory());

String url = "https://someserver.com";

URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
下面是在.jsp上获取x509证书的代码

X509Certificate[] certs = (X509Certificate[]) 
request.getAttribute("javax.servlet.request.X509Certificate");
if (null != certs && certs.length > 0) {

    X509Certificate cert = certs[0];
}
下面是请求证书身份验证的服务器配置

<Connector
    clientAuth="true" 
    port="8443" 
    protocol="HTTP/1.1" 
    SSLEnabled="true"
    scheme="https" 
    secure="true"
    keystoreFile="C:/JavaWeb/tomcat"
    keystoreType="JKS" keystorePass="pswd"
    truststoreFile="C:/JavaWeb/myTrustStore"
    truststoreType="JKS" truststorePass="changeit"
    SSLVerifyCLient="require" SSLVerifyDepth="10" sslProtocol="TLS"
/>

将应用程序迁移到云服务器与让客户机在可以访问其私钥的机器上运行完全不同。您所描述的更像tomcat实例是代表客户机与服务器通信的代理。我不清楚客户机在这个设置中看到了什么。Si一旦代理看到所有明文,客户端和服务器都必须信任代理。客户端身份验证背后的假设被打破,因此代理也可以访问私钥。明白。是否有其他方法直接与服务器连接?可能使用javascript?将应用程序迁移到云服务器是一种完全不同的体系结构,不同于让客户机在能够访问其私钥的机器上运行。您所描述的听起来更像tomcat实例是一个代理,它代表客户机与服务器通信。我不清楚客户机在这个设置中看到了什么。因为代理可以看到所有的plaintext是客户端和服务器都必须信任的代理。客户端身份验证背后的假设已被打破,因此代理也可以访问私钥。明白。是否有其他直接与服务器连接的方法?可能使用javascript?
    var httpRequest = new XMLHttpRequest();        
    httpRequest.open("POST", "https://remoteserver.com");
    httpRequest.setRequestHeader("Role-Type", "role");

    httpRequest.onreadystatechange = function () {

        if (this.readyState === 4) {
            if (httpRequest.status === 200) {
                console.log('Status:', this.status);
                console.log('Headers:', this.getAllResponseHeaders());
                console.log('Body:', this.responseText);

                console.log(httpRequest);

            } else {
                console.log("Erro");
                console.log(httpRequest);
            }
        }
    };

    httpRequest.send();