private byte[] encryptcommand = {(byte)0xa0, (byte)0xc1, (byte)0x00, (byte)0x00, (byte) 0x00};



Similar documents
Introduction to Mobile Phone. Programming in Java Me

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

The Software Engineering of Mobile Application Development

Mobile application development J2ME U N I T I I

JAVA Program For Processing SMS Messages

Licence Informatique Année Exceptions

MIDlet development with J2ME and MIDP

::. Contenuti della lezione *+ ') $ &,!!!$!-,.../- ' % + &

Brazil + JDBC Juin 2001, douin@cnam.fr

TP : Système de messagerie - Fichiers properties - PrepareStatement

Java Programming Language

Creating a Simple, Multithreaded Chat System with Java

Langages Orientés Objet Java

Programmation RMI Sécurisée

Communicating with a Barco projector over network. Technical note

Remote Method Invocation

Tutorial Reference Manual. Java WireFusion 4.1

Les fragments. Programmation Mobile Android Master CCI. Une application avec deux fragments. Premier layout : le formulaire

Annexe - OAuth Introduction. Xavier de Rochefort xderoche@labri.fr - labri.fr/~xderoche 15 mai 2014

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

Liste d'adresses URL

OpenOffice.org Extensions development in Java with NetBeans in practise. Jürgen Schmidt OpenOffice.org Sun Microsystems, Inc.

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Overview of Web Services API

Socket-based Network Communication in J2SE and J2ME

An Android-based Instant Message Application

Lecture J - Exceptions

TP N 10 : Gestion des fichiers Langage JAVA

POB-JAVA Documentation

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

Custom Encryption in Siebel & Siebel Web Service Security Test Guide 1.0

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

CS506 Web Design and Development Solved Online Quiz No. 01

Capario B2B EDI Transaction Connection. Technical Specification for B2B Clients

RMI Client Application Programming Interface

"Internationalization vs. Localization: The Translation of Videogame Advertising"

User s Guide. Sun Java TM Wireless Toolkit for CLDC Version Sun Microsystems, Inc.

Mobile Software Application Development. Tutorial. Caesar Ogole. April 2006

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

OBJECT ORIENTED PROGRAMMING LANGUAGE

Mobile Application Development. MIDP & GUI Programmierung

16.1 DataFlavor DataFlavor Methods. Variables

JAVA - EXCEPTIONS. An exception can occur for many different reasons, below given are some scenarios where exception occurs.

Java Management Extensions SNMP Manager API

CS 111 Classes I 1. Software Organization View to this point:

European Access Point for Truck Parking Data

Continuous Integration Part 2

How to develop your own app

Paillier Threshold Encryption Toolbox

Bangla Text Input and Rendering Support for Short Message Service on Mobile Devices

Tutorial for Creating Resources in Java - Client

Smart Card Based User Authentication

gomobi Traffic Switching Guide Version 0.9, 28 September 2010

Threads & Tasks: Executor Framework

Building a Multi-Threaded Web Server

Getting Started with the Internet Communications Engine


When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer

