Java Card 3
Java Card 3
Michel Koenig
Presentation objectives
Introducing the concepts and the technology of the smart cards Describing the protocols between cards and terminals Describing how to program the Java Cards Exploring the tools and the environments provided by the manufacturers to develop solutions with smart cards
Michel Koenig
Presentation content
Introduction ISO7816 Protocol Java Card The basic rules for Java Card programming Cyphering SIM Card Smart Card Web Server Java Card 3.0 Connected Edition Conclusion
Michel Koenig
Introduction
History, technology, standards
Michel Koenig
Introduction
A brief history of the smart cards The applications supported by the smart cards The standards supported
Michel Koenig
Brief history
Early seventies, first patents
Dr Arimura, R Moreno, M Ugon
Mid eighties, large scale introduction of smart cards in banking system Mid nineties, SIM card introduced in mobile telephony
Michel Koenig
Standardized
ISO 7816
Mecanical properties Electrical behavior Communication protocol
Michel Koenig
Standards
ISO 7816 GSM 11.11 V6.1.0 GSM 11.14 V7.1.0
SIM Toolkit specs
EMV
Europay, Mastercard, Visa
Global Platform
Michel Koenig
Standards
Michel Koenig
10
Conclusion
A brief history of the smart cards The applications supported by the smart cards The standards supported
Michel Koenig
11
ISO7816 Protocol
Physical description, communication layer, file system
Michel Koenig
12
Introduction
An introduction to the ISO7816 standard What is an APDU How to exchange data between the CAD and the smart card
Michel Koenig
13
Michel Koenig
14
A USB port in place of the two optionnal contacts on the bottom of the circuit A NFC (Single Wire Protocol) port for the last optionnal contact
15
USB Port
NFC SWP
Michel Koenig
Due to the unique pin dedicated to input/output, the first protocol used by the smart cards were
Serial Half-duplex
C0
00
00
Communication characteristics:
Data: 8 bits Parity: even Stop: 1 bit
Michel Koenig
16
USB IC
ETSI TS 102.600
Compatible with the previous serial protocol Disk emulation To support TCP/IP protocol
17
Mass Storage
Michel Koenig
NFC SWP
ETSI TS 1002.613 & 622
Michel Koenig
18
Terminology
The smart card reader powered by
a PC A cash register a mobile phone
Michel Koenig
19
Answer to Reset
When a card is inserted into the reader, a micro-switch signals this event to the terminal. The terminal powers up the card
Using a particular protocol
When it is properly powered, the card sends back to the terminal a message called "Answer to Reset"
Michel Koenig
20
General protocol
After sending Answer to Reset, the card waits until the terminal starts a communication The card never starts a communication The card answers to a demand coming from the terminal and waits for the next demand
Michel Koenig
21
Michel Koenig
22
CLA INS P1 P2 LC
Instruction: this is the command
P1, P2: two parameters which can be combined to form a short integer LC: length of parameters which will be exchanged between the terminal and the card (from the terminal to the card, or from the card to the terminal)
Michel Koenig
23
No parameters exchanged
CAD Card
CLA INS
P1
P2
LC
LC ==0 The card receives the APDU It processes it It returns a status word
Two bytes
Michel Koenig
24
CLA INS
P1
P2
LC INS
LC 0 LC indicates the length of the data in bytes The software in the terminal and the software in the card must agree on the direction of the exchange The card acknowledges by sending back the INS byte
Simple case
Michel Koenig
25
CLA INS
P1
P2
The card acknowledges the APDU by sending back the INS byte
Simple case
Michel Koenig
26
Status word
Status report of the internal operation done by the card 0x9000 means success! When different, could indicate
0x9000 Denied access File not found No such CLA or INS expected
Michel Koenig
27
Conclusion
An introduction to the ISO7816 standard What is an APDU How to exchange data between the CAD and the smart card
Michel Koenig
28
Java Card
Java Card Forum, history of the versions, programming aspects
Michel Koenig
29
Introduction
An introduction to the Java Card system What is a Java Card Applet What is the Java Card Runtime Environment The lifecycle of an Applet How to protect access with an OwnerPIN
Michel Koenig
30
Operating systems
Beginning: proprietary systems
Only the applications were standardized
B0' for French banking system
Java Card
Michel Koenig
31
Michel Koenig
32
Applications could be portable from one smart card to another Applications run securely in a "sand box" Small footprint for the applications
Michel Koenig
33
No Strings
No garbage collector
Connected Edition
Michel Koenig
35
Available libraries
Basically, javacard and javacardx contain the smart card API
framework, security and crypto
java.lang is reduced mainly to the exception definitions java.io and java.rmi was introduced in the last 2.2 version
java.io to manage channels java.rmi to manage remote method invocation
Michel Koenig
36
SIM Toolkit
For SIM Toolkit two more packages
access toolkit
Michel Koenig
37
Michel Koenig
38
Michel Koenig
39
Downloading a package
Applets must be encapsulated in a package External processes
Compile the applets Verify the bytecode Create a jar-like container
CAP file
Michel Koenig
40
Michel Koenig
41
Class APDU
This class provides the basic features needed to handle the ISO7816 protocol from the applet point of view It gives access to the internal buffer dedicated to the communication This buffer can be
Retrieved by the applet Filled up by the applet and sent to the CAD
CLA
INS
P1
P2
LC
Michel Koenig
42
apdu.setIncomingAndReceive();
Utilities help to
Transform 2 bytes in a short and vice versa Copy buffers Compare buffers
apdu.setOutgoingAndSend(...);
Michel Koenig
43
Class ISO7816
This class encapsulates most of the ISO7816 constants needed to program the applets Constants are prefixed by
CLA for class related constants INS for instruction related constants OFFSET for offsets in the buffer SW for status word related constants
Michel Koenig
44
Lifecycle of an applet
instance aid
JCRE
er gist e
instance
in s ta ll
The JCRE downloads the package containing the Applet It calls the static method install on the Applet This method creates an instance
Or more
ne
Applet
Michel Koenig
45
Lifecycle of an Applet
instance aid
JCRE
instance
When the instance is created and registered it can be called The JCRE can
select deselect
Applet
Michel Koenig
46
Example of an Applet
Michel Koenig
47
Michel Koenig
48
Michel Koenig
49
Simulation script
Michel Koenig
50
Result
Michel Koenig
51
Netbeans 6.9
Michel Koenig
52
Shareable applets Possibility to have several applets selected at the same time
Michel Koenig
53
OwnerPIN
This class helps the developer to protect the access to some features of the smart card using a PIN code
private OwnerPIN pinCode; /** Creates a new instance of EPurse */ public EPurse() { balance = (short)0; pinCode = new OwnerPIN(EPURSE_PIN_TRY_LIMIT, EPURSE_PIN_MAX_SIZE); }
Michel Koenig
54
OwnerPIN
The CAD must validate the PIN code prior to access the other features
case EPURSE_ADD: apdu.setIncomingAndReceive(); if(!pinCode.isValidated()) ISOException. throwIt( ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); break; case EPURSE_PIN: apdu.setIncomingAndReceive(); if(!pinCode.check(buffer, ISO7816.OFFSET_CDATA, EPURSE_PIN_MAX_SIZE)) ISOException.throwIt( ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); break;
Michel Koenig
55
OwnerPIN
The OwnerPIN proposes a method to unblock a blocked PIN code (after a TRY_LIMIT unsuccessful attempts)
Michel Koenig
56
OwnerPIN
The OwnerPIN proposes a method to reset the validated flag
public boolean select(){ pinCode.reset(); }
Michel Koenig
57
Conclusion
An introduction to the Java Card system What is a Java Card Applet What is the Java Card Runtime Environment The lifecycle of an Applet How to protect access with an OwnerPIN
Michel Koenig
58
Michel Koenig
59
Reduced language Reduced library Most exciting features of Java available in Java Card Most difficulties coming from the ISO7816 protocol hidden by the JCRE and the API
Michel Koenig
60
Upload applets in target Java Cards Test, on board, the uploaded applets
Michel Koenig
61
No consistency in data when the card is teared suddenly from the reader Poor usability and security Time out and memory issues not taken in account
Michel Koenig
62
Tr U S T Me
Michel Koenig
63
Transaction aware
Context
Michel Koenig
64
case EPURSE_ADD: apdu.setIncomingAndReceive(); if(!pinCode.isValidated()) ISOException.throwIt( ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); amount = Util.getShort(buffer, ISO7816.OFFSET_CDATA); balance = (short)(balance + amount); list.add(buffer, ISO7816.OFFSET_INS, ISO7816.OFFSET_CDATA, (short)2, (short)(ISO7816.OFFSET_CDATA + (short)2), (short)8); break;
Michel Koenig
65
Transaction aware
(a better code)
try{ JCSystem.beginTransaction(); amount = Util.getShort(buffer, ISO7816.OFFSET_CDATA); balance = (short)(balance + amount); list.add(buffer, ISO7816.OFFSET_INS, ISO7816.OFFSET_CDATA, (short)2, (short)(ISO7816.OFFSET_CDATA + (short)2), (short)8); JCSystem.commitTransaction(); }catch(TransactionException ex){ } break;
Michel Koenig
66
Usability
Context
On an e-purse, each operation must be accepted only if the users PIN code had been validated and if the operation is possible
Michel Koenig
67
(code example)
Usability
case EPURSE_ADD: apdu.setIncomingAndReceive(); if(! pincode.check(buffer, ISO7816.OFFSET_CDATA, (byte)2)) ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); amount = Util.getShort(buffer, (short)(ISO7816.OFFSET_CDATA + (short)2)); balance = (short)(balance + amount); list.add(buffer, ISO7816.OFFSET_INS, (short)(ISO7816.OFFSET_CDATA + (short)2), (short)2, (short)(ISO7816.OFFSET_CDATA + (short)4), (short)8); break;
Michel Koenig
68
Usability
PIN code must be deselected after the applet had been also deselected
Michel Koenig
69
Security
Context
Iris scan security system with the card holders iris characteristics in a smart card Problem:
Which part of the system must decide if the iris scanned corresponds to the data stored in the smart card: The card acceptance device? The Java Card?
Michel Koenig
70
(proposed answers)
Security
Answer 1:
The scanned data are passed to the smart card which returns yes or no! The Card Acceptance Device get the stored data from the card to compare it with the scanned data
Java Card 3.0 Programming 71
Answer 2:
Michel Koenig
Security
Mutual authentication is needed prior any data exchange Card Acceptance Device
must make the comparison between data stored in the card and the data scanned
Michel Koenig
72
Time out
Context
A message is sent to the Java Card to be encrypted using a first command A second command must be issued to get back the encrypted message
Michel Koenig
73
Time out
(time issues)
What if
The Java card is teared from the card reader after the first command arrives and before the second command is issued The second command arrives before the first one is issued
Or if
Michel Koenig
74
Time out
Must blank the message to be encrypted if deselect and/or select is called before the second command is issued Must refuse the second command if the first was not sent before
Michel Koenig
75
Memory aware
Context
Michel Koenig
76
Memory aware
(code example)
case EPURSE_ADD: apdu.setIncomingAndReceive(); amount = Util.getShort(buffer, ISO7816.OFFSET_CDATA); Operation op = new Operation(buffer, ISO7816.OFFSET_INS,ISO7816.OFFSET_CDATA, (short)2, (short)(ISO7816.OFFSET_CDATA + (short)2), (short)8); list.add(op); break;
Michel Koenig
77
Memory aware
Avoid creating object on the fly Create all the objects needed during construction phase Recycle already created objects
Michel Koenig
78
Conclusion
Michel Koenig
79
Conclusion
Michel Koenig
80
Conclusion
The Java Card programmers must be aware of:
Michel Koenig
81
Security
Hardware and software aspects
Michel Koenig
82
Objectives
In this chapter, we'll see
An introduction about the security aspects of the smart cards
From a hardware point of view From a software point of view
Michel Koenig
83
Hardware security
A smart card contains important data
It could contain money
Electronic purses
It must be tamper resistant "If you know the attack you can build the shield"
Michel Koenig
84
The attacks
X raying the micro-chip Measuring the power consumption variation during critical APDU
When the PIN code is transmitted for example
Michel Koenig
85
The shields
The micro-chip uses an internal shield to protect itself against an X-Ray scanning It guarantees the same delay for both branches of an alternative statement It guarantees the same power consumption in all cases
Michel Koenig
86
Cryptography is based on
A public algorithm A key
Private (DES, DES3, AES) Public (RSA)
Michel Koenig
87
Symmetric Enciphering
Bob
SAME KEY
Alice
Michel Koenig
88
Asymmetric enciphering
Bobs private key Bobs Public Key
Bob
Alice
Michel Koenig
89
Bob
Alice
Michel Koenig
90
Michel Koenig
91
Certification Authority
lf Se ed gn Si
Certificate Subject (name, company, e-mail ) Start Date End Date Issuers subject Public Key
Certificate Subject (name, company, e-mail ) Start Date End Date Issuers subject Public Key Certificate Subject (name, company, e-mail ) Start Date End Date Issuers subject Public Key
Certificate Subject (name, company, e-mail ) Start Date End Date Issuers subject Public Key
Michel Koenig
92
Integrity
Non-repudiation
Michel Koenig
93
Physically secure
No hard drive storage of the private key
Portable
No multi-key Multiple Device
Michel Koenig
94
Document
Hash
Usual algorithms are MD5 (used for linux Password storage) or SHA-1
8365923334
Michel Koenig
95
Kps
Sender
Receiver
Sender's PK
Kss
Sender's SK
Letter
Letter
8365923334
Hash
8365923334
Hash Signing
X.509 X.509
=?
Identification/ Authentication of the content of the letter
Certificate Authority
Michel Koenig
96
S/MIME Encryption
Sender
Message
Receiver
$@/!&@#
Encrypted message
Kpr
Message
Trust Centre
Michel Koenig
97
Example
Michel Koenig
98
Example
Michel Koenig
99
Example
Michel Koenig
100
Example
Michel Koenig
101
Example
Michel Koenig
102
Example
Michel Koenig
103
Example
Michel Koenig
104
Example
Michel Koenig
105
Example
Michel Koenig
106
Encrypting w/public
Michel Koenig
107
Result
Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00 CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 06, b6, 84, 89, 33, 88, 8e, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 00, P2: 00, Lc: 10, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, Le: 40, 66, ff, e8, 04, 8a, 41, 9e, c2, dd, e7, 44, 79, 3d, 65, 31, a5, c6, c8, 54, bd, 49, 52, da, 99, f0, e4, 89, b6, 08, a4, f6, 64, f9, f8, a4, 95, 3a, 13, 2d, 17, 73, 7b, 4c, 49, SW1: 90, SW2: 00 0b, 0c, 0d, 0e, 0f, 08, eb, 3d, 27, a5, d3, ba, 9f, 41, 65, bb, 1e, c2, 0e, 93, 8c, e5, b6, 61, 9c,
Michel Koenig
108
Conclusion
In this chapter, we have seen
An introduction about the security aspects of the smart cards
From a hardware point of view From a software point of view
Michel Koenig
109
SIM Cards
Proactive SIM cards
Michel Koenig
110
Introduction
The standards driving the smart cards for mobile telephony What is the SIM Toolkit How Java Card handles the SIM toolkit A full example of a Java Card applet built using the SIM Toolkit library
Michel Koenig
111
SIM cards
Standardized by ETSI for GSM GSM 11.11 V6.1.0
SIM specs
Subscriber Identification Module
Michel Koenig
112
Proactives SIM
Using the SIM Toolkit, possibility to
Program the SIM Make the SIM card application driving the phone
Access to keyboard, display,
Michel Koenig
113
Internal organization
Root 0x3F00
The SIM contains a certain number of "files" grouped into "directories" Terminology:
Directory 0x2345
File 0x2222
File 0x2A34
Michel Koenig
114
File hierarchy
Michel Koenig
115
File hierarchy
Michel Koenig
116
Proactive SIM
The ISO7816 standard does not permit that the card starts talking first
A card is waiting for an APDU and responds when it receives the APDU
Proactive SIM cards use a specific status word to indicate to the Mobile Equipment that they want to talk to it
Michel Koenig
117
Proactive protocol
Michel Koenig
118
Michel Koenig
119
Michel Koenig
120
Michel Koenig
121
SIMView
The SIMView interface is the interface between the applet and the GSM filesystem It proposes
Constants to identify in a simple way the regular GSM files Methods to access these files
Michel Koenig
122
SIMView
Example:
/** DF under MF */ /** File identifier : DF TELECOM = 0x7F10 */ public static final short FID_DF_TELECOM /** File identifier : DF GSM = 0x7F20 */ public static final short FID_DF_GSM /** File identifier : DF DCS-1800 = 0x7F21 */ public static final short FID_DF_DCS_1800 /** File identifier : DF IS-41 = 0x7F22 */ public static final short FID_DF_IS_41 /** File identifier : DF FP-CTS = 0x7F23 */ = (short)0x7F22; = (short)0x7F21; = (short)0x7F20; = (short)0x7F10;
Michel Koenig
123
SIMView
Example:
public short select(short fid, byte fci[], short fciOffset, short fciLength) throws NullPointerException, ArrayIndexOutOfBoundsException, SIMViewException;
Michel Koenig
124
SIMSystem
The SIMSystem class provides one method which is
SIMView getTheSIMView()
Michel Koenig
125
ToolkitRegistry
The SIM Applet communicates with the mobile equipment through the ToolkitRegistry The SIM applet get an entry from the ToolkitRegistry in order
To receive and process the events sent by the mobile equipment To send command to the mobile equipment
Michel Koenig
126
Michel Koenig
127
initMenuEntry
public byte initMenuEntry( byte[] menuEntry, /* the menu entry string short offset, /* its offset */ short length, /* its byte nextAction, /* boolean helpSupported, byte iconQualifier, short iconIdentifier /* ) throws */
Michel Koenig
128
Michel Koenig
129
Michel Koenig
130
Michel Koenig
131
Running
Michel Koenig
132
Documentation
More documentation in
3gpp 43019-560
Michel Koenig
133
Conclusion
The standards driving the smart cards for mobile telephony What is the SIM Toolkit How Java Card handles the SIM toolkit A full example of a Java Card applet built using the SIM Toolkit library
Michel Koenig
134
Michel Koenig
135
Introduction
A new approach to interface the applications in the SIM card, using the handset The architecture of the SCWS A full application for a SIM card supporting SCWS
Michel Koenig
136
Introduction
SIM Toolkit was introduced at the time when handset had few capabilities for interfacing
Text oriented display No graphics Hierachical menus Full color graphic interface Point and pin menus
Smart cards tutorial 137
Michel Koenig
Introduction
Axalto developers proposed at Cartes 2000 a simplified web server inside the SIM card
SESAME 2000 the introduction of the USB port the powerfulness of modern SIM card the size of SIM applications
With
SCWS
The standard adopted is called: Smart Card Web Server This standard supposes
A TCP/IP link
On USB
Michel Koenig
139
SCWS
Michel Koenig
140
Michel Koenig
141
ScwsConstants
MIME types
CONTENT_TYPE_IMAGE_GIF CONTENT_TYPE_TEXT_HTML
Status code
SC_OK (200) SC_NOT_FOUND (404)
Parsing tags
URI_QUERY_TAG
Michel Koenig
142
ScwsExtension
The applet (servlet!) working in SCWS mode must implement ScwsExtension That means overiding the methods
doGet() doPost() doHead() ...
Michel Koenig
143
HttpRequest
Not really the J2EE HttpRequest but enough to extract data from a HTTP request Provides methods like
findAndCopyKeywordValue getContentLength getContentType
Michel Koenig
144
HttpResponse
As for HttpRequest, helps the user to provide an HTTP response to the request Provides methods like
setContentType() appendContent() writeStatusCode() flush()
Michel Koenig
145
Example
In the next servlet, the strings are encoded as arrays of bytes
Strings are not supported by Java Card 2
In the next two pages, the pseudo code written in comment show how the servlet would be written if String was supported by this release of Java Card
Michel Koenig
146
Example
/* public class HelloWorld extends javacard.framework.Applet AppletEvent, ScwsExtension { public final static String url = "/HelloWorld"; public final static String appId = "HelloWorld; implements
public byte[] temporaryBuffer; public final static short TEMPORARY_BUFFER_LENGTH = (short) 100; public final static String HTML_BEGIN = "<html>"+"<head>"+ "<title>"+"Hello"+"</title>"+"</head>"+ "<body BGCOLOR=\"#FFFFFF\">"+"<center>"; public final static String HELLO = "Hello "; public final static String HTML_END = "</center>"+"</body>"+ "</html>"
Michel Koenig
147
Example
Unfortunately String are not yet supported by Java Card
Strings are supported by Java Card 3
The arrays of bytes are not so easy to read, but the result is the same
Michel Koenig
148
Example
public class HelloWorld extends javacard.framework.Applet implements AppletEvent, ScwsExtension { /** the servlet url */ public final static byte[] url = { (byte)'/', (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)'W', (byte)'o', (byte)'r', (byte)'l', (byte)'d' }; public final static byte[] appId = { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)'W', (byte)'o', (byte)'r', (byte)'l', (byte)'d' };
Michel Koenig
149
Example
// Temporary operation buffer public byte[] temporaryBuffer; public final static short TEMPORARY_BUFFER_LENGTH = (short) 100; public final static byte[] HTML_BEGIN = { (byte)'<',(byte)'h',(byte)'t',(byte)'m',(byte)'l',(byte)'>', (byte)'<',(byte)'h',(byte)'e',(byte)'a',(byte)'d',(byte)'>', (byte)'<',(byte)'t',(byte)'i',(byte)'t',(byte)'l',(byte)'e',(byte)'>', (byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o', (byte)'<',(byte)'/',(byte)'t',(byte)'i',(byte)'t',(byte)'l',(byte)'e', (byte)'>', (byte)'<',(byte)'/',(byte)'h',(byte)'e',(byte)'a',(byte)'d',(byte)'>',
Michel Koenig
150
Example
(byte)'<',(byte)'b',(byte)'o',(byte)'d',(byte)'y',(byte)' ', (byte)'B',(byte)'G',(byte)'C',(byte)'O',(byte)'L',(byte)'O',(byte)'R', (byte)'=',(byte)'"',(byte)'#',(byte)'F',(byte)'F',(byte)'F',(byte)'F', (byte)'F',(byte)'F',(byte)'"',(byte)'>', (byte)'<',(byte)'c',(byte)'e',(byte)'n',(byte)'t',(byte)'e',(byte)'r', (byte)'>'}; public final static byte[] HELLO ={(byte)'H',(byte)'e',(byte)'l', (byte)'l',(byte)'o',(byte)' '}; public final static byte[] HTML_END = { (byte)'<',(byte)'/',(byte)'c',(byte)'e',(byte)'n',(byte)'t',(byte)'e', (byte)'r',(byte)'>', (byte)'<',(byte)'/',(byte)'b',(byte)'o',(byte)'d',(byte)'y', (byte)'<',(byte)'/',(byte)'h',(byte)'t',(byte)'m',(byte)'l',(byte)'>'};
Michel Koenig
151
Example
public HelloWorld(byte[] buffer, short offset, byte length) { // First LV is instance AID short aid = offset; offset += buffer[offset] + (byte) 1; // Second LV is Privilege offset += buffer[offset] + (byte) 1; // Third LV is specific install parameter (extract from TAG C9) offset++; // skip C9 Length // Register the new applet instance to the JCRE register(buffer, (short) (aid + (short) 1), buffer[aid]); //Register application id,there is corresponding appId in the // Run/Debug configuration for URL Mapping ScwsExtensionRegistry.register(this, appId, (short) 0, (short) appId.length);
Michel Koenig
152
Example
try { // Create a temporary buffer for read/write temporaryBuffer = JCSystem.makeTransientByteArray( TEMPORARY_BUFFER_LENGTH, JCSystem.CLEAR_ON_RESET); } catch (SystemException se) { // create buffer in persistent memory as not enough transient // is available temporaryBuffer = new byte[TEMPORARY_BUFFER_LENGTH]; }
Michel Koenig
153
Example
public void doGet(HttpRequest req, HttpResponse resp) throws ScwsException { try { resp.writeStatusCode(ScwsConstants.SC_OK); resp.setContentType(ScwsConstants.CONTENT_TYPE_TEXT_HTML); resp.enableChunkMode(); short queryLength = req.findAndCopyKeywordValue( ScwsConstants.URI_QUERY_TAG, temporaryBuffer,(short)0, (short)temporaryBuffer.length); resp.appendContent(HTML_BEGIN,(short)0,(short)HTML_BEGIN.length); resp.appendContent(HELLO, (short)0, (short)HELLO.length); resp.appendContent(temporaryBuffer, (short)0, queryLength); resp.appendContent(HTML_END,(short)0, (short)HTML_END.length); }catch(Exception e) {resp.writeStatusCode(ScwsConstants.SC_BAD_REQUEST);} resp.flush();
Michel Koenig
154
Static HTML
Static HTML file : helloworld.html
<html> <body> <p>Simagine HelloWorld</p> <br> <form action="/HelloWorld" method="get"> <input name="name" type="text"> <br> <input value="Type in your name" type="submit"> </form> </body> </html>
Michel Koenig
155
Running
Michel Koenig
156
Conclusion
A new approach to interface the applications in the SIM card, using the handset The architecture of the SCWS A full application for a SIM card supporting SCWS
Michel Koenig
157
Michel Koenig
158
Introduction
The main enhancements introduced by Java Card 3 The restrictions of Java Card 3 compared to Java SE A full example of a servlet
Michel Koenig
159
Features
Compatible with Java Card 2 Applications are built with applets With a WEB server embedded HTTP, TCP/IP over USB
Michel Koenig
160
Features
Java Card 3.0 classic edition remains applet oriented Java Card 3.0 connected edition is servlet oriented
Specifications of the supported servlets are extracted from the Servlet API Specifications 2.4
Everything which deals with floating point numbers, J2EE, etc. are not taken in account.
Michel Koenig
161
Features
But, like traditionnal servlets, the Java Card 3 servlets support the methods:
Michel Koenig
Features
All data types except float and double Multiple threads Extensive API support (java.lang, java.util, GCF, and so on) Direct handling of class files, with all loading and linking on card All new Java language syntax constructs, like enums, generics, enhanced for loops, auto boxing/unboxing, and so on Automatic garbage collection
Smart cards tutorial 163
Michel Koenig
Architecture
Michel Koenig
164
Architecture
Michel Koenig
165
Example
The following example is created with NetBeans 6.9 with the Java Card wizard It is the web instance of the very well known Hello world program
Michel Koenig
166
Example
Michel Koenig
167
Example
Michel Koenig
168
Example
Michel Koenig
169
Example
Michel Koenig
170
Example
Michel Koenig
171
Example
Michel Koenig
172
Example
Michel Koenig
173
Example
Michel Koenig
174
Example
Michel Koenig
175
Example
Michel Koenig
176
Example
Michel Koenig
177
Example
Michel Koenig
178
Example
Michel Koenig
179
Example
Michel Koenig
180
Conclusion
The main enhancements introduced by Java Card 3 The restrictions of Java Card 3 compared to Java SE A full example of a servlet
Michel Koenig
181
Conclusion
Michel Koenig
182
Conclusion
In 1996, the Java Card system changed dramatically the way to program secure applications for smart cards Despite many concurents on the field, this system remains today the first language for smart cards in the world Combined with Java for Mobile Equipment it represents the solution to develop secure applications for the future powerful smartphones
Smart cards tutorial 183
Michel Koenig