0

I am new to Java Card development. I have created a Java Card applet for online payment.. But I couldn't find way to how to do offline transactions. I need to know how to store offline data (such as the balance) in Java Card. Is there any way to use file structure to store data?

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
Sajith Vijesekara
  • 1,324
  • 2
  • 17
  • 52

3 Answers3

1

A JavaCard is a little different from Java on your PC. Everything you do in your applet is persistent. Only if you explicitly allocate a variable in RAM the content is lost upon card reset (or power loss).

Therefore every field variable e.g. in your applet class can be used for storing your offline data.

Robert
  • 39,162
  • 17
  • 99
  • 152
1

For offline transactions it is required that you store the data in persistent memory. Moreover, updates to this persistent memory should be atomic. This means that if a transaction is in progress and there is a card tear then the transaction should be nullified. For this, Java Card has the (aptly named) beginTransaction and abortTransaction methods in JCSystem.

There are some discussions if the security level of normal EEPROM or Flash is enough for sensitive data such as transactions and balances. It could not hurt to update a (secure) checksum together with the transaction so that an advanced attacker cannot alter the data stored on the smart card. Storing this checksum has to be part of the atomic transaction.

Java Card does not supply any file based structure. There was a proposed API a long time ago, but currently the support for the ISO 7816-4 file system ends with the applet selection by it's AID. The rest of the protocol is your responsibility. Note that you should not update the contents of an Elementary File by anything other than UPDATE BINARY (and friends). In general the content of the files should be either static or generated by the off card entity. Using for instance records and GET DATA would be more appropriate - but you will have to program those yourself as well.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • thanks owlstead.i read about ISO 7816-4 file system and how to apply in java card. But i want to know is there any mechanism used for store offline data in smart card. what mechanism used in EMV cards ?? – Sajith Vijesekara Dec 24 '13 at 04:29
  • Generally payment cards do not contain balance information. Everything is stored in the servers of the bank. The cards are just used for identification and (transaction) authentication. With regards to mechanisms in EMV cards: read the standard. – Maarten Bodewes Dec 24 '13 at 12:52
  • Thanks. But offline transaction payment we can't access the servers.So in this kind of scenario how we pay the amount through card.Normally visa pay-wave keep some balance for the payment (like $50). So i want to know how to store balance for the offline transaction. – Sajith Vijesekara Dec 26 '13 at 05:10
1
  1. Create a persistent array for offline balance

    ex. balance = new byte[length_of_balance];

  2. Create a transient array to calculate offline balance

    ex. temp_balance = JCSystem.makeTransientByteArray(length_of_balance, CLEAR_ON_DESELECT);

  3. when the new amount is received,

    a. load the balance to temp_balance

    b. accumulate new amount to temp_balance

    c. copy temp_balance to balance using Util.arrayCopy

Hope this helps~

  • Thanks.I thought also the same way. But i want to know is that the other offline transaction payment system followed(visa pay-wave). What is the standard way to store data in java card?? – Sajith Vijesekara Dec 26 '13 at 05:54