Pages

Tuesday, March 27, 2012

Please join me to congratulate Susantha Senevirathne on his new Job at anotherinnovation Ltd as a Senior Software Engineer

Thursday, January 12, 2012

Tuesday, January 10, 2012

Mediator Design Pattern

When an application use many objects and those objects are sharing their references on each other. These kind of situation is so hard to maintain. 

This is the object sharing complexity.
In such a situation we can use the Design patter called Mediator. Using this design pattern it keep a Mediator class (Controller class) and it has reference to all above classes (Object1, Object2....), and All above object has reference to Mediator. Using that we can maintain Complex Object sharing scenarios.

This is after applying Mediator design pattern

Smartcard Unique Identifier

Card that has Mifare contain a unique identifier in Mifare block 0. To read the that Mifare Unique identifier we have two ways
1. Using Applet we can read the Mifare Block 0 using Mifare API.
2. You can send command FFCA000000
This is a purely Mifare command and this will not work in the contact interface.

You can get the unique identifier of the card using the command 80CA9F7F00. This command giving you lot of information of the card.

Following is the Example output and the information of a card.
9F 7F 2A 47 90 50 37 16 71 92 59 48 04 10 46 95 00 07 54 71 49 47 92 02 17 16 73 92 64 16 74 12 91 00 00 00 74 00 00 00 00 00 00 00 00 90 00

  IC Fabricator                      : 4790
  IC Type                          
  : 5037
  Operating System ID                : 1671
  Operating System release date      : 9259 (16.9.2009)
  Operating System release level     : 4804
  IC Fabrication Date                : 1046 (15.2.2001)
  IC Serial Number                   : 95000754
  IC Batch Identifier                : 7149
  IC Module Fabricator               : 4792
  IC Module Packaging Date           : 0217 (4.8.2000)
  ICC Manufacturer                   : 1673
  IC Embedding Date                  : 9264 (21.9.2009)
  IC Pre-Personalizer              
: 1674
  IC Pre-Perso. Equipment Date       : 1291 (18.10.2001)
  IC Pre-Perso. Equipment ID         : 00000074
  IC Personalizer                  
: 0000
  IC Personalization Date            : 0000
  IC Perso. Equipment ID             : 00000000 

If you are using jcop tools you can execute the command get-cplc and get above information.

APDU Structure

When we are doing smartcard programming we should properly know the structure of the APDU.
APDUs has two categories, Command APDU and Response APDU (C-APDU and R-APDU)

Command APDU
Field
Length(byte)
Comment
CLA
1
indicates the type of command
INS
1
indicates the specific command Ex: Get Data
P1
1
Instruction parameter 1  for the command
P2
1
Instruction parameter 2  for the command
Lc
N
Number of bytes in the data field
Data
Nc
Contain the data
Le
N
The maximum number of bytes expected in the data field in the response APDU

Response APDU
Field
Length(byte)
Comment
Response Data
N
Response Data
SW1-SW2
2
Status of the command processing Ex: Success : 90 00

Example to select the applet.

C-APDU : 00 A4 04 00 08 A0 00 00 00 03 00 00 00
R-APDU : 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 00

Getting start android

android SDK can configured in both NetBean and Eclipse. But according to my experience eclipse will be much better (I am not blaming NetBean :) )

This is a very good  video to setup the development environment for android.



Boost to starting Java Card

I also faced to lot of difficulties to really start to work with javacard programming. Hope this will be a boost to who starting to learn javacard programming. Here I am not going to give any introduction or theoretical overall about javacard since you can Google and find many resources on the web.

Download jpcsc.jar library from http://www.linuxnet.com/


Context cardContext = new Context();
cardContext.EstablishContext(PCSC.SCOPE_SYSTEM, null, null);
String[] sa = cardContext.ListReaders();
if (sa.length == 0) {
  // there is no reader detected.
} 

try {
    Card card = cardContext.Connect(sa[0], PCSC.SHARE_EXCLUSIVE, PCSC.PROTOCOL_T0);
    System.out.println("Card Get connected");
          // Here After You can transmit APDU commands to card using card.Transmit
    } catch (Exception ex) {
       ex.printStackTrace();
    }