Certificate problems with Android Apps

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Hey all,

So here is my problem. I wrote a program using the api, as a desktop application, and it all worked fine, no problems.

I decided to expand it and turn it into an android application as well. The program still works as a desktop application but when I try to run it as an android application, it has problems with the certificate.

I have tried using both jGW2API’s hard coded certificate, and the attached ca.cer file for my certificate, but both times the logcat tells me that there is not enough data in the certificate(input stream to be specific).

Anyone know why this is happening/how I can solve it?

Rurik

subnote: Cannot attach .cer file, changed it into .txt file via editing the extension. I hope this doesnst cause any issues.

Attachments:

Certificate problems with Android Apps

in API Development

Posted by: Rasman.7812

Rasman.7812

I had the same problem, so i just deleted the certificate. That worked for me.
Also remember to add the INTERNET persmission in your manifest file.

Certificate problems with Android Apps

in API Development

Posted by: Tanis.5134

Tanis.5134

I am successfully using the API in an Android app without manually specifying or installing a certificate.

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Strange, I was under the assumption that with it being a https: connection, it would require a certificate, also I am pretty sure it gave me troubles when i tried to connect without a certificate.

But I will give it a try and see what happens.

As a side not, where in the manifest should I put the INTERNET tag?

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Never mind, google did the trick. Thanks for the help. Now I will just need to work on speeding it up somehow.

Certificate problems with Android Apps

in API Development

Posted by: Goddchen.4958

Goddchen.4958

HttpsURLConnection seems to be able to handle the HTTPS connection just fine without any further config.

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Hmm so I dont know whats happened, but since fixing this issue, my pc application version no longer works, with a:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target error.

while my android app is once again having problems, but this time an IO exception with logcat giving a warning that there is an SSLException, stating Not Trusted Server Certificate… android frustrates me

Certificate problems with Android Apps

in API Development

Posted by: Yamagawa.5941

Yamagawa.5941

I don’t think it’s you. Or rather, I don’t think you caused the error:
https://forum-en.gw2archive.eu/forum/community/api/HTTP-access/first#post2236704

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

No its definitely not on my end, as my precompiled (weeks ago) program wont work either. Something is definitely going wrong with the server, and it is probably the Worlds List bug.

Or it could be the new certificate they are running, interesting. (probably it, as the old hard coded certificate in my pc program would no longer be correct)

(edited by Rurik Telmonkin.3648)

Certificate problems with Android Apps

in API Development

Posted by: Yamagawa.5941

Yamagawa.5941

Updates in the other thread. They got a new key issued from a more widely accepted root authority. You can probably axe most/All your SSL specific code.
//Yamagawa

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Yes, the new certificate fixed the pc version issues certainly. However my android version is still giving me warnings about not having a secure ssl cert, as well as an IOException when grabbing world names. I suspect that the latter is the null world causing issues.

EDIT
hmm, it seems to definitely be a server issue that I cannot change or fix on my end, as the IO exception is being caused by this.httpsConnection.getInputStream().

I know its not an issue on my end as I use the same thing for two different calls and only one is failing, that being the one grabbing world names.

(edited by Rurik Telmonkin.3648)

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Hmm interesting, it seems is was failing on the first call, it just wasnt notifying me because the second call overwrote it. So for some reason, all my calls to the api are failing with an IOException in my android app, with a warning of an SSL Exception saying No Trusted Server Certificate, and a CertificateException stating that TrustAnchor for CertPath not found.

Whats strange is that these work perfectly on the pc version of the app and I just dont know what could be going wrong.

Certificate problems with Android Apps

in API Development

Posted by: Cliff Spradlin.3512

Cliff Spradlin.3512

Lead Programmer

Hmm interesting, it seems is was failing on the first call, it just wasnt notifying me because the second call overwrote it. So for some reason, all my calls to the api are failing with an IOException in my android app, with a warning of an SSL Exception saying No Trusted Server Certificate, and a CertificateException stating that TrustAnchor for CertPath not found.

Whats strange is that these work perfectly on the pc version of the app and I just dont know what could be going wrong.

Can you post the code relevant to setting up SSL and connecting to the API?

