forked from ruboto/ruboto
-
Notifications
You must be signed in to change notification settings - Fork 0
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:
-----BEGIN CERTIFICATE-----
BASE64 code
-----END CERTIFICATE-----
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)
new_sock.start(Ruboto::R::raw::client)
#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
new_sock.close
end