How To Run A Test File Extension On A Rexx (Unix) On A Microsoft Linux (Amd64) (Orchestra) (For Windows) (

13 File Output and Input

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

Chapter 6 Load Balancing

Les Support Packs IA94 et IA9H

Aucune validation n a été faite sur l exemple.

Web Development in Java

Advanced Network Programming Lab using Java. Angelos Stavrou

Introduction au BIM. ESEB Seyssinet-Pariset Economie de la construction contact@eseb.fr

"Templating as a Strategy for Translating Official Documents from Spanish to English"

Java Programming Fundamentals

Web Service Caching Using Command Cache

Implementing a Web Service Client using Java

CSE 308. Coding Conventions. Reference

Using ilove SharePoint Web Services Workflow Action

CS 1302 Ch 19, Binary I/O

APPLICATION PROGRAMMING - MOBILE COMPUTING Mobile Computing

MSDG Services Integration Document Draft Ver 1.2

WebSphere and Message Driven Beans

Network/Socket Programming in Java. Rajkumar Buyya

Java Applet and Terminal Application for Financial transactions

An Overview of Java. overview-1

Operation Instructions PowerCool Series

Background Tasks and Blackboard Building Blocks TM. Two great tastes that taste great together

Network Communication

Archived Content. Contenu archivé

"Simultaneous Consecutive Interpreting: A New Technique Put to the Test"

Using mobile phones to access Web Services in a secure way. Dan Marinescu

Mail User Agent Project

Transcription:

/* *Utilisation des Java Card (U)SIM pour la sécurisation des communications et des données dans les applications sur téléphones mobiles Cette midlet est chargée de proposer une interface à l'utilisateur qui lui permette de déclencher l'envoi d'une information confidentielle à transmettre (chiffrée) par SMS. La midlet communique avec l'applet appropriée, récupère l'information chiffrée et l'expédie au contact indiqué Code de la midlet (listing 6) serge.chaumette at labri.fr jonathan.ouoba at labri.fr */ import javax.microedition.midlet.midlet; import javax.microedition.midlet.midletstatechangeexception; import javax.microedition.apdu.apduconnection; import javax.microedition.io.connector; import javax.wireless.messaging.*; import java.io.ioexception; import javax.microedition.io.connectionnotfoundexception; import javax.microedition.lcdui.commandlistener; import javax.microedition.lcdui.display; import javax.microedition.lcdui.displayable; import javax.microedition.lcdui.form; import javax.microedition.lcdui.item; import javax.microedition.lcdui.itemcommandlistener; import javax.microedition.lcdui.stringitem; import javax.microedition.lcdui.textfield; import javax.microedition.lcdui.command; public class Midlet_Misc extends MIDlet implements CommandListener, ItemCommandListener { private Display display; private Form form; private String smsport; private String phonenumber; private TextField stringitem; private StringItem commandreceive; private StringItem commandsend; private StringItem commandexit; private Command CMD_RECEIVE = new Command("Receive", Command.ITEM, 3); private Command CMD_SEND = new Command("Send", Command.ITEM, 2); private Command CMD_EXIT = new Command("Exit", Command.EXIT, 1); private Thread tapdu; private Send_APDU sapdu; private Thread tsms; private Send_SMS ssms; private Thread tssms; private Receive_SMS rsms; private byte[] tempbuffer = null; private byte[] encryptcommand = {(byte)0xa0, (byte)0xc1, (byte)0x00, (byte)0x00, (byte) 0x00; -1-

private byte[] decryptcommand = {(byte)0xa0, (byte)0xc3, (byte)0x00, (byte)0x00, (byte) 0x08, (byte)0x61, (byte)0x62, (byte)0x63, (byte)0x64, (byte)0x31, (byte)0x32, (byte)0x33, (byte )0x34, (byte)0x00; public Midlet_Misc() { display = Display.getDisplay(this); smsport = "50005"; phonenumber = "+5550001"; // create the main form with its component form = new Form("Demo Midlet - MISC"); stringitem = new TextField("Output", "", 100,0); stringitem.setlayout(item.layout_newline_after); form.append(stringitem); commandexit = new StringItem("", "Exit", Item.BUTTON); commandexit.setdefaultcommand(cmd_exit); commandexit.setitemcommandlistener(this); commandsend = new StringItem("", "Send", Item.BUTTON); commandsend.setlayout(item.layout_newline_before); commandsend.setdefaultcommand(cmd_send); commandsend.setitemcommandlistener(this); commandreceive = new StringItem("", "Receive", Item.BUTTON); commandreceive.setdefaultcommand(cmd_receive); commandreceive.setitemcommandlistener(this); form.append(commandsend); form.append(commandreceive); form.append(commandexit); form.setcommandlistener(this); // display the main screen public void showscreen() { display.setcurrent(form); protected void destroyapp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub protected void pauseapp() { // TODO Auto-generated method stub protected void startapp() throws MIDletStateChangeException { initapp(); showscreen(); -2-

public void initapp() { //application initialization operations //SMS Server Communication rsms = new Receive_SMS(smsPort,this); tsms = new Thread(rSMS); tsms.start(); // set the message of the stringitem public void setmessage(string text) { stringitem.setstring(text); //emission of encrypted SMS public void sendsms(string message) { ssms = new Send_SMS(smsPort,message,"",phoneNumber,this); tssms = new Thread(sSMS); tssms.start(); // fill the byte array to send as apdu command private void fill_apdu(byte[] apdu, String message) { short i; short length = (short)(message.length()-2); apdu[0] = (byte) 0xA0; apdu[1] = (byte) 0xC3; apdu[2] = (byte) 0x00; apdu[3] = (byte) 0x00; apdu[4] = (byte) length; for (i = 0; i < length; i++) apdu[i + 5] = message.getbytes()[i]; apdu[length + 5] = (byte) 0x00; //managenement of received encrypted SMS public void receivedsms(string message) { fill_apdu(tempbuffer, message); sapdu = new Send_APDU(this, tempbuffer, (byte)0xc3); tapdu = new Thread(sAPDU); tapdu.start(); // button action management public void commandaction(command c, Item i) { // exit the application if (c == CMD_EXIT) { destroyapp(false); catch (Exception ex) { -3-

setmessage("impossible to exit..."); notifydestroyed(); else if (c == CMD_SEND) { sapdu = new Send_APDU(this, encryptcommand, (byte)0xc1); tapdu = new Thread(sAPDU); tapdu.start(); else if (c == CMD_RECEIVE) { sapdu = new Send_APDU(this, decryptcommand, (byte)0xc3); tapdu = new Thread(sAPDU); tapdu.start(); public void commandaction(command com, Displayable d) { // TODO Auto-generated method stub //class to send apdu command an get apdu response (encryption and decryption operations) class Send_APDU implements Runnable { private Midlet_Misc parent; private APDUConnection apduconnectionref = null; private byte[] data = null; private byte[] response = null; private byte tag; Send_APDU(Midlet_Misc parent, byte[] data, byte tag) { this.parent = parent; this.data = data; this.tag = tag; private void openapduconnection() { //Opening SATSA APDU connection parent.setmessage("opening"); apduconnectionref = (APDUConnection) Connector.open("apdu:0;target=A0.00.00.00.18.50.00.00.00.00.00.00.52.41.44.41"); parent.setmessage("opening Done - "+String.valueOf(data.length)); catch (ConnectionNotFoundException ex) { parent.setmessage("not able to make connection "); catch (IOException ex) { //parent.display_alert(alerttype.info, "INFO","Error opening APDU 1...", 2000); parent.setmessage("error Opening..."); private void tcloseapduconnection() { -4-

if (apduconnectionref!= null) { //Closing SATSA APDU connection apduconnectionref.close(); catch (Exception ex) { parent.setmessage("error closing APDU..."); private byte[] sendapdu(byte[] messapdu) { byte[] result = null; //Sending APDU command result = apduconnectionref.exchangeapdu(messapdu); catch (IOException ioerr) { parent.setmessage("can't send APDU..."); catch (IllegalArgumentException argerr) { parent.setmessage("illegal APDU..."); return result; public static String arraytohex(byte[] data) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < data.length; i++) { String bs = Integer.toHexString(data[i] & 0xFF); if (bs.length() == 1) { sb.append(0); sb.append(bs); sb.append((i + 1) % 8 == 0? '\n' : ' '); return sb.tostring(); public void run() { openapduconnection(); response = sendapdu(data); if (tag == (byte) 0xC1) { parent.setmessage(arraytohex(response)); parent.sendsms(new String(response)); if (tag == (byte) 0xC3) { //parent.setmessage("\n" + new String(response)); parent.setmessage(arraytohex(response)); tcloseapduconnection(); -5-

//class that handles the reception of SMS class Receive_SMS implements Runnable, MessageListener{ private Midlet_Misc parent; private String smsport; private MessageConnection smsconn; private Message msg; private Thread tsms; private boolean running; Receive_SMS(String smsport,midlet_misc parent) { this.parent = parent; this.smsport = smsport; running = true; String smsconnection = "sms://:" + smsport; //Open the message connection if (smsconn == null) { smsconn = (MessageConnection)Connector.open(smsConnection); smsconn.setmessagelistener(this); parent.setmessage("#sms connection opened"); catch (IOException ioe) { ioe.printstacktrace(); System.out.println(smsConnection); smsconn.setmessagelistener(this); catch (IOException ioe) { ioe.printstacktrace(); parent.setmessage("sms connection mode error"); tsms = new Thread(this); tsms.start(); public void closeconnection() { if (smsconn!= null) { smsconn.close(); catch (IOException e) { //Ignore any errors on shutdown System.out.println("Closing intermediary SMS connection..."); public void notifyincomingmessage(messageconnection conn) { //tsms = new Thread(this); -6-

//tsms.start(); public void run() { while (running) { msg = smsconn.receive(); if (msg!= null) { String receivedmessage = ((TextMessage)msg).getPayloadText(); parent.setmessage("sms received from "+msg.getaddress()); parent.receivedsms(receivedmessage); catch (IOException e) { e.printstacktrace(); //class that handles the emission of SMS class Send_SMS implements Runnable { private String message; private String adr; private String myself; private Midlet_Misc parent; private String smsport; private String address; private String desadr; Send_SMS (String smsport,string message,string myself,string adr,midlet_misc parent) { this.smsport = smsport; this.message = message; this.parent = parent; this.adr = adr; this.myself = myself; public void run() { desadr = "sms://" + adr; address = desadr + ":" + smsport; MessageConnection smsconn = null; // open the message connection smsconn = (MessageConnection)Connector.open(address); TextMessage txtmessage =(TextMessage)smsconn.newMessage(MessageConnection. TEXT_MESSAGE); txtmessage.setaddress(address); txtmessage.setpayloadtext(message); smsconn.send(txtmessage); //parent.setmessage("#sent via sms"); -7-

catch (Throwable t) { parent.setmessage("send caught: "+smsport); t.printstacktrace(); // close the message connection if (smsconn!= null) { smsconn.close(); //parent.sendmessagesms(); catch (IOException ioe) { parent.setmessage("closing connection caught"); ioe.printstacktrace(); -8-