Jcardsim Java Card Is Simple!: Javaone Moscow, 2013
Jcardsim Java Card Is Simple!: Javaone Moscow, 2013
Jcardsim Java Card Is Simple!: Javaone Moscow, 2013
Agenda
Birth of Java Card
February 2, 1997, the first Java card was received from the factory
June, 2005
Sun Microsystems, Inc. announces that 1 billion Java Card cards
have been sold.
Standardization
12 February, 1997
Leading Smart Card Manufacturers Announce Formation of Java Card Forum -
Industry initiative endorsed by Sun, creator of the Java™ Card API standard
20 October, 1997
Public review on version 2.0 of the Java Card specification
March, 1999
Java Card version 2.1 announced. There are three specifications: Java Card API,
Java Card Runtime Environment, Java Card Virtual Machine
May, 2006
Java Card version 2.2.2 announced. Adds contactless capabilities and biometry
support for smart card chip manufacturers
New Age
March, 2008
Java Card version 3.0 announced. Classic and Connected Editions.
• Classic Edition is an evolution of the Java Card 2.2.2
• Connected Edition is a revolution technology for high-end smart cards
Today
• More than 10 billion Java technology based smart cards have been deployed
• NFC wallets requires Java Card
• Secure M2M Solutions
• ISO 7816
• ISO 14443
• Java Card Specification
• Global Platform
Basic Standards
ISO 7816 standards
Command APDU
Client Card
Application Application
Response APDU
APDU Structure (1/2)
Command APDU
Field Length Description
CLA 1 Class of instruction
INS 1 Instruction code
P1 1 Instruction parameter 1
P2 1 Instruction parameter 2
Lc 1 or 3 Number of bytes present in the data field
of the command
Data Lc String of bytes sent in the data field of the
command
Le 1 or 3 Maximum number of bytes expected in
the data field of the response to the
command
APDU Structure (2/2)
Response APDU
Field Length Description
Data Lr String of bytes received in the data field
of the response
SW1 1 Command processing status
SW2 1 Command processing qualifier
Applet 1 Applet 2 …
Card Management
Security Policy/
Global Platform API
Issuer/Vertical Market Defined API
Split VM Architecture
• Off-card
• Class loading, linking and name resolution
• Bytecode verification, optimization and conversion
• On-card
• Bytecode execution and security enforcement
JCVM
Class Cap
files Converter Interpreter
file
Computer Card
Java Card Classic Virtual Machine (version 3.0.4) 2/3
• Unsupported Features
• Dynamic Class Loading
• Security Manager
• Finalization
• Threads
• Cloning
• Access Control in Java Packages
• Typesafe Enums
• Enhanced for Loop
• Varargs
• Runtime Visible Metadata (Annotations)
• Assertions
• Unsupported Types
The Java Card platform does not support types char, double, float and long. It also
does not support arrays of more than one dimension.
Java Card Classic Virtual Machine (version 3.0.4) 3/3
• Supported Features
• Packages
• Dynamic Object Creation
• Virtual Methods
• Interfaces
• Exceptions
• Generics
• Static Import
• Runtime Invisible Metadata (Annotations)
• Runtime Visible Metadata (Annotations)
• Assertions
• GC (optional)
• Supported Types
Java programming language types boolean, byte, short are supported. Objects (class
instances and single-dimensional arrays) are also supported.
The int keyword and 32-bit integer data support is optional.
Java Card Runtime Environment (version 3.0.4)
• Card resource management
• Communications
• Applet execution
• Applet security (firewall)
Firewall
• Provides isolation between applications
• Operates dynamically at run-time
• Isolation is at the package level
• Applets can explicitly share objects (javacard.framework.Shareable)
Java Card API (version 3.0.4)
• java.io
• java.lang
• java.rmi
• javacard.framework
• javacard.security
• javacardx.annotations
• javacardx.apdu
• javacardx.biometry
• javacardx.crypto
• javacardx.external
• javacardx.framework.math
• javacardx.framework.string
• javacardx.framework.tlv
• javacardx.framework.util
• javacardx.framework.util.intx
Global Platform
Global Platform Card Specification is a secure, dynamic card and application
management specification
• Security Domains
• Secure channels
• Application Management
• Card Management
http://www.globalplatform.org/
• Application Model
• Development Workflow
Java Class
Source
Compiler files
Java Card
Java VM
Converter
CAP file
JCWDE jCardSim
C-JCRE
Java Card
Simulator
• Java Card Development Kit
• GPShell
• JCOP Tools from NXP (IBM)
• jCardSim
Developer Tools
jCardSim (1/3)
• Implementation of javacard.security
One of the main differences is the implementation of javacard.security: current
version is analogous with NXP JCOP 31/36k card. For example, in jCardSim we
have support an on-card KeyPair.ALG_EC_F2M/ALG_RSA_CRT-key generation
• Simulator API
jCardSim has simple and usable API, which allows you to work with simulator like
with real Java Card using javax.smartcardio
• Cross-platform
jCardSim completely written in Java and can therefore be used at all platforms
which supports Java (Windows, Linux, MacOS, etc)
• PetID – ePassport for home pets
• Concepts
• Architecture
• Implementation Notes
• Protocol
• Demo
Nowadays, one of the main applications of Java Card is electronic identity cards
(i.e. ePassport)
• The application must provide the ability to store, receive and transmit
information about a pet.
• Must provide protection against modification of the data from a malicious
person.
public PetIDApplet () {
petInfoData= new byte[4086];
register();
}
public static void install(byte[] bArray, short bOffset, byte bLength) throws
ISOException {
new PetIDApplet ();
}
Source Applet (2/2)
public void process(APDU apdu) throws ISOException {
if (selectingApplet()) return;
byte[] buffer = apdu.getBuffer();
if (buffer[ISO7816.OFFSET_CLA] != BASE_CLA) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
byte ins = buffer[ISO7816.OFFSET_INS];
switch (ins) {
case PERSONALIZE_INS:
personalize(apdu);
break;
case STORE_PET_INFO_INS:
storePetInfo(apdu);
break;
case LOAD_PET_INFO_INS:
loadPetInfo(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
Source PetInfo
public class PetInfo {
// tlv types
private final static byte NAME_TAG = 1;
private final static byte BIRTH_TAG = 2;
private final static byte BREED_TAG = 3;
private final static byte SEX_TAG = 4;
private final static byte SIGNATURE_TAG = 5;
//
private String name;
private boolean sex;
private String breed;
private Calendar dateOfBirth;
…
}
Source Unit-test (1/3)
System.setProperty("com.licel.jcardsim.smartcardio.applet.0.AID", TEST_APPLET_AID);
System.setProperty("com.licel.jcardsim.smartcardio.applet.0.Class",
“samples.PetIDApplet");
if (Security.getProvider("jCardSim") == null) {
JCardSimProvider provider = new JCardSimProvider();
Security.addProvider(provider);
}
// select applet
CommandAPDU selectApplet = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 0,
0, Hex.decode(TEST_APPLET_AID));
response = jcsChannel.transmit(selectApplet);
assertEquals(response.getSW(), 0x9000);
Secure Element
Application
NFC API Phone OS
NFC
SE
Controller
Java Card
NFC Antenna
• The initial project team consisted of three developers
• First public release has been announced in December
2011
• In June 2012 the official site, jcardsim.org, has been
started and available in following languages: English,
Russian, Spanish
• Main audience of the project is students which are
learning Java Card and professional Java Card developers
jCardSim Facts
2Q 2013
• Shareable Interface Support
• Service Framework Support
• Multiple Logical Channels
3Q 2013
• Application Firewall Support
• Basic Global Platform functionality
jCardSim RoadMap
THANKS!
Email: jcardsim@licel.ru
Twitter: @MikhailDudarev
WWW: jcardsim.org