尝试通过Java连接到Apple的推送服务器时出现SSL握手错误。

时间:2012-05-03 12:12:24

标签: java ssl apple-push-notifications

我一直在Eclipse / Maven / Jetty项目中尝试来自此question的代码,我从sslSocket.startHandshake()附近的try {}块中获取SSLHandshakeException。我已经尝试将我的.p12文件加载到keyStore以及我的.pem中。它们都不起作用。两者都在我构建的PHP原型中工作。还不清楚这两个用途是否具有相同的密码。

try {
    KeyStore keyStore = KeyStore.getInstance("PKCS12");

    keyStore.load(getClass().getResourceAsStream("cert.p12"), "<password>".toCharArray());
    KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance("SunX509");
    keyMgrFactory.init(keyStore, "<password>".toCharArray());

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyMgrFactory.getKeyManagers(), null, null);
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

    SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(host, port);
    String[] cipherSuites = sslSocket.getSupportedCipherSuites();
    sslSocket.setEnabledCipherSuites(cipherSuites);
    sslSocket.startHandshake();
}catch()...

我已使用

检查了与Apples服务器的连接
openssl s_client -connect gateway.sandbox.push.apple.com:2195

作为回报,我得到以下内容。

CONNECTED(00000003)
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate
verify return:0
18183:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:/SourceCache/OpenSSL098/OpenSSL098-44/src/ssl/s3_pkt.c:1102:SSL alert number 40
18183:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:/SourceCache/OpenSSL098/OpenSSL098-44/src/ssl/s23_lib.c:182:

我不确定发生了什么。有任何想法吗?

0 个答案:

没有答案