2

我在设置双向 SSL 身份验证时遇到问题。我需要从 wso2 企业集成商访问 HTTPS 端点。服务提供商给了我一个 pfx 密钥库,其中包含我必须提供给服务器的证书和私钥。

我在我的 Windows 计算机上安装了这个 pfx 密钥库,并尝试从 Chrome 访问端点(端点在根上下文中有一个返回 hello 消息的 GET 服务)。访问此端点时,chrome 告诉我选择提供给服务器的证书...我选择好的证书并返回 hello 消息...很好,证书有效。

我也尝试使用 curl,提供密钥、cacert 和 cert(使用 openssl 从 pfx 文件中提取)。一切正常。

问题是当我尝试从 wso2 ei 服务访问此端点时。我使用 keytool 按照以下步骤将我的 pfx 文件导入默认密钥库 (wso2carbon.jks):

  1. 在 jks 中导入 pfx

    keytool -importkeystore -srckeystore .pfx -srcstoretype pkcs12 -destkeystore wso2carbon.jks -deststoretype JKS -srcstorepass -deststorepass wso2carbon

  2. 导出 jks 公钥

    keytool -export -alias "" -keystore wso2carbon.jks -file publickey.pem -storepass wso2carbon

  3. 在默认 client-trustore.jks 中导入公钥

    keytool -import -alias "" -file publickey.pem -keystore client-truststore.jks -storepass wso2carbon

  4. 更新 wso2carbon 密钥库中别名的密码(必须与 jks pwd 相同)

    keytool -keypasswd -alias "" -new wso2carbon -keystore wso2carbon.jks -keypass -storepass wso2carbon

  5. 将根和中间服务器证书添加到 trustore

    keytool -import -v -trustcacerts -alias root -file root.cer -keystore client-truststore.jks -storepass wso2carbon keytool -import -v -trustcacerts -alias intermed -file intermed.cer -keystore client-truststore.jks -storepass wso2carbon

重新启动 WSO2 EI 然后尝试访问端点(握手失败!!!)

我在错误的痕迹下方激活了 -Djavax.net.debug=ssl:handshake。似乎 WSO2 EI 找不到服务器要求的证书

...
*** CertificateRequest
Cert Types: RSA, DSS, ECDSA
Supported Signature Algorithms: SHA512withRSA, Unknown (hash:0x6, signature:0x2), SHA512withECDSA, SHA384withRSA, Unknown (hash:0x5, signature:0x2), SHA384withECDSA, SHA256withRSA, Unknown (hash:0x4, signature:0x2), SHA256withECDSA, SHA224withRSA, Unknown (hash:0x3, signature:0x2), SHA224withECDSA, SHA1withRSA, SHA1withDSA, SHA1withECDSA
Cert Authorities:
<CN=Autorite Bureau RTE, O=RTE, L=Pacy, ST=Eure, C=FR>
<CN=Autorite Racine RTE, O=RTE, L=Pacy, ST=Eure, C=FR>
<CN=Autorite Bureau Machine RTE, DC=bureau, DC=si, DC=interne>
*** ServerHelloDone
Warning: no suitable certificate found - continuing without client authentication
*** Certificate chain
<Empty>
***
*** ClientKeyExchange, RSA PreMasterSecret, TLSv1.2
PassThroughMessageProcessor-2, WRITE: TLSv1.2 Handshake, length = 320
SESSION KEYGEN:
PreMaster Secret:
... no IV derived for this protocol
PassThroughMessageProcessor-2, WRITE: TLSv1.2 Change Cipher Spec, length = 64
*** Finished
verify_data:  { 111, 185, 151, 74, 99, 156, 152, 185, 240, 222, 162, 116 }
***
PassThroughMessageProcessor-2, WRITE: TLSv1.2 Handshake, length = 80
PassThroughMessageProcessor-2, READ: TLSv1.2 Alert, length = 64
PassThroughMessageProcessor-2, RECV TLSv1.2 ALERT:  fatal, handshake_failure
%% Invalidated:  [Session-1, TLS_RSA_WITH_AES_256_CBC_SHA256]
%% Invalidated:  [Session-2, TLS_RSA_WITH_AES_256_CBC_SHA256]
PassThroughMessageProcessor-2, called closeSocket()
PassThroughMessageProcessor-2, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
PassThroughMessageProcessor-2, called close()
PassThroughMessageProcessor-2, called closeInternal(true)

我尝试使用 SOAP UI,引用先前创建的密钥库,GET 调用返回 hello 消息(握手成功)。

我还尝试了一个使用该密钥库的片段 java 类,并且 ssl 握手过程运行良好。

System.setProperty("javax.net.ssl.keyStore", keystorePath);
        System.setProperty("javax.net.ssl.keyStorePassword", CERT_PASSWORD);
        System.setProperty("javax.net.ssl.keyStoreType", "JKS");
        URL myUrl;
        try {
            myUrl = new URL(endpoint);
            HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
            InputStream is = conn.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);

            String inputLine;

            while ((inputLine = br.readLine()) != null) {
                System.out.println(inputLine);
            }

Cert Authorities:
<CN=Autorite Bureau RTE, O=RTE, L=Pacy, ST=Eure, C=FR>
<CN=Autorite Racine RTE, O=RTE, L=Pacy, ST=Eure, C=FR>
<CN=Autorite Bureau Machine RTE, DC=bureau, DC=si, DC=interne>
*** ServerHelloDone
matching alias: alias-cert

我很感激任何帮助。谢谢。

亲切的问候,鲁迪

4

0 回答 0