Javacard-Compiling and installing an applet

Source: Internet
Author: User

I finally recieved the smart-cards I'm going to use for my implementation:

TheJcop21 18 KAndCosmo V7 128 K.

Note that the jcop21 requires the Java card SDK 2.2.1.

This is a guide how to compile and install a javacard applet forJcop21Javacard:

1. Install gpshell

You will need gpshell to install the applets to the javacard as apdutool pcsc support is optional (and didn't work for me ...).

Go to the gpshell "SourceForge" website:

-> Http://sourceforge.net/projects/globalplatform/files/

DownloadGlobalplatform library 6.0.0

Unpack and install:

 
./Configuremakesudo make install

Now downloadGPShell-1.4.4And repeat the above steps for gpshell.

You will maybe need to install some dependencies.

Note: note that in the unpacked gpshell folder, you will find useful gpshell scripts examples.

2. Compile and convert your applet

Let's suppose we work on an applet called helloworld in the packageMe. Test. Hello.

The source-FileHelloworld. Java(You can take some code from the SDK samples) goes to"Helloworld/src/ME/test/Hello". Make sure it fits to the package structure specified inHelloworld. Java.

Compile from the "helloworld" folder by using javac: The-source and-target options will make sure you don't get the "class file format error ".

 
Error: UnsupportedClassFile Format of version49:0

If you get the error, try modifying the source and target arguments.

 
Javac-g-Source1.2-Target1.2-Classpath $ jc_home/lib/API. jar: $ jc_home/lib/Installer. Jar src/ME/test/Hello/helloworld. Java-D Bin

Now we need to convert the class file to a cap file: For this we will write a little config file for the Java card converter tool:

Lets call the file "helloworld. Opt ":

-Classdir Bin - Out  Exp JCA cap -Exportpath $ jc_home/ Api_export_files -Applet 0x01 : 0x02 : 0x03 : 0x04 : 0x05 : 0x06 : 0x07 : 0x08 : 0x09 :0x00 : 0x00  Me. Test. Hello. helloworldme. Test. Hello  0x01 : 0x02 : 0x03 : 0x04 : 0x05 : 0x06 : 0x07 : 0x08 : 0x09 : 0x00   1.0 

This file shoshould be located in the "helloworld" folder. Note that you can of course choose your own AIDS.

You will now have. Cap . ExpAnd. JCAFiles in the"Bin/ME/test/Hello/javacard"Folder.

3. Download the applet to the Java card

If not already installed: Install "pcscd" with your packet Manager (APT-Get)

Now first, check if you have a card reader and a card connected, by using "pcsc_scan ".

Go to the folder where you unpacked gpshell. And try if the communication with the card works by using one of the sample gpshell scripts provided. For example:

 
Gpshell listgp211.txt

This shoshould give you the names of some applets that are currently installed.

Warning: If you have problem authenticating with your card (cryptogram errors), you'll have to check what keys are used. The card will be locked after too many attempts! (Jcop, 10 attempts I think)

Next, you will have to copy the helloinstall <your-card>. txt file to the"Helloworld/bin/ME/test/Hello/javacard"And edit a few lines in order to fit your program. You will have to change the aid in the DELETE command and the CAP file for the install command. For simplicity I call the file"Install.gpshell.txt":

 Mode_211enable_traceestablish_contextcard_connect  Select - Aid a000000003000000open_ SC -SCP 2 -Scpimpl 0x15 -Security 1 -Keyind 0 -Keyver 0 -Mac_key 404142434445464748494a4b4c4d4e4f-enc_key 404142434445464748494a4b4c4d4e4f //  Open secure channel Delete-aid 01020304050607080900   //  Your aid Delete-aid 0102030405060708090   //  Package aid Install-file test. Cap-instparam c90145-priv 2  //  Test. Cap gen. by Converter  Card_disconnectrelease_context 

Finally run:

 
Gpshell install.gpshell.txt

If everything was OK, you should be able to see the application using the"Listgp211.txt"File.

If you want to delete the applet, just check the sample script files in the gpshell folder and change the aid.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.