【问题标题】:How to avoid java.security.cert.CertificateException with AuthorizeNet connection?如何使用 AuthorizeNet 连接避免 java.security.cert.CertificateException?
【发布时间】:2015-06-11 04:07:19
【问题描述】:

我需要连接 AuthorizeNet 但我得到了:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: 找不到与certificate.authorize.net 匹配的主题替代DNS 名称(请参阅下面的错误跟踪)。

我使用的网址是https://certification.authorize.net/gateway/transact.dll

我的类AuthorizeNet中的连接代码如下:

        URL url = new URL(“https://certification.authorize.net/gateway/transact.dll”);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());

错误跟踪如下:

2015-04-06 13:00:52,592 [ajp-bio-8009-exec-1] 错误 com.aaa.AuthorizeNet:541 - javax.net.ssl.SSLHandshakeException:java.security.cert.CertificateException:没有找到与certificate.authorize.net匹配的主题备用DNS名称。 在 sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 在 sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884) 在 sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276) 在 sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270) 在 sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341) 在 sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153) 在 sun.security.ssl.Handshaker.processLoop(Handshaker.java:868) 在 sun.security.ssl.Handshaker.process_record(Handshaker.java:804) 在 sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016) 在 sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) 在 sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339) 在 sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) 在 sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) 在 com.aaa.AuthorizeNet.startNetConnection(AuthorizeNet.java:533)

【问题讨论】:

标签: java security connection authorize.net


【解决方案1】:

我使用旧 URL 进行连接,这给出了错误。新的真实 URL 是https://secure.authorize.net/gateway/transact.dll。然后需要从 AuthorizeNet 获取 LoginID 和 transaction Key。如果您是商家,您可以获得允许您测试交易的 LoginID/TransactionKey

【讨论】:

    【解决方案2】:

    通过使用这些额外参数运行客户端解决了这个问题:-Djavax.net.debug=ssl,handshake 参考:Paypal SSLHandshakeException

    在另一种情况下,下面的 sn-p 帮助我解决了这个问题:

    urlCon.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session){
            return true;
        }
    });
    

    【讨论】:

    • 如果是第二种解决方案,请尝试使用 HttpsURLConnection 而不是 URLConnection。
    猜你喜欢
    • 2012-05-23
    • 2014-11-18
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2018-07-07
    相关资源
    最近更新 更多