私はAndroidが初めてです。アプリケーションの場合、Android でプレーン TCP ソケットを SSL ソケット (サーバー モード) にアップグレードする必要があります。次のコードは機能しましたが、Android 2.3.3 (API 10) を搭載した Samsung Galaxy S で SSL ハンドシェイクを完了するのに約 12 秒かかりました。Android 4.0.3 (API 15) のシミュレーターでも同じコードをテストしましたが、結果は同じでした。クライアントは Chrome ブラウザーでした。Wireshark トレースから、すべての SSL ハンドシェーク メッセージが非常に速く流れ、暗号仕様の変更/暗号化ハンドシェーク メッセージ (サーバー側での SSL ハンドシェークの最後の 2 つのメッセージ) と最初のアプリケーション データ (それはクロムからの HTTP GET)。
private boolean handleSSLHandshake() {
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(this.kmf.getKeyManagers(), null, null);
SSLSocketFactory factory = sc.getSocketFactory();
this.sslSocket = (SSLSocket) factory.createSocket(this.socket,
this.socket.getInetAddress().getHostAddress(),
this.socket.getPort(),
true);
this.sslSocket.setUseClientMode(false);
this.sslSocket.addHandshakeCompletedListener(this);
this.sslSocket.startHandshake();
Log.d(TAG, "SSL upgrade succeeds!");
this.input = this.sslSocket.getInputStream();
this.output = this.sslSocket.getOutputStream();
} catch (NoSuchAlgorithmException e) {
Log.d(TAG, "Got NoSuchAlgorithmException while upgrading to SSL" + e);
this.sslSocket = null;
return false;
} catch (KeyManagementException e) {
Log.d(TAG, "Got KeyManagementException while upgrading to SSL" + e);
} catch (UnknownHostException e) {
Log.d(TAG, "Got UnknownHostException while upgrading to SSL" + e);
this.sslSocket = null;
return false;
} catch (IOException e) {
Log.d(TAG, "Got IOException while upgrading to SSL" + e);
this.sslSocket = null;
return false;
}
return true;
}
public void handshakeCompleted(HandshakeCompletedEvent event) {
Log.d(TAG, "SSL handshake completed");
}
どのコードに 10 秒かかったのか、誰にもわかりませんか? これを減らす方法は?AndroidでSSLハンドシェイクをデバッグする方法は?
助けてくれてどうもありがとう、
/カイドゥアン