Research on patch mechanism of smart card operating system

With the continuous advancement of science and technology, the application of smart cards has been involved in various fields of human life, such as business, medical, insurance, transportation, social public utilities and other fields. At the same time, the number of smart cards in the hands of users is also increasing, especially for the same kind of cards, it is often necessary to change a new card due to the need to upgrade card information. Therefore, how to effectively use the smart card, that is, how to design the smart card patch mechanism to update the card application after card issuance or modify the card operating system BUG is an important issue.

1 Smart Card Operating System Overview

Smart card operating system, referred to as COS. COS is generally developed around the characteristics of the smart cards it serves. Compared to the operating systems on those common microcomputers, COS is essentially closer to the monitoring program. The communication between the smart card and the terminal is in the form of a command. According to the requirements of the specification, the system adopts the command response pair mode. The read/write device issues a command, and the smart card receives the command for processing. After the processing is completed, the corresponding response is sent. Therefore, the most fundamental problem that COS needs to solve is how to handle and respond to external commands.

The entire COS is to store and manage data through files. The file structure system is similar to the DOS directory management method. It can implement multi-level directories, and multiple types of files can be created under each directory. The file system is composed of a DF (Dedicated File) and a basic file EF (Elementary File). The DF of the root directory is called MF, and any file organization is a structure starting with MF. All the remaining files (DF, EF) is a branch of MF. DF and EF branches can be created under DF. EF is the end. Files cannot be created under EF. The file system structure is shown in Figure 1.

File structure of smart card operating system

Figure 1 File structure of the smart card operating system

Fig. 1 File structures of COS

The smart card operating system COS is designed to be a cyclical way when designing the main function. The loop implements the smart card to receive commands, processes them, and sends the corresponding responses after processing.

The main program receives the command sent by the terminal and passes the transmission management module. First, it determines what kind of instruction is, and needs to operate on those files. After the operation, it returns to the main program for processing, and returns the corresponding data and execution result. The interaction process with the terminal is performed by continuous operation of the files in the card.

2 Application background of smart card operating system patch mechanism

2. 1 The use of patches in smart card operating systems

Usually, the download mode of the smart card operating system COS is determined by the chip provider. Before downloading the COS, the state of the card is the BootLoader state. The card BootLoader has its own operation instructions. The patch mechanism in this paper studies 51 series smart cards as an example. In actual operation, the compiler used is the Keil compiler. After the program is compiled, a .hex file will be generated. When downloading the program, the address information and corresponding data information in the .hex file are parsed out, and then the download command of the BootLoader can be used. .

Under normal circumstances, after downloading COS, if you find that there are program errors in COS or need to add new functions and need to modify some letters or files, the easiest way is to reissue the card, that is, recycle the card and re-download COS. The card is already in the hands of the user. At this time, not only the card needs to be recycled, but also the stage of COS downloading, personalization, etc. This is very troublesome. Therefore, we should give a patch (PATCH) interface when designing the card operating system. In this case, when the card needs to add new functions or modify the bug, just download the patch to the card.

2. 2 How to implement the patch

The traditional patch design method is to reserve one or more pieces of code directly in the program. In this way, when you need to download the patch, you only need to write the patch to the reserved address. However, because the code is reserved. The size and number of patches to be downloaded in the future cannot be determined. Therefore, this implementation method has certain limitations. Moreover, when the patches to be downloaded are larger or larger, the code overlap is more likely to occur, so that the COS is in the process of execution. An exception error has occurred.

Based on the above problems, the following is a combination of 51 series smart cards to develop a patch mechanism, which is suitable for patch download of any 51 series smart card. This method is realized by establishing PATCH function table and designing the interface of calling patch in the main program of the operating system. Patch downloading and management can be downloaded according to different patch classification indexes, and is no longer limited by the size of the patch, and supports downloading of multiple patches.

3 smart card operating system patch mechanism design

3. 1 Implementation mechanism

In this paper, the patching mechanism of the smart card operating system is implemented by means of an address mapping table. That is, a PATCH function table is placed in EEPROM / FLASH (ram) (or an internal management file storage is created). The data recording format is shown in Table 1. The patch ID value is customized or operator defined. The patch attribute byte definition is shown in Table 2.

3. 2 implementation

1) Pre-create a patch index table in the system data area of ​​the card, and reserve enough table space.

2) Reserve an interface in the firmware that may call the patch.

Example of calling method:

The Judge_Patch function is located in the firmware. It can parse the patch index table, determine whether there is a patch to execute according to the patch ID, and obtain the first address of the patch. The Judge_Patch function will automatically assign the first address of the patch to a global function pointer. So if there is a patch program, you can directly call the function pointer to implement the call to the patch function. If the Judge_Patch function returns 0, indicating that the relevant patch function is not found, the original processing flow is continued.

3) Execute the patch, COS directly goes to the first address of the obtained patch program to start execution. The internal implementation protects the current program address and registers before the patch is executed.

4 example analysis

If the two patch functions of the smart card operating system are: AP I_FindDfEf_patch, the EF file under the current DF file is found; Update_Record_Patch, that is, the update log file, the detailed steps for downloading the patch function are given below:

1) Write the patch function, and download this code to the free space of the code area of ​​the chip (you can get the address from the file generated after COS compilation), and record the first address of the download.
2) Set the location and related attributes in the patch index table for the current patch, as shown in Table 4.

3) After the card is reset, after the power is turned back on, the COS will judge whether to execute the patch function and which patch to execute through the Judge _Patch function. According to the attribute byte, the patch to be executed is the first patch, that is, the current DF file is found. The EF file, Judge_Patch will send the starting address of the patch, in the next patch, the implementation is as follows:

4) It is the patch function verification, card reset, and execution of an EF file command under DF. Because the instruction is internally implemented by the previously downloaded patch. Therefore, the correctness of downloading the patch in this article can be observed from the execution result of the instruction. In this example, the card returns the correct status code and related information of the selected EF.

5 Conclusion

This article first introduces the basic concept of the smart card operating system, and then combines the contact 51 series smart card chip to illustrate the application background of the patch download in the smart card operating system. A patch management mechanism is proposed for the shortcomings of the current patch download method. The specific examples are given and analyzed, and the implementation methods and steps are given. The feasibility of this patch download method is verified. The patch management mechanism proposed in this paper is suitable for patch downloading of any 51 series smart cards, and is no longer subject to The patch size is limited, and the patch download can be performed according to different patch classification indexes. Therefore, the solution has good application value.

(Text/Tianjin University of Technology, School of Computer and Communication Engineering, Zhang Lijing, Zhang Qiuyan)

6Pcs Steak Knife Set

French Steak Knives,Wooden Handle Steak Knives,Wusthof Steak Knives,12Pcs Steak Knife


Posted on