Eventmachine SSLSocket Client using keystore in Ruby or Jruby

I want to move to non blocking i/o from java to eventmachine or any
evented io framework like nodejs. Here is a sample code i have from java
to create a SSLSocket client and then perform to and fro data transfer.
I want to switch to eventmachine as i have lot of headaches managing the
java code eg. detecting socket disconnection etc.

How do i create a SSLSocket client in eventmachine

public SSLSocket createSocket(String ip, int port)
{
//Socket socket;

try{
    KeyStore localKeyStore = KeyStore.getInstance("JKS");

    char[] localKeyStorePassword = "xxxxxxx".toCharArray();
    //localKeyStore.setCertificateEntry("", "");

    localKeyStore.load(new FileInputStream("cert/sample-keys"),

localKeyStorePassword);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(“SunX509”);
kmf.init(localKeyStore, localKeyStorePassword);
TrustManagerFactory tmf =
TrustManagerFactory.getInstance(“PKIX”);
tmf.init(localKeyStore);
SecureRandom secureRandom = new SecureRandom();
secureRandom.nextInt(); // Force initialisation to occur now.
SSLContext sslContext = SSLContext.getInstance(“TLS”);
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
secureRandom);
SSLSocketFactory sf = sslContext.getSocketFactory();
return (SSLSocket)sf.createSocket(ip, port);
}
catch(Exception kse)
{
kse.printStackTrace();
return null;
}
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs