Skip to content

ungue/mifareapplet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mifare Applet

This applet allow you to use mifare cards from Javascript. For now, the applet has been tested with SCM SDI010 card reader and Omnikey CardMan 5321.

Parameters

The following parameters are allowed:

  • terminal

  • protocol

These two avoid you have to call setTerminal and setProtocol in javascript.

Functions

It only has six simple autoexplanatory functions:

  • load_key

  • auth

  • read

  • write

  • beginTransaction

  • endTransaction

load_key and key encryption (for developers only)

May be you need to get keys from a key store which gives you them encrypted. Well, load_key allows these ones to be decrypted internally to prevent anyone can get their real values. The use of this capability is simple. You need to implement your own class which implements IDecoder and set the name of this class into config.properties. Let see an example:

import javax.crypto.*;
import javax.crypto.spec.*;

class DESDecoder implements IDecoder {

  private byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; // Hardcoded DES key 8 bytes

  private Cipher cipher;
  private SecretKey secretKey;

  public DESDecoder(){
    System.out.println("DES/ECB/PKCS5Padding Decoder loaded");

    try{
      cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
      secretKey = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(key));
    }catch(Exception e){
      e.printStackTrace();
    }
  }

  public byte[] decode(byte[] bytes){
    try{
      cipher.init(Cipher.DECRYPT_MODE, secretKey);
      return cipher.doFinal(bytes);
    }catch(Exception e){
      e.printStackTrace();
      return null;
    }
  }
}

The file config.properties has to contain the following line:

mifareapplet.keys.decoder = DESDecoder

Example of use

Here we can see how a card block is readed from a web page by mean of Javascript:

$(function() {
  app = $('#app')[0];

  app.setTerminal(jQuery.parseJSON(app.terminals())[1]);
  app.setProtocol("T=1");

  app.beginTransaction();

  r = jQuery.parseJSON(app.load_key([0x55,0x55,0x55,0x55,0x55,0x55],app.KEY_B));
  r = jQuery.parseJSON(app.auth(0,app.KEY_B));
  r = jQuery.parseJSON(app.read(0));

  app.endTransaction();
});

Dependencies

Troubleshootings

  • The card is inserted but the reader seems not to respond. Have you installed the proper drivers? First, launch pcscd in foreground an debug mode to test if all goes fine.

    sudo pcscd -f -d

    For example, to get working SDI010 in Ubuntu 11.04, you’ll have to do so:

  • No terminal is shown in the applet. May be libpcsclite.so is not found by java. Check for /usr/lib/libpcsclite.so availability.

About

Applet to manage Mifare cards from Javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published