My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 4914 attachment: SslPeerUpdater.java (1.9 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.lang.reflect.Field;
import javax.net.ssl.SSLEngine;

/**
* Update peer host and port data by using reflection
* in order to fix Android OS bug described here:</br>
* <i>http://code.google.com/p/android/issues/detail?id=4914</i></br>
* </br>
* Important note:</br>
* Use it only in Android OS version 2.1 (Eclair) or older.
* Do not use it in newer versions. There is no need for that
* because this bug in OS is fixed in Froyo.
*
* @author Dragan Marjanovic
*/
public class SslPeerUpdater {

/**
* Usage:</br>
* SskPeerUpdater.updatePeerData(engine, "www.mydomain.com", 443);
*/
public static void updatePeerData(SSLEngine engine, String sslDomain, int sslPort)
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
{
Class<? extends SSLEngine> clsEngine = engine.getClass();
Field fldHandshakeImpl = clsEngine.getDeclaredField("handshakeProtocol"); //get field
fldHandshakeImpl.setAccessible(true); //needed for private or protected fields
Object sHandshakeImpl = fldHandshakeImpl.get(engine); //get field value
Class<? extends Object> clsClientHandshakeImpl = sHandshakeImpl.getClass();
Class<?> clsClientHandshakeImplSuperClass = clsClientHandshakeImpl.getSuperclass(); //get super class
Field fldSession = clsClientHandshakeImplSuperClass.getDeclaredField("session");
fldSession.setAccessible(true);
Object oSession = fldSession.get(sHandshakeImpl);
Class<? extends Object> clsSession = oSession.getClass(); //Class.forName("SSLSessionImpl");
Field fldHost = clsSession.getDeclaredField("peerHost");
fldHost.setAccessible(true);
fldHost.set(oSession, sslDomain); //update field value; change with your domain value
Field fldPort = clsSession.getDeclaredField("peerPort");
fldPort.setAccessible(true);
fldPort.setInt(oSession, sslPort); //change with your port value
}
}
Powered by Google Project Hosting