Secured socket

Put your problem here if it does not fit any of the other categories.

Secured socket

Postby kazy » Wed Mar 16, 2011 2:33 pm

Hello, does anybody know how can I make a secured connection with sockets (not httpget or post) using two classes (not precisely these) EasySSLSocketFactory and the EasyX509TrustManager class to pass the certificate validation...

I need only to instantiate(not sure if this is the word) my socket to work with this trust manager...

I have tried the following code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TrustAllSSLSocketFactory sl = new TrustAllSSLSocketFactory();
  2.        
  3.         socket = sl.createSocket(socket, localaddrstr, port, false);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4

where socket is my connection socket. But with this code I get the following error:

03-16 15:24:55.146: ERROR/AndroidRuntime(15104): FATAL EXCEPTION: AsyncTask #1
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): java.lang.RuntimeException: An error occured while executing doInBackground()
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at android.os.AsyncTask$3.done(AsyncTask.java:200)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.lang.Thread.run(Thread.java:1096)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): Caused by: java.lang.StackOverflowError
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:662)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at java.lang.StringBuilder.toString(StringBuilder.java:664)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at org.apache.harmony.luni.util.Util.toASCIIUpperCase(Util.java:358)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at org.apache.harmony.security.Util.equalsIgnoreCase(Util.java:27)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:92)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at javax.net.ssl.SSLContext.getInstance(SSLContext.java:58)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:18)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>(TrustAllSSLSocketFactory.java:20)
03-16 15:24:55.146: ERROR/AndroidRuntime(15104): at com.sun.mail.util.TrustAllSSLSocketFactory.<init>
...

Thank you !
kazy
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 15, 2011 7:56 am

Top

Re: Secured socket

Postby ruelblapid » Thu Mar 17, 2011 3:03 am

Hi Kazy,

Check this out http://code.google.com/p/transdroid/.

Best,
Ruel B. Lapid
Senior Android Engineer
User avatar
ruelblapid
Experienced Developer
Experienced Developer
 
Posts: 65
Joined: Mon Mar 14, 2011 2:37 am

Re: Secured socket

Postby kazy » Thu Mar 17, 2011 7:19 am

Hi ruelblapid,
They use the TrustAllSocketFactory on the HttpGet/Post and I want to implement it on sockets...

Does anyone know how can I do that?
kazy
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 15, 2011 7:56 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests