Well it’s been a couple of days since my last post and now I’m wondering if anyone is listening here.
I have an update on my findings with the latest WordPress for Android 2.1 build. It seems the problem I’m having isn’t a threading issue but rather a problem using SSL from an Android Virtual Device.
I’m sure anyone doing development here that doesn’t have an actual Android device knows about the AVD which comes with the Android development kit. Well this is my primary development environment since I don’t have an Android device handy.
As such, it’s kind of a big problem for SSL not to work when communicating with the WordPress service. I found an article dating back to 2009 which mentions that there was a problem using the WordPress RSD service when using SSL. Apparently this was causing intermittent problems when devices would attempt to discover information about WordPress and it was reported that the service would take upward of 3 minutes or more to respond which was causing the system level timeouts to abort the connection attempt.
Although haven’t discovered the exact location of the problem in the WordPress for Android 2.1 code base it seems like it’s probably around the call “getXMLRPCUrl” in AddAccout which attempts to use RSD to get the proper url. I’ve found that if I just hard code it to use “http://wordpress.com/xmlrpc.php” instead of letting it discover the preferred url, the problem goes away.
Perhaps this is a problem specifically with using the AVD environment and the Eclipse debugger but it’s still too soon for me to say. If anyone has had this problem and has a suggestion on how to work around it without modifying the codebase, please let me know.
Again, patiently awaiting a response.
Thanks in advance!
Dan 10:05 am on May 11, 2012 Permalink | Log in to Reply
The AVD has always been able to connect up just fine for me, I can add accounts without issue. Lately, the BlackBerry app has been having some problems with SSL and WordPress.com. Could be related. Where are you from? I wonder if it’s something that doesn’t work in certain areas.
wssemtech 10:39 am on May 11, 2012 Permalink | Log in to Reply
That’s an interesting question, Dan. I’m in Las Vegas, Nevada.
I’m still on the fence whether it’s my issue or a problem with the application but I just started doing Android development so I have to lean towards it being my issue at this point. Fortunately I seem to be getting to the bottom of it and it definitely seems to be an issue with configuring SSL on an AVD. I was just about to look into configuration of SSL on an AVD as I saw your post.
So, if you have any advice on this topic, it would be appreciated but regardless that’s what’s I’m looking into next.
I’ve found that if I just disable the code that uses RSD to get the preferred url, I’m now able to add an existing WordPress hosted blog to my Android application but I’m also finding that once inside the dashboard other functions do not work because SSL is not working properly on the AVD I’ve created.
So, if you don’t have any advice for me, it’s understandable as it may just be an issue on my end. I’ll let you know if I find the problem and I’ll be sure to post a follow up to let anyone else getting setup to develop on this project know what they need to do to properly configure an AVD for use with the WordPress for Android application.
Dan 10:46 am on May 11, 2012 Permalink | Log in to Reply
Yeah, I’m afraid it’s just ‘always worked’ for me. I am using Eclipse on OS X if that helps at all.
Are you adding a WordPress.com blog to the app through the ‘Add a blog hosted at WordPress.com’ button?
That process doesn’t even need to use RSD since we already know the XMLRPC url for WordPress.com.(edit: looks like it uses RSD for WordPress.com anyways)wssemtech 10:53 am on May 11, 2012 Permalink | Log in to Reply
Yes, the second option on the menu, or using the “wpcom==true” flag if you’re looking at it from the perspective of the source code.
Yes, you’re right it doesn’t need RSD, but since I got past that problem I’m seeing that there are other problems using SSL in my environment so I’ll have to work through those issues to say for sure where the problem lies.
I really appreciate you taking the time to respond though!
I was wondering if this was still an active blog. I know you’re just releasing this 2.1 version as beta right now so I figured maybe everyone was taking a break.
By the way, just so you know I’ve been developing software for over 15 years so I’m not new to trouble shooting issues like this but this is the first time (or actually second time) that I’ve worked with anyone from the open source community so I’m still kind of feeling my way around.
For instance, I’m trying to get setup on the TracWiki and I’m having trouble figuring out how to enter a ticket there.
So any advice along those lines would also be very helpful if you have time.
Dan 10:57 am on May 11, 2012 Permalink | Log in to Reply
No problem! In order to enter a new ticket you’ll need to get a login over at WordPress.org: http://wordpress.org/support/register.php
Then you can sign in at the trac site and a ‘New Ticket’ button will appear.
wssemtech 12:14 pm on May 11, 2012 Permalink | Log in to Reply
Dan, thank you very much. I will check that out as soon as I get to the bottom of this problem.
By the way, I think I’ve just made a significant discovery in resolving my issue. This article may be of particular interest to anyone using an AVD for testing the WordPress for Android codebase.
http://intrepidusgroup.com/insight/2011/08/setting-up-a-persistent-trusted-ca-in-an-android-emulator/
This actually applies to anyone using the AVD with any application that uses SSL.
wssemtech 8:36 am on May 13, 2012 Permalink | Log in to Reply
Dan, I think I might’ve found the offending code which has been eluding me all weekend.
public TrustAllSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
super(null);
try {
SSLContext sslcontext = SSLContext.getInstance(“TLS”);
sslcontext.init(null, new TrustManager[] { new TrustAllManager() }, null);
factory = sslcontext.getSocketFactory();
setHostnameVerifier(new AllowAllHostnameVerifier());
} catch(Exception ex) { }
}
If you notice the top of this constructor which is used only when you attempt to make an SSL connection is passing “null” to the parent class’s constructor.
Well the parent class has two different constructors which have one “object” parameter so which one should it be using for construction? I’m sure that it uses the first one in natural order which would happen to be the constructor which takes a key store.
Well here’s the problem, if I do a network trace of the communication I’m finding that there’s always a cipher negotiation. I’m thinking that it’s failing because there is no keystore specified.
You sould it expect it to just throw an exception but apparently it runs along fine until we try to decipher the data in which case it just throws up it’s hands and says there was no connection in the first place.
I also found another article stating that in the HttpClient classes, they are now more prone to throw this particular exception in cases where a recoverable error in encountered. I’ll have to dig into the source for HttpClient now to figure out if that is in fact the source of the problem I’m seeing but after looking at this code I’m pretty sure there is a very real and possibly intermittent problem with this application.
Please let me know if you have any insight into this particular class.
The class is “TrustAllSSLSocketFactory”.
Dan 11:09 pm on May 13, 2012 Permalink | Log in to Reply
That class was added so that the app would work with self-signed SSL certificates. It was added a long time ago, I think it came from here: http://www.java2s.com/Open-Source/Android/Framework/imogene/org/imogene/android/util/http/ssl/Catalogssl.htm
I’m no expert on HttpClient I’m afraid, I wish I had more help to offer you. If you do find the root of the problem, patches are welcome
Which version of Android are you running in the emulator by the way?
wssemtech 9:45 am on May 14, 2012 Permalink | Log in to Reply
Dan,
Thanks again for your insight. I am digging deep to get to the root of this problem because it’s critical for me to be able to continue working with this code base in my development environment. Someone has mentioned that Sony is now offering a 30 day lease plan for equipment which I may try out in the future but for now I think I’m still making progress on working toward a solution for this particular issue.
I apologize for my verbose and frequent updates but I must defer to those with more experience at this point to understand whys and wheres of this code base. As such I may have jumped to hasty conclusions so please don’t be insulted if I may be pointing my finger in the wrong direction but after doing some exhaustive analysis using network traces from the AVD and Wireshark I’m finding that the main difference between a successful transaction and a failed one is simply that the server really doesn’t respond to the first encrypted query. I can follow the SSL handshake which according to my findings is occurring successfully but when the first encrypted message is sent, the server simply doesn’t respond. My next step will be to see if the return message is simply being consumed by another network device. I have to consider at this point that there might be an issue with my network configuration because the AVD has it’s own internal virtual router but I’m also running behind an actual router on our network.
The part the perplexes me the most is that I’m able to get all of the network calls to work fine when I just extract the necessary classes from the WordPress for Android codebase and run them in a separate project. It’s only when I run the WordPress for Android project itself that the communication fails.
I do appreciate all of your insight, feedback and support. I will definitely try to get a fix into the code base if it is indeed a fix that is necessary. If not then at least I will have learned something new about Android development and hopefully can share my experience.