Tutorial: Socket SSL

lucaspiressimao edited this page Oct 25, 2013 · 17 revisions

First off all, you need to insert the keys in you project. For this case we used One-Way SSL authentication Use the client certificate, that there are two entries:


BASE64 code


For this example:

1- create a new folder /res/raw inside the project

2- Download the file http://www.java2s.com/Code/JarDownload/bcprov/bcprov-jdk16-1.45.jar.zip

3- insert the certificate to project with the command:

keytool -importcert -v -trustcacerts -file "/path/to/certificate/ca.crt" -alias IntermediateCA -keystore "res/raw/client.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "/path/to/jarfile/bcprov-jdk16-145.jar" -storetype BKS -storepass (password)

4- Paste SocketSSL.java and MySSLSocketFactory.java inside your project

download here https://gist.github.com/lucaspiressimao/6467806

5- call all requires inside you main file Activity

require 'java'
java_require 'yourpath/SocketSSL'
java_import "yourpackage.SocketSSL"

Now you are ready to use it. How to?

Create a new thread

 @eth_thread = Thread.with_large_stack(512) 
      #create a new socket - pass the context      
      new_sock = SocketSSL.new(self)

      #here you need to create something to wait the socket load CA it will take 1 or 2 seconds
      #Send message
      new_sock.send("Hello World")
      #read it
      retorno = new_sock.receive
      #and close
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.