JavaCard Simulation
Iam new to javacard development. I have downloaded the kit and built the samples.
The process of generating script file and running apdutool are clear.
The apdutool is generating some big output which iam not able to understand.
Iam doing simulation with CREF.
Suppose for JavaPurse Applet
My doubt is How can we enter the PIN and Credit and Debit amount and where can we see balance.
I have simulator which I have downloaded from http://www.wrankl.de/JavaCard/smartcafe.zip
The simulator is very clear. It is showing APDU's neatly and prompting user values for Credit and Debit.
I wish to acheive the simulator kind of features through card kit.
How can I get it?
Any one please help me out.
Thanks in advance
I mean any mobile simulation tool like J2ME tool kit can load these STK Applications.
Please answer if u can give me any direction.
thanks,
bilal
Similar Messages
-
How to select Card manager on Default JavaCard simulator from NetBeans 7.2
Hi
I'm trying to resolve three questions
1) to find FAQ/Manual about simulator included into 3.0.2 JavaCard Connected platform
2) which commands for Card Manager of simulated default JavaCard are supported
3) how to upload simple applet (ex. HelloWorld from JavaCard 3.0.2) using Card Manager applet simulated on Default javaCard Connected platfrom simulator available from NetBeans 7.2
ThaaaanksFrom my understanding, NetBeans uses the CREF executable from the JCDK for simulation. You can check the documentation (developer guide etc) from the JCDK for more details. The CREF emulator uses a custom applet loader so it does not use standard GP commands and will be different to a real card. As for loading your applet, you should be able to run from NB and it will start your emulator and deploy your code. I do not use netbeans so cannot really comment further.
- Shane -
Unable to connect offcard terminal with jcop simulator
Hi all,
I have made a JavaCard applet, called DisplayApplet.
I am using Eclipse with the JCOP tools plugin.
But now I want to make use of an own Terminal that connects to the applet and communicates to it using APDUs.
I don't have a smart card reader/card, so I want to use the simulation environment.
Now I read that I must use the "Remote" value in the JCTerminal constructor to connect to the simulation environment, but it doesn't work (of course I specify the remote value as input parameter).
I am unable to open a terminal.
I get the following exception at the term.open() command:
can't find/open/connect/reset smartcard/reader:
Failed to open [localhost:8050]: Connection refused: connect
Can anyone tell me what's wrong and how I can connect from an own made terminal to a JCOP simulation (I want to run the terminal within Eclipse, because I want to add a UI later on top of it) ??
Here is the code of my own made HostTerminal:
import com.ibm.jc.*;
public class HostTerminal {
public static final String remoteTermName = "Remote";
public static final String nativeTermName = "pcsc:4";
public static final String remoteTermPara = null;
public static final String nativeTermPara = null;
public static void main(String[] args) {
String termName = nativeTermName;
String termPara = nativeTermPara;
if (args.length > 0) {
if (!args[0].equals("native")) {
if (args[0].equals("remote")) {
termName = remoteTermName;
termPara = remoteTermPara;
} else {
try {
System.out.println("args[0] > " + args[0]);
System.out.println("args[1] > " + args[1]);
termName = args[0];
termPara = args[1];
} catch (Exception e) {
System.out.println("invalid command line options");
System.exit(1);
// create terminal, i.e. create a connection to a reader
// and wait for a card insertion
JCTerminal term = null;
try {
term = JCTerminal.getInstance("Remote", null);
term.open();
term.waitForCard(5000);
} catch (Exception e) {
System.out.println(
"can't find/open/connect/reset smartcard/reader: "
+ e.getMessage());
System.exit(1);
System.out.println("Connected to reader and card terminal ...");
// now get the object representing the connection to the card
JCard card = null;
try {
card = new JCard(term, null, 1000);
} catch (Exception e) {
System.out.println(
"can't connect to card in reader: " + e.getMessage());
System.exit(1);
String s;
// get atr of card and print it
try {
ATR atr = card.getATR();
s = JCInfo.atrToString(atr);
System.out.println("Connected to card and received ATR: " + s);
} catch (Exception e) {
System.out.println("can't get ATR: " + e.getMessage());
System.exit(1);
// Note here that the DisplayApplet has to have to aid "display". The IDE
// supports ascii characters in AIDs by using | when editing AIDs.
// For instance, |display results in 636F756E746572.
System.out.println("Selecting Display applet ...");
DisplayApplet displayApplet = null;
try {
byte[] aid = ("phil0Display").getBytes();
displayApplet = new DisplayApplet(card, aid);
displayApplet.select();
s = JCInfo.toHex(aid, 0, aid.length);
System.out.println(
"Selecting of Display applet with aid " + s + " succeeded");
} catch (Exception e) {
System.out.println("can't select Display: " + e.getMessage());
System.exit(1);
}If you run the JavaCard simulator from within Eclipse make sure you disconnect the JCOP shell before trying to connect via JCTerminal() from your Java program. Use the command /close
If you want to disconnect the JCOP shell automatically modify your "Java Card Application" run-configuration:
set Shell commands to execute: to /close
BTW: You were talking about JCOP 3.0, the Eclipse 2.1-plugin or do you use the new pre-release version JCOP 3.1 for Eclipse 3? -
Error while test applet with jcwde simulator using netbeans
i make applet using netbeans 6.5.. i have compile class and i get no error and results *.class but while I use netbeans service on Javacard simulator.. while I try to connect with entry aid applet i have an error.
this is error log
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ Cannot connect to simulator. Cause: Exception during creating JavaCardSimulatorAdapter +
+ +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
why this error is happened ?
thank for your attention.. :D
By Roni
Edited by: ronized on Apr 18, 2009 6:35 AMHi,
As per this part of the trace:
Exception in SAP Application Integrator occured: Application URL &\#39;:///sap(ZT1KVXBWektldldTeV9QQXBXRjNaWTRBLS1OZmRvZzBRWWY2QmN0WThNUmgqdUlRLS0=)/bc/gui/sap/its/webgui&\#39; is not valid! Please check the protocol and host entries for system &\#39;sapdev&\#39;. at ...
You can clearly see that the system object 'sapdev' is not configured correctly/at all - you are trying to launch transaction iView
(WEBGUI) and in order to do so you should configure the 'internet transaction server' category of the system object
with the hostname of the ITS server.
Generally the template is
<System.Access.ITS.protocol>://<System.Access.ITS.hostname>/sap<ESID>/bc/gui/sap/its/webgui?\....
So that's why you got
Please check the protocol and host entries for system .. -
Where can i get a simulator?
hi,i'm a newbie to Java Card..i'm studying JavaCard and
use OpenCard FrameWork to devlop java card applet,but it just begin,can anybody tell me where can i get a javacard simulator??or it already exists in JavaCard package or in OpenCard Framework??
thxThere is a simulator provided with the Java Card kit. The JCWDE is a very relaxed environment and it runs the VM of the JDK installed on your machine. Because it's running the VM of the JDK and not the JCVM ( Java Card VM ) you can invoke other APIs with your applet, like System.out.println....
There is also an emulator provided with the Java Card kit, the C-REF. This is a JCVM simulator and is very strict. It will enforce rules that the JCWDE won't. You can also simulate EEPROM by saving your data to a file and loading it later. -
hi all,recently i want to plan a project that is about
i want to make a connection between javacard and j2me(on pda)
i.e. a j2me game can communicate with javacard..
but i don't know has any existed solution ??
at beginning i only want to make project in the simulation environment (pda simulatior<->javacard simulator) ,i hope u can give me any solution that can communicate between pda and javacard
thx in advance!!AFAIK the j2me (the MIDP profile) does not support smartcard communication
i.e. a j2me gsm phone cannot communicate with the sim card inside
unless something has changed in this subject recently
regards
Kuba -
How to load an applet in card?
Hi everyone,
I use NetBeans and its JavaCard Simulator, protocol T = 0, and I am wandering how to load an applet using APDU tool instead of clicking on Run Projetc which do the mentioned thing. It would be helpfull if someone post ouptut and explain all used apdu commands.
Thanks,
Mare.Here is the APDU trace:
Select Card Manager
=> 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00
<= 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65
01 FF 90 00
Authenticate
cm> init-update 255
=> 80 50 00 00 08 09 41 55 62 DF F5 61 2B 00
<= 00 00 C6 D8 6A 1C B2 02 14 13 FF 02 00 00 93 73
3A B8 2C 0F 8E A4 1D EF 84 60 77 12 90 00
cm> ext-auth plain
=> 84 82 00 00 10 B5 AA A8 E6 8B 73 57 F9 5D 37 6C
D1 FE CF 56 32
<= 90 00
Install For Load
=> 80 E6 02 00 12 05 11 11 11 11 11 08 A0 00 00 00
03 00 00 00 00 00 00 00
<= 00 90 00
Load Block 1
=> 80 E8 00 00 FF C4 82 01 65 01 00 1A DE CA FF ED
02 02 04 00 01 05 11 11 11 11 11 0A 68 65 6C 6C
6F 57 6F 72 6C 64 02 00 21 00 1A 00 21 00 0A 00
0B 00 2A 00 0E 00 A1 00 0A 00 17 00 00 00 5A 02
5A 00 00 00 00 00 00 01 01 00 04 00 0B 01 02 01
07 A0 00 00 00 62 01 01 03 00 0A 01 06 11 11 11
11 11 11 00 08 06 00 0E 00 00 00 80 03 00 FF 00
07 01 00 00 00 1C 07 00 A1 00 01 10 18 8C 00 04
7A 05 30 8F 00 09 3D 8C 00 02 18 1D 04 41 18 1D
25 8B 00 03 7A 04 22 18 8B 00 07 60 03 7A 19 8B
00 06 2D 1A 04 25 75 00 6D 00 06 00 00 00 1D 00
01 00 2C 00 02 00 3B 00 40 00 4A 00 41 00 57 00
42 00 62 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08
70 49 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08 70
3A 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08 70 2B
03 32 04 8D 00 00 32 1F 8D 00 01 70 1E 05 8D 00
00 32 1F 8D 00
<= 00 90 00
Load other Blocks with 80 E8 00 xx ... which xx is the Block number
Load Last Block
=> 80 E8 80 01 6A 00 01 70 13 03 8D 00 00 32 1F 8D
00 01 70 08 11 6D 00 8D 00 01 7A 08 00 0A 00 00
00 00 00 00 00 00 00 00 05 00 2A 00 0A 06 80 08
10 06 80 07 01 06 00 00 01 03 80 03 02 06 80 03
00 03 80 0A 06 03 80 0A 01 03 80 03 03 03 80 0A
08 01 00 02 00 09 00 17 00 00 00 13 05 06 04 0A
07 07 25 09 06 09 06 09 08 05 06 05 06 05 08 00
<= 00 90 00
Install For Install
cm> install -i 111111111111 -q C9#() 1111111111 111111111111
=> 80 E6 0C 00 1A 05 11 11 11 11 11 06 11 11 11 11
11 11 06 11 11 11 11 11 11 01 00 02 C9 00 00 00
<= 90 00Note that if you want to use APDU manually, you should do the authenticate process and loading all blocks of the CAP file yourself.
Note that this is the APDU for a real card that is executed in JCOP Environment. I think it should work for the simulators too except the authentication commands. -
JCOP + Eclipse + pegoda reader
Hi all,
i have written one java card applet with the help of eclipse plugin of JCOP,but i don't have philips pegoda reader to test my applet.
is there any other way of testing applet without use of reader?
or any other reader is available?
Divyesh.You should use the JCOP (or some other) JavaCard simulator. You may also use any PCSC compliant reader.
Regards,
Aleksandar -
Problem about javacard 2.2.1 simulator
Hello,
Does anyone know how to make the simulator support for RSA 1024 bits key length? I have tried to replace the lib file in javacard 2.2.1 to JCOP jc221 lib files, but the simulator works as the same as before, don't allow me to use 1024 bits key length in keyBuilder.
Can the SATSA API for mobile connect to a real javacard? or JCOP simulator?
I have tried to modify the JCOP simulator port number to 9025, but it doesn't work.
Can anyone help me? Thanks a lot.Does anyone know how to make the simulator support
for RSA 1024 bits key length? What do you use as "Simulator"? The JCWDE or CREF?
I have tried to replace
the lib file in javacard 2.2.1 to JCOP jc221 lib
files, but the simulator works as the same as before,
don't allow me to use 1024 bits key length in
keyBuilder.If you are using cref - it can not work. There is AFAIK no cryptographic support in cref and you can not extend it. With JCWDE I don't have any experience.
Can the SATSA API for mobile connect to a real
javacard? or JCOP simulator?
I have tried to modify the JCOP simulator port number
to 9025, but it doesn't work.The JCOP-simulator are normally accessible via TCP/IP. The default port is localhost:8050
Jan -
Simulation using Eclipse plugin for JCOP tools
Dear All,
In search for a simulation environment for java card applet development I tried to use Eclipse plugin for JCOP tools.
The samples which comes with the JCOP tools works fine but when try to debug my applet I receive the error: Wrong Data 6A 80.
Generic JCOP v2.4.1 is selected for Java Card Simulation.
Following is the JCOP Shell screen:
cm- /term "Remote|localhost:8050"
--Opening terminal
/card -a a000000003000000 -c com.ibm.jc.CardManagerresetCard with timeout: 0 (ms)
--Waiting for card...
ATR=3B F8 13 00 00 81 31 FE 45 4A 43 4F 50 76 32 34 ;.....1.EJCOPv24
31 B7 1.
IOCTL().
ATR: T=1, FI=1/DI=3 (93clk/etu), N=0, IFSC=254, BWI=4/CWI=5, Hist="JCOPv241"
=> 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00 ..............
(908058 nsec)
<= 6F 65 84 08 A0 00 00 00 03 00 00 00 A5 59 9F 65 oe...........Y.e
01 FF 9F 6E 06 47 91 92 18 00 00 73 4A 06 07 2A ...n.G.....sJ..*
86 48 86 FC 6B 01 60 0C 06 0A 2A 86 48 86 FC 6B .H..k.`...*.H..k
02 02 01 01 63 09 06 07 2A 86 48 86 FC 6B 03 64 ....c...*.H..k.d
0B 06 09 2A 86 48 86 FC 6B 04 02 15 65 0B 06 09 ...*.H..k...e...
2B 85 10 86 48 64 02 01 03 66 0C 06 0A 2B 06 01 +...Hd...f...+..
04 01 2A 02 6E 01 02 90 00 ..*.n....
Status: No Error
cm> set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f
cm> init-update 255
=> 80 50 00 00 08 B1 04 15 2B 41 3F 62 AB 00 .P......+A?b..
(2668 usec)
<= 00 00 F9 02 71 E3 BB AD BD CD FF 02 00 00 3D 02 ....q.........=.
9C 31 C7 89 AD 44 8E 13 17 15 2E 5A 90 00 .1...D.....Z..
Status: No Error
cm> ext-auth plain
=> 84 82 00 00 10 CE 6C DC D2 8C BE 5E 33 EC 58 D0 ......l....^3.X.
57 3A 52 D2 24 W:R.$
(2288 usec)
<= 90 00 ..
Status: No Error
cm> delete -r a00000006203010c04
=> 80 E4 00 80 0B 4F 09 A0 00 00 00 62 03 01 0C 04 .....O.....b....
00 .
(1084 usec)
<= 6A 88 j.
Status: Reference data not found
jcshell: Error code: 6a88 (Reference data not found)
jcshell: Wrong response APDU: 6A88
Ignoring expected error
cm> upload -d -b 250 "D:\JCOP\eclipse\projects\DigitalTachograph\bin\digitaltachograph\javacard\digitaltachograph.cap"
=> 80 E6 02 00 16 09 A0 00 00 00 62 03 01 0C 04 08 ..........b.....
A0 00 00 00 03 00 00 00 00 00 00 00 ............
(2100 usec)
<= 00 90 00 ...
Status: No Error
=> 80 E8 00 00 FA C4 82 84 42 01 00 25 DE CA FF ED ........B..%....
02 02 04 00 01 09 A0 00 00 00 62 03 01 0C 04 11 ..........b.....
64 69 67 69 74 61 6C 74 61 63 68 6F 67 72 61 70 digitaltachograp
68 02 00 21 00 25 00 21 00 0E 00 29 03 3E 00 CD h..!.%.!...).>..
23 D2 01 BB 04 44 00 00 09 E3 4B E5 00 11 00 05 #....D....K.....
01 A2 04 01 00 04 00 29 04 00 01 07 A0 00 00 00 .......)........
62 00 01 02 01 07 A0 00 00 00 62 01 01 02 01 07 b.........b.....
A0 00 00 00 62 01 02 02 01 07 A0 00 00 00 62 02 ....b.........b.
01 03 00 0E 01 0A A0 00 00 00 62 03 01 0C 04 01 ..........b.....
01 DF 06 00 CD 00 00 00 80 00 00 FF 00 01 00 00 ................
00 01 81 03 13 00 12 07 03 00 00 02 01 03 06 0B ................
8C 81 00 00 00 80 00 0B 00 0B 01 01 00 00 0B F9 ................
00 80 00 11 00 0F 01 01 00 10 0E A9 0D D4 0D F7 ................
0E 07 0E 18 0E 26 0E 35 0E 44 0E 50 0E 72 0E 81 .....&.5.D.P.r..
0E 90 0E 9B 0E F5 11 05 11 1A 11 50 00 80 00 05 ...........P....
00 04 01 04 00 01 13 AF 13 B5 13 BA 14 0C 13 00 ................
(6775 usec)
<= 6A 80 j.
Status: Wrong data
jcshell: Error code: 6a80 (Wrong data)
jcshell: Wrong response APDU: 6A80
Unexpected error; aborting execution
I will be very happy if you can help me. I am desperately in need of a working debugging environment.
Thanks in advance!
Kind regards,
Mehmet* Processes incoming READ_BINARY APDUs. Returns data of the currently
* selected file.
* @param apdu where the offset is carried in header bytes p1 and p2.
* @param le expected length by terminal
* @return length of the response APDU
private short processReadBinary(APDU apdu, boolean protectedApdu, short leUnprotected) {
if (!hasFileSelected()) {
ISOException.throwIt(SW_CONDITIONS_NOT_SATISFIED);
byte[] buffer = apdu.getBuffer();
// retrieve p1p2 from apdu buffer
byte p1 = buffer[OFFSET_P1];
byte p2 = buffer[OFFSET_P2];
short offset = Util.makeShort(p1, p2); // offset encoded in P1/P2, 15 lowest bit
// offset encoded in P1/P2, 15 lowest bit
// check if le != 0 <-- no response expected
if (leUnprotected == 0) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (selectedFile == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
if ((selectedFile.getAccessConditions() & READ_REQUIRES_SM) == READ_REQUIRES_SM) {
if(!protectedApdu)
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
short fileSize = (short) selectedFile.getFileLength();
// check offset
if (offset >= fileSize) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
// check expected length
if ((short) (offset + leUnprotected) > fileSize) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
//ISOException.throwIt(SW_TAMAM);
short bufferOffset = 0;
crypto.setEncryptionStatus(isSelectedFileEncrypted());
if (protectedApdu) {
bufferOffset = crypto.getApduBufferOffsetDT(leUnprotected);
if(isSelectedFileEncrypted())
bufferOffset = crypto.getApduBufferOffset(leUnprotected);
apdu.setOutgoing();
Util.arrayCopyNonAtomic(selectedFile.getData(), offset, buffer, bufferOffset, leUnprotected);
return leUnprotected;
* Processes and UPDATE_BINARY apdu. Writes data in the currently selected
* file.
* @param apdu
* carries the offset where to write date in header bytes p1 and
* p2.
private void processUpdateBinary(APDU apdu, boolean protectedApdu) {
if (!hasFileSelected() || isLocked()) {
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
if ((selectedFile.getAccessConditions() & DigitalTachograph.UPDATE_ALW) != DigitalTachograph.UPDATE_ALW) {
if ((selectedFile.getAccessConditions() & DigitalTachograph.UPDATE_REQUIRES_SM) != DigitalTachograph.UPDATE_REQUIRES_SM) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
return;
}else if(!protectedApdu){
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
byte[] buffer = apdu.getBuffer();
byte p1 = buffer[OFFSET_P1];
byte p2 = buffer[OFFSET_P2];
short offset = Util.makeShort(p1, p2);
short readCount = (short) (buffer[ISO7816.OFFSET_LC] & 0xff);
//if (!protectedApdu){
readCount = apdu.setIncomingAndReceive();
while (readCount > 0) {
selectedFile.writeData(offset, buffer, OFFSET_CDATA, readCount);
offset += readCount;
readCount = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
private short processInternalAuthenticate(APDU apdu , boolean protectedApdu) throws CryptoException {
byte[] buffer = apdu.getBuffer();
short lc = (short) (buffer[OFFSET_LC] & 0xFF);
if (lc != (short) (KID_LENGTH * 2)) {
ISOException.throwIt(SW_WRONG_LENGTH);
if (apdu.setIncomingAndReceive() != lc) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
// Check if VU.CHR maches the one of the selected certificate on the card
if (Util.arrayCompare(buffer, (short) (OFFSET_CDATA + KID_LENGTH), keyStore.selected_KID, (short) 0, KID_LENGTH) != 0) {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
if (Util.arrayCopyNonAtomic(buffer, OFFSET_CDATA, Rnd1, (short) 0, (short) 8) != (short) 8) { // Receive Rnd1
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
// Hash(PRnd2||K1||Rnd1||VU.CHR)
random.generateData(PRnd2, (short) 0, (short) 90);
random.generateData(K1, (short) 0, (short) 16);
crypto.shaDigest.update(PRnd2, (short) 0, (short) 90); // PRnd2
crypto.shaDigest.update(K1, (short) 0, (short) 16); // PRnd2||K1
crypto.shaDigest.doFinal(buffer, OFFSET_CDATA, lc, digest, (short) 0); //Rnd1||VU.CHR
BigNumber mod = new BigNumber((short) 128);
mod.init(keyStore.Card_PubMod, (short) 0, (short) keyStore.Card_PubMod.length, BigNumber.FORMAT_HEX);
mod.subtract(signed, (short) 0, (short) 128, BigNumber.FORMAT_HEX);
if (mod.compareTo(signed, (short) 0, (short) 128, BigNumber.FORMAT_HEX) == -1) {
mod.toBytes(signed, (short) 0, (short) 128, BigNumber.FORMAT_HEX);
// To be added: if the selected private key is considered corrupted, the processing state returned is '6400' or '6581'.
signed[0] = (byte) 0x6A;
Util.arrayCopyNonAtomic(PRnd2, (short) 0, signed, (short) 1, (short) 90);
Util.arrayCopyNonAtomic(K1, (short) 0, signed, (short) 91, (short) 16);
Util.arrayCopyNonAtomic(digest, (short) 0, signed, (short) 107, (short) 20);
signed[127] = (byte) 0xBC;
if (!keyStore.cardPrivateKey.isInitialized()) {
CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
try {
crypto.rsaSigner.init(keyStore.cardPrivateKey, Signature.MODE_SIGN);
crypto.rsaSigner.doFinal(signed, (short) 0, (short) 128, signed, (short) 0);
} catch (Exception e) {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
if (!keyStore.selectedPublicKey.isInitialized()) {
CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
try {
crypto.rsaCipher.init(keyStore.selectedPublicKey, Cipher.MODE_ENCRYPT);
crypto.rsaCipher.doFinal(signed, (short) 0, (short) 128, signed, (short) 0);
} catch (Exception e) {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
apdu.setOutgoing();
Util.arrayCopyNonAtomic(signed, (short) 0, buffer, (short) 0, (short) 128);
return (short) signed.length;
private void processExternalAuthenticate(APDU apdu) {
short equipmentType = 0;
if (keyStore.Selected_Cert != null) {
equipmentType = (short) keyStore.Selected_Cert.CHA[6]; // check equipment type
if (equipmentType != (short) 1 && equipmentType != (short) 2 && equipmentType != (short) 3 && equipmentType != (short) 4 && equipmentType != (short) 6) {
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); // Instead of 6F00 throw a more meaningfull SW in case CHA is not valid.
if (Util.arrayCompare(keyStore.Selected_Cert.CHA, (short) 0, TACHOGRAPH_AID, (short) 0, (short) 6) != 0) {
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
byte[] buffer = apdu.getBuffer();
byte p1 = (byte) (buffer[OFFSET_P1] & 0xff);
byte p2 = (byte) (buffer[OFFSET_P2] & 0xff);
if (p1 != 0 || p2 != 0) {
ISOException.throwIt(SW_WRONG_P1P2);
short lc = (short) (buffer[OFFSET_LC] & 0xFF);
if (lc != (short) (128)) {
ISOException.throwIt(SW_WRONG_LENGTH);
if (apdu.setIncomingAndReceive() != lc) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
Util.arrayCopyNonAtomic(buffer, OFFSET_CDATA, signed, (short) 0, (short) 128); // receive the cryptogram from the VU
// decrypt the encrypted message with the card private key
try {
crypto.rsaCipher.init(keyStore.cardPrivateKey, Cipher.MODE_DECRYPT);
crypto.rsaCipher.doFinal(signed, (short) 0, (short) 128, signed, (short) 0);
} catch (Exception e) {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
// verify the signature with the VU public key
try {
crypto.rsaCipher.init(keyStore.selectedPublicKey, Signature.MODE_VERIFY); // Cipher.MODE_ENCRYPT
crypto.rsaCipher.doFinal(signed, (short) 0, (short) 128, signed, (short) 0);
} catch (Exception e) {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
if (signed[0] != (byte) 0x6A || signed[127] != (byte) 0xBC) {
ISOException.throwIt(Util.makeShort(signed[0], signed[127]));
try {
verifyCardCertificates();
Util.arrayCopyNonAtomic(signed, (short) 1, preDigest, (short) 0, (short) 106); // accumulate preDigest
Util.arrayCopyNonAtomic(Rnd3, (short) 0, preDigest, (short) 106, (short) 8); // accumulate preDigest
Util.arrayCopyNonAtomic(keyStore.Card_Cert.CHR, (short) 0, preDigest, (short) 114, (short) 8); // accumulate preDigest
Util.arrayCopyNonAtomic(signed, (short) 91, K2, (short) 0, (short) 16); // receive K2 value
crypto.shaDigest.update(signed, (short) 1, (short) 106); // PRnd4||K2
crypto.shaDigest.update(Rnd3, (short) 0, (short) 8); // Rnd3
crypto.shaDigest.doFinal(keyStore.Card_Cert.CHR, (short) 0, (short) 8, digest, (short) 0); //||Card.CHR
} catch (Exception e) {
ISOException.throwIt(SW_TAMAM);
if (Util.arrayCompare(signed, (short) 107, digest, (short) 0, (short) 20) != 0) {
ISOException.throwIt(SW_TAMAM);
volatileState[0] |= MUTUAL_AUTHENTICATED;
try {
DTUtil.xor(K1, (short) 0, K2, (short) 0, KaKb, (short) 0, (short) 16);
Util.arrayCopyNonAtomic(Rnd3, (short) 4, SSC, (short) 0, (short) 4); // tail of Rnd3
Util.arrayCopyNonAtomic(Rnd1, (short) 4, SSC, (short) 4, (short) 4); // tail of Rnd1
} catch (Exception e) {
ISOException.throwIt(SW_TAMAM);
try {
keyStore.setKey_Ka(KaKb, (short) 0);
keyStore.setKey_Kb(KaKb, (short) 8);
keyStore.setSecureMessagingKeys(KaKb, (short) 0, KaKb, (short) 0);
} catch (Exception e) {
ISOException.throwIt(SW_TAMAM_DEGIL);
return;
private short returnPreDigest(APDU apdu) {
byte[] buffer = apdu.getBuffer();
apdu.setOutgoing();
Util.arrayCopyNonAtomic(preDigest, (short) 0, buffer, (short) 0, (short) 122);
return (short)preDigest.length;
private short returnDigest(APDU apdu) {
byte[] buffer = apdu.getBuffer();
apdu.setOutgoing();
Util.arrayCopyNonAtomic(digest, (short) 0, buffer, (short) 0, (short) 20);
return (short)digest.length;
private short returnOriginalText(APDU apdu) {
byte[] buffer = apdu.getBuffer();
apdu.setOutgoing();
Util.arrayCopyNonAtomic(signed, (short) 0, buffer, (short) 0, (short) 128);
return (short)signed.length;
private void processVerify(APDU apdu) { // Verify_CHV(Pin_Ws)
byte[] buffer = apdu.getBuffer();
// retrieve the PIN data for validation.
byte byteRead = (byte) (apdu.setIncomingAndReceive());
// the PIN data is read into the APDU buffer
// at the offset ISO7816.OFFSET_CDATA the PIN data length = byteRead
if (pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead) == false) {
ISOException.throwIt(SW_VERIFICATION_FAILED);
return;
private void processPSO(APDU apdu) { // verify certificate
byte[] buffer = apdu.getBuffer();
byte p1 = (byte) (buffer[OFFSET_P1] & 0xff);
byte p2 = (byte) (buffer[OFFSET_P2] & 0xff);
short lc = (short) (buffer[ISO7816.OFFSET_LC] & 0xFF);
if (p1 == (byte) 0x00 && p2 == P2_VERIFYCERT) {
if (lc != TACHO_CERT_LENGTH) {
ISOException.throwIt(SW_WRONG_LENGTH);
if (apdu.setIncomingAndReceive() != lc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
try { // copy the certificate to be verified from APDU buffer to cert object
Util.arrayCopyNonAtomic(buffer, OFFSET_CDATA, cert, (short) 0, lc);
} catch (Exception e) {
ISOException.throwIt(SW_TAMAM);
if (Util.arrayCompare(keyStore.selected_KID, (short) 0, keyStore.ERCA_KID, (short) 0, KID_LENGTH) == 0) {
keyStore.VUCA_Cert.verifyCert(cert, keyStore.selectedPublicKey, keyStore.selected_KID);
} else if (Util.arrayCompare(keyStore.selected_KID, (short) 0, keyStore.VUCA_Cert.CHR, (short) 0, KID_LENGTH) == 0) {
keyStore.VU_Cert.verifyCert(cert, keyStore.selectedPublicKey, keyStore.selected_KID);
} else {
ISOException.throwIt(SW_CERT_VERIFICATION_FAILED); // Selected keyId, with MSE, is neither ERCA_KID nor VUCA_KID
} else {
ISOException.throwIt(SW_CERT_VERIFICATION_FAILED);
return;
private short processGetChallenge(APDU apdu, boolean protectedApdu) {
byte[] buffer = apdu.getBuffer();
byte p1 = (byte) (buffer[OFFSET_P1] & 0xff);
byte p2 = (byte) (buffer[OFFSET_P2] & 0xff);
if (p1 != 0 || p2 != 0) {
ISOException.throwIt(SW_WRONG_P1P2);
random.generateData(Rnd3, (short) 0, (short) 8);
short Le = apdu.setOutgoing();
if (Le != (short) 8) {
ISOException.throwIt(SW_WRONG_LENGTH);
Util.arrayCopyNonAtomic(Rnd3, (short) 0, buffer, (short) 0, (short) 8);
return Le;
private void processMSE(APDU apdu) {
byte[] buffer = apdu.getBuffer();
if (buffer[OFFSET_P1] == (byte) 0xC1 && buffer[OFFSET_P2] == P2_DST) {
short lc = (short) (buffer[OFFSET_LC] & 0xFF);
if (lc != (short) (KID_LENGTH + 2)) {
ISOException.throwIt(SW_WRONG_LENGTH);
if (apdu.setIncomingAndReceive() != lc) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
if (buffer[OFFSET_CDATA] != (byte) 0x83) {//check the tag of the data
ISOException.throwIt(SW_SECURE_MESSAGING_DATA_OBJECTS_MISSING);
} else if (buffer[OFFSET_CDATA + 1] != (byte) 0x08) {
ISOException.throwIt(SW_INCORRECT_DATA_OBJECT); // check if the key is already selected one
} else if (Util.arrayCompare(buffer, (short) (OFFSET_CDATA + 2), keyStore.selected_KID, (short) 0, KID_LENGTH) != 0) {
if (Util.arrayCompare(buffer, (short) (OFFSET_CDATA + 2), keyStore.ERCA_KID, (short) 0, KID_LENGTH) == 0) {// KID is EUR_KID
keyStore.selected_KID = keyStore.ERCA_KID;
keyStore.selectedPublicKey = keyStore.eurPublicKey;
keyStore.Selected_Cert = null; // ERCA public key is selected
return;
} else if (Util.arrayCompare(buffer, (short) (OFFSET_CDATA + 2), keyStore.VUCA_Cert.CHR, (short) 0, KID_LENGTH) == 0) {// KID is MSCA_KID
keyStore.Selected_Cert = keyStore.VUCA_Cert;
} else if (Util.arrayCompare(buffer, (short) (OFFSET_CDATA + 2), keyStore.VU_Cert.CHR, (short) 0, KID_LENGTH) == 0) { // KID is VU_KID
keyStore.Selected_Cert = keyStore.VU_Cert;
} else {
ISOException.throwIt(SW_REFERENCE_DATA_NOT_FOUND);
}// KID not found
keyStore.selectedPublicKey = keyStore.Selected_Cert.publicKey;
keyStore.selected_KID = keyStore.Selected_Cert.CHR;
} else { // if the KID is already set, just return
return;
} else {
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
private void processSelectFile(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short lc = (short) (buffer[OFFSET_LC] & 0x00FF);
// retrieve p1p2 from apdu buffer
byte p1 = buffer[OFFSET_P1];
byte p2 = buffer[OFFSET_P2];
short p1p2 = Util.makeShort(p1, p2);
apdu.setIncomingAndReceive();
if (p1 == 4) {
if (lc == (short) TACHO_AID_LENGTH) {
if (Util.arrayCompare(buffer, (short) OFFSET_CDATA, TACHOGRAPH_AID, (short) 0, (short) TACHO_AID_LENGTH) == 0) {
selectedFile = fileSystem.getDT();
fileSystem.selectDT();
volatileState[0] |= FILE_SELECTED;
return;
} else {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
} else if (lc != 2) {
ISOException.throwIt(SW_WRONG_LENGTH);
short fid = Util.getShort(buffer, OFFSET_CDATA);
if (fileSystem.getFile(fid) != null) {
selectedFile = fileSystem.getDT();
fileSystem.selectDT();
volatileState[0] |= FILE_SELECTED;
return;
} else if (p1 == 2) {
if (lc != 2) {
ISOException.throwIt(SW_WRONG_LENGTH);
short fid = Util.getShort(buffer, OFFSET_CDATA);
if (fileSystem.getFile(fid) != null) {
selectedFile = fileSystem.getFile(fid);
volatileState[0] |= FILE_SELECTED;
return;
} else {
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
setNoFileSelected();
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
public static void setNoFileSelected() {
if (hasFileSelected()) {
volatileState[0] ^= FILE_SELECTED;
public static boolean hasFileSelected() {
return (volatileState[0] & FILE_SELECTED) == FILE_SELECTED;
public static boolean hasMutuallyAuthenticated() {
return (volatileState[0] & MUTUAL_AUTHENTICATED) == MUTUAL_AUTHENTICATED;
static boolean isLocked() {
return (persistentState & LOCKED) == LOCKED;
public boolean isSelectedFileEncrypted() {
return ((selectedFile.getAccessConditions() & DigitalTachograph.ENCRYPTED) == DigitalTachograph.ENCRYPTED);
} -
I am new to Javacard. I would like to build an applet that displays text messages to the user and get user input from an input source such as a cell phone with a javacard. Does anyone have an example? I have downloaded the javacard 2.1.2 and I can somewhat understand the applet code. But I don't know how the javacard will interface with an external display source. Is that a specification that I can read about this requirement? Also, what kind of simulation environment can I use to test this applet. For example, I want to display "hello world" to the cell phone screen or display a menu and let the user selects the menu.
Thanks,
-JohnBut it is very expensive , it cost US$3xxxx
to display anything on phone screen you have to use
JavaCard SIM API, which let you use SIM Toolkit
commands
you also have to have a javacard sim card (like
Gemplus GemXplore Xpresso v3) and load your applets on
it
sim api can be downloaded from www.etsi.org
standard number 03.19
if you buy i.e. gemplus cards, you can also get
development environment
it cotains phone simulator, which can help you in
testing the applets
you just simulate a card, and a phone, load the applet
on a simulated card, connect the phone to it and voila
Kuba -
Error on installing applet into JAVA Simulator
Hello all, i have a very basic question (well...for this you can see how newbie i am...)
I'm having problems installing an applet into the simulator.
My helloWorld.src file looks like this:
powerup;
// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
// create HelloWorld
0x80 0xB8 0x00 0x00 0x0b 0x09 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x1 0x00 0x7F;
// Select HelloWorld
0x00 0xA4 0x04 0x00 9 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x1 0x7F;
powerdown;I run cref like this:
cref -o demoeeand apdutool like this:
apdutool helloWorld.scr > hello.outthen, the result i get is:
Java Card 2.2.2 APDU Tool, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
Opening connection to localhost on port 9025.
Connected.
Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x01
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0b, 09, a0, 00, 00, 00, 62, 03, 01, 0c, 01, 00, Le: 00, SW1: 64, SW2: 43
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 0c, 01, Le: 00, SW1: 6d, SW2: 00so, the 6443 means
Applet not found for installation.
�Cause: An attempt was made to create an applet instance, but the applet code was not installed on the card.
�Solution: Verify that the applet package has been downloaded to the card.
so, what step did i miss here??
thank you
PS: i also tried with JCWDE but the error was the same
Message was edited by:
HelriI've noticed that my applet uses the java.lang package. For what i've read the CREF only has installed the Installer Applet and the javacard.framework package, so can that be the problem? i.e., do I have first to load the java.lang package into the simulator??
I really need help...i'm literally stuck on this.... -
Beginner basics to deploy a JavaCard applet
I've been struggling with the JavaCard 2.2 Dev Kit for a while now. I've read tons of material on writing JavaCard applets and OpenCard host apps, and feel I have a firm grasp of that. My problem now is in how to get the applet java file into an emulator, and then get a host app running that will communicate with the emulated card.
I've read the documentation and demos that came with the Dev Kit but nowhere does it simply list the big picture procedure for deploying a JC applet, nor for how to communicate with an emulated card, nor which emulator to use.
The PDF files included are filled with references to CAP, JCWDE, JCA, CREF, etc, etc, ad nauseum, all of which are poorly explained, or simply not explained at all.
I just want something like this:
1) Compile the applet's java file
2) Run A to generate a B file
3) Run C to start the card emulator
4) Do X to install your B file into the emulated card
5) Do Y to have your host program talk to the emulated card
etc
etc
etc
Can anyone help?all of which are poorly explained,
Read the cJDK user guide that comes with the kit. The samples and how to use the Sun JC tools are explained in detail there. Chapter 4 is Running applets in the simulated environment. Don't jump around the document but read it in order. -
Hi all,
I faced some problems with the simulator.
I am practicing the java applets according to the java card developement kit user's guide.
But I got the problem below.
C:\JavaCard\java_card_kit-2_2\samples\classes>converter -config ..\src\com\sun\j
avacard\samples\wallet\Wallet.opt
Java Card 2.2 Class File Converter (version 1.3)
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to lic
ense terms.
conversion completed with 0 errors and 0 warnings.
C:\JavaCard\java_card_kit-2_2\samples\classes>scriptgen -o Wallet.scr ..\..\clas
ses\com\sun\javacard\samples\wallet\javacard\wallet.cap
Unaccessable: ..\..\classes\com\sun\javacard\samples\wallet\javacard\wallet.cap
C:\JavaCard\java_card_kit-2_2\samples\classes>cd..
C:\JavaCard\java_card_kit-2_2\samples>cd src\demo
C:\JavaCard\java_card_kit-2_2\samples\src\demo>scriptgen -o Wallet.scr ..\..\cla
sses\com\sun\javacard\samples\wallet\javacard\wallet.cap
Java Card 2.2 APDU Script File Builder (version 0.11)
Copyright 2002 Sun Microsystems, Inc. All rights reserved.
APDU script file for CAP file download generated.
C:\JavaCard\java_card_kit-2_2\samples\src\demo>jcwde 90250 jcwde.app
usage: jcwde [-help] [-p port] [-nobanner] [-version] configfile
C:\JavaCard\java_card_kit-2_2\samples\src\demo>apdutool -nobanner -notar demo1.s
cr > demo1.scr.jcwde.out
Invalid flag -notar.
usage: apdutool [-h hostname] [-nobanner] [-noatr] [-o outputFile] [-p port] [-s
serialPort ][-version] [inputFile ...]
C:\JavaCard\java_card_kit-2_2\samples\src\demo>apdutool -nobanner -noatr demo1.s
cr > demo1.scr.jcwde.out
java.net.ConnectException: Connection refused: connect
What is the Connection refused?
May I know what is the steps to make the example run successfully?
Sorry if this question already posted before.
If you don't mind pls give me some guide.
Your response is highly appreciated!
Thank you in advance.
Warmest regards,
AliceHi Joseph,
I guess what you mean is there is something wrong to the command below:
C:\JavaCard\java_card_kit-2_2\samples\src\demo>jcwde 90250 jcwde.appusage: jcwde [-help] [-p port] [-nobanner] [-version] configfile
I tried the command below, but got another error:
C:\JavaCard\java_card_kit-2_2\samples\src\demo>jcwde -p 90250 jcwde.app
Java Card 2.2 Workstation Development Environment (version 0.18).
Copyright 2002 Sun Microsystems, Inc. All rights reserved.
jcwde is listening for T=0 Apdu's on TCP/IP port 90,250.
java.lang.IllegalArgumentException: Port value out of range: 90250
Exception on TCP/IP socket port # : 90250
jcwde terminating on receipt of SimulationException. See previous messages for
cause.
com.sun.javacard.jcwde.SimulationException
*********************************************************Sorry, I am very new in java card, so might need a little bit more explanation if you don't mind.
Thank you in advance! -
Simulator supports KeyPair.ALG_RSA?
I'm working on an javacard applet with rsa algorithm.
When I try to generate a keypair with the ALG_RSA, I always get an error (6F00).
I used KeyPair.genKeyPair to generate a pair of RSA keys with 1024-bits long.
When I tested applet source In Debug Mode, Simulator says the the source is not found in first line below.
KeyPair = new KeyPair(KeyPair.ALG_RSA, (short)1024);
KeyPair.genKeyPair();
But when I generate the keypair with ALG_RSA_CRT it works.
The important thing is that I'm testing with not Card but Simulator.
I'm working with Eclipse 3.2 with jcop plugin.
Any idea?
Jenny.
Edited by: JennyJPN on May 27, 2008 11:46 PMJCOP does not support RSA plain, but only the CRT version.
Maybe you are looking for
-
Using process variables in conditional transition
HI, I am usin Oracle BPM 1.03 I wanto to have a value of a variable visible in the user's inbox. Therefore, I need to use project level variables. I also want to use this variable in conditional tranistion, but the condition editor only allows Instan
-
MacBook Pro (Late 2007, 2.4/2.2GHz) - Built-in isight camera issue
I have a MBP (as mentioned, Late 2007) running Lion 10.7.2 (updated yesterday). And I have a problem with the built-in iSight camera Same with photo booth and skype. So far I have tried 1) shutdown, unplug power, remove battery, press power for 5 sec
-
My Xperia M4 Dual ringtone doesnt ring incoming calls. Speaker works fine when I listen music. And sim 1 keeps rejecting calls. If there is anything Sony can do, please resolve.
-
Insert into multiple table view
I have a view with multiple table query and and INSTEAD OF trigger on the view that inserts into multiple tables. When I attempt to do a commit out of a ADF Creation Form, I get the following error: ORA-01779: cannot modify a column which maps to a n
-
Adapter Exchange Program Request/Shipment Status Support or Contact Info
If I submitted an adapter exchange request online on 14 October 2008 and have not yet received the new adapter and return shipment info for the old adapter, how do I request follow-up assistance/support using the Online Assistant or directly via e-ma