0
我無法與Ingenico iPP320設備建立SSL/TLS連接。我曾嘗試解決建議here但我得到這個錯誤iOS上的TLS連接swift握手問題
CFNetwork SSLHandshake failed (-9824 -> -9829)
我是新來使用SSL/TLS連接,不知道應該怎麼去建立連接。我使用的是一個受密碼保護的p12文件,證書也不是自簽名的。我被告知服務器也必須認證客戶端,因此中間和根CA可能必須發送到服務器。我能夠在Android上使用身份驗證,但我不確定如何在iOS中執行此操作。
下面是可用的Android代碼。
public SSLSocket createSSLSocket(String ipAddress, int port)
{
try
{
SSLSocket socket = null;
String certStorePassword = "password";
String certStoreType = "pkcs12";
InputStream iStream = getResources().openRawResource(R.raw.clientP12File);
KeyStore keyStore = KeyStore.getInstance(certStoreType);
keyStore.load(iStream, certStorePassword.toCharArray());
// KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, certStorePassword.toCharArray());
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(keyManagerFactory.getKeyManagers(), trustAllCerts, new SecureRandom());
SSLContext.setDefault(sc);
SSLSocketFactory factory = sc.getSocketFactory();
socket = (SSLSocket) factory.createSocket(ipAddress, port);
socket.setEnabledProtocols(new String[] { "TLSv1.2" });
socket.setUseClientMode(true);
socket.startHandshake();
return socket;
}
catch (Exception ex) {
Log.e(TAG, "createSSLSocket: ", ex);
}
return null;
}