不能重用SSLsession问题
Android 2.3有个bug,需要重新改造SSLSocketFactory,把socket中的impl对象实例中注入带host信息的InetAddress及port。样例代码如下:
@Override
public Socket createSocket(Socket socket, String host, int port,
boolean autoClose)throws IOException, UnknownHostException {
Socket sk = xx.getSocketFactory().createSocket(socket, host, port, false);
//特殊解决方案,解决android 2.3 SSL不能重用session问题
try {
Field implFiled = Socket.class.getDeclaredField("impl");
implFiled.setAccessible(true);
SocketImpl impl = (SocketImpl) implFiled.get(sk);
Field addFiled = SocketImpl.class.getDeclaredField("address");
addFiled.setAccessible(true);
addFiled.set(impl, InetAddress.getByName(host));
Field portFiled = SocketImpl.class.getDeclaredField("port");
portFiled.setAccessible(true);
portFiled.set(impl, port);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return sk;
}