otr4j is part of my GSoC 09' project and is encouraged by the SIP Communicator development. otr4j is an implementation of the OTR (Off-the-Record) protocol in java.

Thursday, April 30, 2009

Create a simple plugin for SipCommunicator with an external library and debug in Eclipse

Setting up the library project

  • Create a new java project that will host your library, this will be our foo4j lib. Make sure you create a proper project layout (folder structure) for you project, in order for the ant buildfile in step 3 to work.

  • Create a foo class with two dummy methods like this:

    package net.java.foo4j;

    public class Foo {
    public void helloWorld() {
    System.out.println("Hello World!");
    }

    public void byeWorld() {
    System.out.println("Bye World!");
    }
    }
  • Create a build.xml (ant buildfile) like the one bellow to produce a foo4j.jar file and build the project.

    <?xml version="1.0" ?>

    <project default="main" name="otr4j">
    <property name="src.dir" value="src" />
    <property name="build.dir" value="bin" />
    <property name="classes.dir" value="${build.dir}/classes" />
    <property name="jar.dir" value="${build.dir}/jar" />
    <target name="clean">
    <delete dir="${build.dir}" />
    </target>
    <target name="main" depends="compile, compress"
    description="Main target">
    <echo>
    Building the .jar file.
    </echo>
    </target>
    <target name="compile" description="Compilation target">
    <mkdir dir="${classes.dir}" />
    <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" />
    </target>
    <target name="compress" description="Compression target">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar"
    basedir="${classes.dir}" />
    </target>
    </project>

Setting up SipCommunicator

Our plugin will be build as an OSGi bundle. What helped me understand OSGi, is Clement Escoffier's paper "Developing an OSGi-like service platform for .NET", just skip all the .NET stuff.

In this paper you can find a high level overview of the OSGi framework. there are various sources on the web that can help you better
understand OSGi once you get the high level picture.

For the purpuses of this mini-guide, our strategy will be to build an OSGi bundle, and plug it into SipCommunicator. This OSGi -plugged in SipCommunicator- bundle will be our plugin, so I may use the term bundle and plugin interchangibly.

  • Edit the properties of SipCommunicator project and add foo4j project in the Java Build Path.
  • Create a class (FooActivator) that will implement the BundleActivator Interface. This class will handle the starting and stopping of our plugin.
     
    package net.java.sip.communicator.plugin.foo;

    import org.osgi.framework.BundleActivator;
    import net.java.foo4j.Foo;

    public class FooActivator implements BundleActivator {
    @Override
    public void start(BundleContext arg0) throws Exception {
    Foo foo = new Foo();
    foo.helloWorld();
    }

    @Override
    public void stop(BundleContext arg0) throws Exception {
    Foo foo = new Foo();
    foo.byeWorld();
    }
    }
  • Create the manifest for you bundle

    Bundle-Activator: net.java.sip.communicator.plugin.otr.FooActivator
    Bundle-Name: The infamous foo plugin!
    Bundle-Description: A plug-in that will help burgers accomplish their master plan to rule the world.
    Bundle-Vendor: sip-communicator.org
    Bundle-Version: 0.0.1
    System-Bundle: yes
    Export-Package: net.java.sip.communicator.plugin.foo,
    net.java.foo4j,
    Import-Package: net.java.sip.communicator.service.protocol,
    net.java.sip.communicator.service.protocol.event,
    net.java.sip.communicator.util,
    org.osgi.framework
    Pay attention that our bundle exports the net.java.foo4j package.
  • Edit SipCommunicator's build.xml and add an ant build target for our bundle

    <!-- BUNDLE-PLUGIN-OTR -->
    <target name="bundle-plugin-otr">
    <!-- Creates a bundle for the plugin OTR.-->
    <jar compress="false" destfile="${bundles.dest}/otr-plugin.jar"
    manifest="${src}/net/java/sip/communicator/plugin/otr/otr.manifest.mf">
    <zipfileset dir="${dest}/net/java/sip/communicator/plugin/otr"
    prefix="net/java/sip/communicator/plugin/otr"/>
    <zipfileset dir="PATH_TO_FOO4j_PROJECT/bin/jar/foo4j.jar"
    prefix="net/java/foo4j"/>
    </jar>
    </target>
    Make sure that you change PATH_TO_FOO4j_PROJECT
    to something meaningful.


We're done, now you should be able to debug SipCommunicator as it described in the official guide here.

Thursday, April 23, 2009

Initial Commit err.. Thoughts!

Hello World!

In this post, I will try to present my initial thoughts on how will I be implementing the OTR messaging project.

OTR Protocol Very High Level Overview

OTR assumes a network model which provides in-order delivery of messages, but that some messages may not get delivered at all (for example, if the user disconnects). There may be an active attacker, who is allowed to perform a Denial of Service attack, but not to learn the contents of messages.

  • Alice signals to Bob that she would like (using an OTR Query Message) or is willing (using a whitespace-tagged plaintext message) to use OTR to communicate. Either mechanism should convey the version(s) of OTR that Alice is willing to use.

  • Bob initiates the authenticated key exchange (AKE) with Alice. Version 2 of OTR uses a variant of the SIGMA protocol as its AKE.

  • Alice and Bob exchange Data Messages to send information to each other.

This text is taken from the OTR protocol description here.

Implementation

Overview

I plan to split my development efforts into two parts. The first part will be building a new reusable Java library for OTR (otr4j) and the second part incorporating that library in SipCommunicator.

Java library for OTR - otr4j

OTR4j architecture will be service driven, i.e. you have a state object, e.g. OtrlUserState, that you pass over to a service, e.g. MessageServiceImpl, with other required parameters for the service to work. I have already uploaded a skeleton of the library in Google Code http://code.google.com/p/otr4j/. Nothing functional yet, just a bunch of interfaces that may change in the future.

SipCommunicator Integration

SipCommunicator is build on top of Felix, so it makes sense to integrate the otr4j via an OSGi bundle, therefore the integration should be as simple as creating an OtrActivator class (I don't include it here because it would make the post too lengthy... )
This class is only a tiny tiny tiny (...) draft of the final OtrActivator and it doesn't have any GUI hooks, it just implements the BundleActivator interface that is required for the class to be an OSGi bundle and MessageListener and ServiceListener to hook to the inbound/outbound message traffic.

All of the above writing is “near to theory”, issues for further discussion will arise as soon as actual coding starts.

My Commits to SIP Communicator

Mercurial commits to project otr4j on Google Code