powered by Jive Software

Plugin connecting to another server with SSL certificate

Hello all,

I am a newbie in openfire plugin development. So please bear with me if I am stuck with something trivial.

I have to develop a plug-in which establishes a TLS connection to an existing server (not XMPP). I have the certificate and private key in a .p12 file and I am loading them using the following lines of code:

SSLSocketFactory factory = null;
            try {
                 SSLContext ctx;
                 KeyManagerFactory kmf;
                 KeyStore ks;
                 char[] passphrase = password.toCharArray();                  ctx = SSLContext.getInstance("TLS");
                 kmf = KeyManagerFactory.getInstance("SunX509");
                 ks = KeyStore.getInstance("PKCS12");                  ks.load(new FileInputStream(certificateAndKey), passphrase);                  kmf.init(ks, passphrase);
                 ctx.init(kmf.getKeyManagers(), null, null);                  factory = ctx.getSocketFactory();
            } catch (Exception e) {
                 e.printStackTrace();
                 throw new IOException(e.getMessage());
            }             SSLSocket socket = (SSLSocket)factory.createSocket(staticHost, staticPort);             socket.startHandshake();

The variable certificateAndKey is the path to my .p12 file. Everything is fine when I use the absolute path of the .p12 file. However when I use the relative path I don’t know where I am supposed to put the certificate file. When I put it inside the main directory of my plugin it does not get packaged into the jar file and does not get deployed. I’ve also tried manually copying the file to various locations in my openfire installation (target/openfire, target/openfire/plugins, target/openfire/my_plugin, target/openfire/my_plugin/lib) but I always get a FileNotFoundException.

What is the proper way to achieve what I am trying to do?

Thanks a lot…