📜 ⬆️ ⬇️

Use Java smart cards to protect software. Chapter 3. Installing and Configuring IDE

image

In this series of articles we will discuss the use of Java smart cards (cheaper analog keys of electronic keys) to protect software. The cycle is divided into several chapters.

To read and understand the information from the articles you will need the following skills:

The purpose of the cycle is to acquaint the reader with Java maps (there is very little literature in Russian on their use). The cycle does not claim the status of "Guidelines for the development of software protection based on Java cards" or the title of "Handbook of Java cards."
')

The composition of the cycle:




1. Install the necessary software


I didn’t come across a normal IDE that fully supported Javacard SDK 2.2.1. Well, except that JCOP Tools, which IBM sold NXP, and NXP somewhere lost. But even if you find this kit - it is paid. To use it rumored to be required and the signing of the NDA. There are several paid SDKs of which I only worked with the CyberFlex SDK. Did not like.

NetBeans 6.9+ includes the Javacard Tools plugin, which is really quite powerful. But, unfortunately, this plugin currently supports only the development of maps compatible with Javacard SDK 3.0 Connected. And there are few such cards on the market. However, no one bothers to develop an applet in this environment without using the capabilities of the Java Card API 3.x, and then just compile / convert the source of the applet with the usual SDK 2.2.1.

For development, I used the usual Eclipse IDE for Java Developers for a long time, which I brought to mind a bit by embedding the necessary tools from the SDK. So, download the latest version of the Eclipse IDE for Java Developers from the Eclipse website.

Download the archive just unzip somewhere (not in Program Files preferably) to your hard drive. I usually put it in the root of the disk in the eclipse-java folder. Hereinafter, it is undesirable to use Russian letters and spaces in the folder names.

Next we need Java SDK of any version. It is usually called JavaSE (Java Standard Edition SDK), JDK. Since Oracle bought Sun, the link may change, but Google will help you if this happens. So far you can download from here. It comes with an installer, so just install it as usual.

And we also need the Java Card Development Kit 2.2.1. I also usually put it in the root of the hard disk.

Now you need to adjust the system a bit. Click Windows + Break together on the keyboard or simply open the properties of My Computer. Click the Advanced tab and click the Environment Variables button. In system variables you need to add the following:

JC_HOME = C: \ java_card_kit-2_2_1 - the path where you unpacked the Java Card Development Kit
JAVA_HOME = c: \ j2sdk1.4.1 - the path where the Java SDK was installed. If it is installed in Program Files, it is better to use the short 8.3 path "C: \ Progra ~ 1 \ ...".

And now you need to add the value ";% JC_HOME% \ bin;% JAVA_HOME% \ bin;" to the end of the PATH variable . Moreover, the variables% ..% is better to open and specify in the PATH path completely.

You can check the installation correctness by running the build_samples.bat file located in the folder with the Java Card SDK (samples subdirectory). True, if you use a Java Developer Kit other than 1.3 or 1.4, you will have to adjust it a bit. Open the build_samples.bat file and add the "-target 1.2 -source 1.2" parameters to the " set JCFLAGS" line (without quotes, of course). This is necessary because the file converter for cards expects files compiled by a compatible compiler).

After starting build_samples correctly, the files HelloWorld.cap, HelloWorld.exp, HelloWorld.jca should appear in the % JC_HOME% \ samples \ classes \ com \ sun \ javacard \ samples \ HelloWorld \ javacard \ folder. The HelloWorld.cap file is ready for immediate upload to the map.

2. Configure Eclipse


Run Eclipse. When you first start you will be asked about the desired location of the workspace. I usually leave the default location.

Create a new java project. File -> New -> Project -> Java -> Java Project. Call it somehow. You can place outside the workspace, if you so convenient. The remaining settings can be left as is. Click Next. Go to the Libraries tab and remove from there all that is there. Click the Add External JAR button and select the % JC_HOME% \ lib \ api.jar file (% JC_HOME% = inside the Java Card SDK that you unpacked). Click Finish.

The Package Explorer window will appear on the left. Right-click on the src folder and select New -> Package. We need to create a package, which will include our test applet. Call it as you like. For example, testpackage. Right-click on the package icon in the Package Explorer. Select New -> Class. As a superclass (the class from which the class of our applet will be inherited) you need to select "javacard.framework.Applet". Mark the creation of all the stubs that Eclipse offers, except for main () (Constructors from superclass, Inherited abstract methods). Enter the class name of the applet. For example, TestApplet. Click Finish.

As you can see, Eclipse generated an applet stub, which we will have to turn into a full-featured applet in the next chapters.

Now we need to make life a little easier by writing files to automate the process of compiling the applet and converting it into a * .cap file. For this we need to create two files. One for compiling and converting and applet, and the other for loading into the map. However, if you want, you can combine everything into one file. Notice that we called the package mytestapplet, and the applet MyTestApplet.

So build.bat:

@echo off set APPLET_HOME=C:\Work\JavaCard\MyTestApplet set PACKAGE_NAME=mytestapplet set APPLET_NAME=MyTestApplet del /q %APPLET_HOME%\bin\%PACKAGE_NAME%\*.class del /q %APPLET_HOME%\bin\%PACKAGE_NAME%\javacard\*.* %JAVA_HOME%\bin\javac -g -d %APPLET_HOME%\bin -classpath %JC_HOME%\samples\classes\;%JC_HOME%\lib\api.jar;%JC_HOME%\lib\installer.jar -source 1.2 -target 1.2 %APPLET_HOME%\src\ %JC_HOME%\bin\converter -config %APPLET_HOME%\%APPLET_NAME%.opt pause 


I think everything is clear without comments. And the sample MyTestApplet.opt file from which the information is read by the converter (the last but one line * .bat):

 -out CAP JCA -exportpath E:\java_card_kit-2_2_1\api_export_files;D:\java_card_kit-2_2_1\lib\api.jar -classdir C:\Work\JavaCard\MyTestApplet\bin\ -d C:\Work\JavaCard\MyTestApplet\bin\ -verbose -applet 0xa0:0x46:0x52:0x41:0x43:0x54:0x41:0x4c:0x0:0x1 mytestapplet.MyTestApplet mytestapplet 0xa0:0x46:0x52:0x41:0x43:0x54:0x41:0x4c:0x0 1.0 


Notice the -applet directive (it indicates the applet's AID) and the last line (AID and package version). * .cap file after our manipulations should be in the folder C: \ Work \ JavaCard \ MyTestApplet \ bin \.

You can add this file to the Eclipse menu via Run -> External Tools -> External Tools Configurations. I think everything is quite trivial and will not require an explanation.

3. IntelliJ (JetBrains) IDEA


I must say that I am an IDEA fan. IDEA is the ideal ideal development environment for me (sorry for repetitions, I was deeply moved). Therefore, some time later I left Eclipse, moved to IDEA, and transformed bat files into simple Ant tasks. I am quite pleased with the result.

I highly recommend that you do the same. Although, of course, the taste and color ...

4. Gratitude to patient readers.


Thanks to everyone who read to this place. Gratitude and indignation are accepted.

I will welcome any questions in the comments and try to update the article so that it includes the answers.

Source: https://habr.com/ru/post/255533/


All Articles