我正在尝试为iPhone实现一个独立的应用程序;我希望为iPhone客户端使用Apple推送通知。 我收到了javax.net.ssl.SSLHandshakeException:Received fatal alert: unknown_ca错误提示。
以下是我的Java代码连接到apns网关:
int port = 2195;
String hostname = "gateway.sandbox.push.apple.com";
char[] passwKey = "password".toCharArray();
KeyStore ts = KeyStore.getInstance("PKCS12");
ts.load(new FileInputStream("/path/to/file/Cert.p12"), passwKey);
KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509");
tmf.init(ts, passwKey);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(tmf.getKeyManagers(), null, null);
SSLSocketFactory factory = sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket(hostname,port);
String[] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
//start handshake
socket.startHandshake();
请帮忙理解 SSL 证书在 Linux 机器上如何安装。
编辑:
现在它对我有用了,我重新创建了 Cert.p12 文件,程序开始工作了。我不知道导致它不起作用的确切原因是什么,但我猜测可能是 Cert.p12 文件损坏了。
感谢大家的帮助。