Also, what happens when you visit an API url on your mobile browser? Is there a certificate error?

(edited by Cliff Spradlin.3512)

Certificate problems with Android Apps

in API Development

Posted by: Goddchen.4958

Goddchen.4958

Certificate problems with Android Apps

in API Development

Posted by: Healix.5819

Healix.5819

Whats strange is that these work perfectly on the pc version of the app and I just dont know what could be going wrong.

I’m assuming the “pc version” is basically the same program and not an entirely different one? If your Android device is version 2.2 or below, it doesn’t trust GeoTrust’s certificate. It should however trust their old (Equifax) certificate, in which case ArenaNet could update theirs to point to that one as a workaround (http://www.geocerts.com/support/cross_root).

And here’s a workaround for you:

Download GeoTrust Global CA certificate (or, direct pem link) and place it in your resources.
When creating the HTTPS connection, set it up to trust that CA.

An example can be found in the tutorial (Unknown certificate authority):
http://developer.android.com/training/articles/security-ssl.html#UnknownCa

(edited by Healix.5819)

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Thank you Healix, that would be the problem, I have minimum sdk set to 2.2.

I will try out that cert later and hopefully it will work.

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Hmm interesting, it seems is was failing on the first call, it just wasnt notifying me because the second call overwrote it. So for some reason, all my calls to the api are failing with an IOException in my android app, with a warning of an SSL Exception saying No Trusted Server Certificate, and a CertificateException stating that TrustAnchor for CertPath not found.

Whats strange is that these work perfectly on the pc version of the app and I just dont know what could be going wrong.

Can you post the code relevant to setting up SSL and connecting to the API?

Also, what happens when you visit an API url on your mobile browser? Is there a certificate error?

It works fine on my mobile browser, I assume because of what Healix said below, that my app is running on 2.2 which doesn’t support geotrust naturally, but I can get around that easy enough.

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Well, after re-enabling file based cert files it has, instead of catching errors and running ahead, is crashing.

I am using the original version of jGW2API as my base for api calls, with the only major difference being the following lines in the StartComSSLSocketFactory.java:

private static Context thisContext = MenuActivity.context;

private StartComSSLSocketFactory()
throws CertificateException, NoSuchAlgorithmException,
KeyStoreException, IOException, KeyManagementException {
super(readTxt()/StartComSSLSocketFactory.StartComRootCertificate/, “StartCom”, “X.509”, “X509”);
this.sslSocketFactory = this.sslCon.getSocketFactory();
}

private static InputStream readTxt() throws IOException{
//AssetManager res = thisContext.getAssets();
InputStream in = thisContext.getAssets().open(“ca.pem”);
return in;
}

and the problem seems to be that it cannot see the ca.pem file, despite it being in the assets folder. Until I figure out why its not finding that file, I won’t be able to see if it was my running on 2.2 that was affecting it.

The obvious solution to this, is to redo my project using sdk 2.3+ as the minimum, but I would rather not do that if avoidable

EDIT:
Well somehow I just managed to screw up and lose all my work, so I am gonna start again on gingerbread sdk, hopefully I wont run into these problems again

(edited by Rurik Telmonkin.3648)

Certificate problems with Android Apps

in API Development

Posted by: Varonth.5830

Varonth.5830

You don’t need a StartCom SSLSocketFactory anymore.
In fact, the socket factory generated by my SSL Helper class sets up factories which provide SSL sockets for a single certificate.
If the server you are connecting to isn’t using that certificate directly or as part of its certificate chain, than these sockets will refuse the connection (which in that case is the correct behavior for these sockets).

With the change to GeoTrust from StartCom as certificate authority StartCom SSLSockets will refuse the connection.

Instead you can just use the default SSLSocketFactory of your java implementation (GeoTrust should really be included in any Java implementation, including the Dalvik VM used by Android).
Latest version, which I uploaded does exactly that, and it works just fine.

Certificate problems with Android Apps

in API Development

Posted by: Rurik Telmonkin.3648

Rurik Telmonkin.3648

Well huzzah, with the change to 2.3.3, it is pulling in data just fine. Now just to work out all the other bugs and issues that will undoubtedly occur. But that is for me to figure out on my own thanks all