Friday, September 20, 2013

Running a JAR as a service using upstart

It is very simple to run JAR file as a daemon in latest version of linux using upstart script.Instead of creating a script in /etc/init.d, as with System-V init, you create a .conf file in /etc/init folder. Then upstart takes care of running it as a service.

This example for a 'sample' service for a sample.jar located in /usr/local/ folder( you can put jar anywhere in system, but always use absolute path)

Create a sample.conf file in /etc/init in following syntax


description "sample service" 
author "Jinesh" 

start on runlevel [3] 
stop on shutdown 

expect fork 

script 
      java -jar /usr/local/sample.jar
      emit sample_running 
end script 

Then you can start service using

service sample start

and stop using

service sample stop

Thursday, August 1, 2013

MQTT Java Publisher and Subscriber using Eclipse Paho


MQTT is a one of most popular machine-to-machine (M2M) connectivity protocol. It was designed with extremely lightweight that support embedded and low power processing device. MQTT popularly used in samrtphone chat application and sensor communication. You can find more information about MQTT from here. MQTT is broker based message queuing system. It is very to install open Source MQTT server like Mosquitto using a simple apt-get or yum command.

sudo apt-get install mosquitto
Eclipse Paho is one mqtt client work well with mosquitto. The below MQTT subscriber and publisher code based on java eclipse paho library 1.0.1. You can also use public mosquitto server in http://test.mosquitto.org/

MQTT subscriber


MQTT publisher



Complete eclipse project https://bitbucket.org/mkjinesh/mqttclient

Tuesday, April 23, 2013

Gvfs upgrade for MTP support in ubuntu 12.04

Starting with Android 4.0 Ice Cream Sandwich, the OS does not support Mass Storage Device interface for USB data transfer. It use MTP for phone storage access via USB . It cause some difficulty in Ubuntu 12.04/12.10 for browsing and copying via USB. You can mount the SD card and phone storage, but its only display the first level folder. You can't browse the any file inside it because 12.04 and 12.04 shipped without MTP sppport

Upgrade Gvfs for MTP support

1. Add the the langdalepl/gvfs-mtp' PPA to your sytem.
sudo add-apt-repository ppa:langdalepl/gvfs-mtp
sudo apt-get update
2. Lanuch update manger and install all updates from LP-PPA-langdalepl-gvfs-mtp or use 'apt-get upgrade'


3. Restart your system and connect your device. You can mount the SD card and browse the files using ubuntu file browser.

Tuesday, March 26, 2013

Paper Review:- The most dangerous code in the world: validating SSL certificates in non-browser software


Authors: M. Georgiev, S. Iyengar, S. Jana, R. Anubhai, D. Boneh, and V. Shmatikov

SSL is a common standard used by Internet community for secure communication. Now a days SSL provides a critical role in many application like banking, sensitive data transfer etc. The core concepts of of SSL depends on the certificate provided by the server during the initial connection establishment. This paper reveals the security flows in many security critical application and libraries due to the improper use of SSL functions. Many of these vulnerability is due to the badly designed APIs in SSL data transport implementation. Most of SSL implementation APIs expose the low level details to application programmers. The common application developers are unaware of options and other parameters in SSL implementation. These leads to the incorrect use of SSL functionality in the application.
Chain-of-trust verification and Host name verification are the two important steps in SSL handshake. This paper give a detailed analysis on this area based on some commonly used libraries and APIs. OpenSSL and JSSE are the most commonly used libraries for SSL abstraction. But both libraries are only covered certification verification part of SSL handshake. Application programmers are need to implement host name verification part by themselves on their application. The non-standard use of these functionality introduce serious vulnerability in SSL communication. Data transport libraries like cURL and Apache httpclient also use the same libraries to achieve SSL capability. SSL tunels are widely used non-browser environment like Cloud Client API, Merchant payment SDK, Web servicing middle ware etc. These applications are security critical because of the nature of data they are handling . Paper also present a experiment conducted based on the vulnerability found on basic libraries and APIs. They are succeeded to perform man-in the middle attack in many application including Amazone Flexible Paymant Gateway,Lynx,Paypal IPN etc.
These paper tries to convey a warning to application developers and APIs Developers. APIs developers must wrap the basic functionality of underlaying system and application developers must study the APIs functionality and options before using them.

Thursday, March 21, 2013

Install TinyOS 2.1.1 in ubuntu 12.04

TinyOS is a open source operating system for low power wireless device used in sensor networks,person area network, smart meters etc. You can find more information about tinyos from here

These configurations are done for tiny os  2.1.1 for micaz mote

Open /etc/apt/sources.list and add the following line at the end of file.

deb http://tinyos.stanford.edu/tinyos/dists/ubuntu karmic main

Update apt-get and install tinyos

sudo apt-get update
sudo apt-get install tinyos-2.1.1

Change the ownership of tinyos root directory to your user

sudo chown : -R /opt/tinyos-2.1.1/ 

Edit .bashrc in user home and add the following lines at the end

export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.$CLASSPATH
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/opt/msp430/bin:$PATH
source /opt/tinyos-2.1.1/tinyos.sh

Install the java tools using

sudo tos-install-jni

Install Java docs 

Go to /opt/tinyos-2.1.1/support/sdk/java
make
make install
make javadoc 

Common Errors

1.Unexpected operator during tos-jni-install command

Error

sudo tos-install-jni 
[: 31: =: unexpected operator 

Installing 32-bit Java JNI code in /usr/lib/jvm/java-1.5.0-sun/jre/lib/i386 …

done.

Solution  

Edit /usr/bin/tos-install-jni and change 1st line from “#!/bin/sh” to “#!/bin/bash”

Tuesday, February 12, 2013

Git Clone Error "http://myserver.com/example.git/info/refs not found: did you run git update-server-info on the server?"

I got a simple solution for this issue. 

Problem

1. Git reposiory over http with ldap authentication
2. Repository authentication and listing is work perfect using browser
3. But git clone fails with “http://myserver.com/example.git/info/refs not found: did you run git update-server-info on the server?”

Solution

In the git repository server

1. Go to git repository folder(Here example.git)
2. Create a empty file with name 'git-daemon-export-ok'
[eg: $touch git-daemon-export-ok]

Then try 'git clone http://username@/example.git'

Happy coding ...:)