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.
The following parameters are allowed:
-
terminal
-
protocol
These two avoid you have to call setTerminal and setProtocol in javascript.
It only has six simple autoexplanatory functions:
-
load_key
-
auth
-
read
-
write
-
beginTransaction
-
endTransaction
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
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(); });
-
JSON classes (github.com/douglascrockford/JSON-java)
-
Apache Commons Lang 3 (commons.apache.org/lang)
-
Java 1.6
-
PC/SC v2.01 or higher compliant contactless card reader
-
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:
-
sudo aptitude install pcscd libpcsclite1 libccid
-
Download and install the driver from SCM: support.scmmicro.com/download_scm/download_scm.php
-
-
No terminal is shown in the applet. May be libpcsclite.so is not found by java. Check for /usr/lib/libpcsclite.so availability.