This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Mar 1, 2012 5:29 PM by safarmer RSS

what about ISO/IEC-7816 file structure, Is this concept is not in jcard.

914939 Newbie
Currently Being Moderated
Hello all,

I read out ISO/IEC 7816-4 and it tell about MF , DF, EF files which are used in smart card, i am using java card.
I am reading java card but i did not read about these file structure,
according to iso/iec-7816-4 , A4 is a INS for SELECT FILE command. In scosta if i want to save name in smart card then i do

*1*- create MF
*2*-create Df ( INS- E0)

*3*- create ef with record oriented structure(INS-E0)

*4* run write record command (*INS-D2*)
and now i can read this name whenever i want by using read record command.
-------------------------------------------------------------------------------------

I only want to know that if i want to record several names in java card (in java card eeprom ) then which line i need to write inside the PROCESS () method of applet.
-----------how i permanent save in smart card memory?
-----------how i read the data from perticular location or the location where name exist?

Thanks in advance..............

Edited by: rohit pathak on Feb 9, 2012 10:41 PM

Edited by: rohit pathak on Feb 9, 2012 10:42 PM
  • 1. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,

    Actually, if you are using java smart card then you will not have these file systems present in the card. These files are only present in a SIM card.

    Regards
  • 2. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    911936 wrote:
    Hello all,
    I only want to know that if i want to record several names in java card (in java card eeprom ) then which line i need to write inside the PROCESS () method of applet.
    You can create internal buffer arrays for these to store as many name as you like (memory is a constraint)
    -----------how i permanent save in smart card memory?
    all the objects and primitive types which are not declared as transient are automatically store on EEPROM of the java card by default
    -----------how i read the data from particular location or the location where name exist?
    You can easily access these arrays whenever you want.

    Regards
  • 3. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
    Thanks umer,

    It's cleared me something, now i need to read how the declare the things , that would save data in EEPROM.
    Not Very Necessart but if you show me some code of line then It would be more helpful,
    ---------------------------------------------------------------Anyways Thanks a lot

    Edited by: rohit pathak on Feb 5, 2012 12:04 PM
  • 4. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,
    rohit pathak wrote:
    Thanks umer,

    It's cleared me something, now i need to read how the declare the things , that would save data in EEPROM.
    Not Very Necessart but if you show me some code of line then It would be more helpful,
    public class NamesClass{
    private byte[] names;
    
    public NamesClass()
    {
      names = new byte[100];
    }
    //rest of the java card functions process() etc ....
    }
    Note It is recommended that you should always assign memory in the constructor

    Regards
    Umer
  • 5. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Jean-Damien LEBUI Explorer
    Currently Being Moderated
    File System notion does exist in JavaCard. I don't care about SCOSTA or whatever, if the card follows the ISO-7816, that means it supports all type of files mentioned in the specifications.

    for Java-enable SIM card, the default selected SIM applet will implement the FileSystem class as you read in GSM specification documents.

    In Java-enable smartcard, you can implement yourself the FileSystem class with MF, DF and EF as in ISO-7816 specifications. However, in this case, you must implement other methods to handle these files. I have done myself an application on smartcard (IDCard) in which I have to implement a FileSystem class with all other related methods (READ RECORD, READ BINARY, etc.)

    Best regards,
    JDL
  • 6. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
    Thanks Umer for Simple code.....But let me clear one thing,



    I already write some line of codes in c , c++ , .Net, In everywhere variable takes part in RAM (Volatile Memory ), but java card have persistent and transient concept.

    question 1 - if we do not declare any object transient , so it would work as a persistent ( means it will save after power off)? ex- u did not mention names byte array as persistent but u r saying it will be live in card.
    is by default objects is persistent?
    question 2 - I think, in a case where I need to save student name once and read multiple time, we would have one read and one write method inside the process method of java card. right? so according to your code.
    so can i think whenever i access , names byte array,
    1- after writing name array or
    2-next time when i insert the card in CAD while we have already written name array by using write case of process()
    we will get the data which we saved with using write method????????????????????????

    question 3 . you mean to say they are no requirement of memory address or offset to get persistent data, we only need to know about object name {example- names in this case} and by using it (names byte array in read code area) we get the data which it hold it, any time ????????????


    These are the basics and if once i understand it so i would be pass the way very easily, so Umer Sir Please let me clear the concepts.....
    Very very thanks in advance....

    Edited by: rohit pathak on Feb 9, 2012 10:40 PM
  • 7. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,
    rohit pathak wrote:
    question 1 - if we do not declare any object transient , so it would work as a persistent ( means it will save after power off)? ex- u did not mention names byte array as persistent but u r saying it will be live in card.
    is by default objects is persistent?
    Yes. Everything which has a class scope will be persistent and anything which has a function scope will not be i mean temporary variables will not be persistent.
    question 2 - I think, in a case where I need to save student name once and read multiple time, we would have one read and one write method inside the process method of java card. right? so according to your code.
    Actually it depends on your code and requirements. If the name initialization will be static( should be initialized before card issuing to user) then you can initialize them within the constructor and write the getter function to get the name and also you can write a setter function to set values/name.
    so can i think whenever i access , names byte array,
    1- after writing name array or
    2-next time when i insert the card in CAD while we have already written name array by using write case of process()
    we will get the data which we saved with using write method????????????????????????
    Yes you are right. Data will be available on next power-on also.
    question 3 . you mean to say they are no requirement of memory address or offset to get persistent data, we only need to know about object name {example- names in this case} and by using it (names byte array in read code area) we get the data which it hold it, any time ????????????
    Yes you can do that also: Lilke
    public class Info{
    private static byte[10] fName;
    private static byte[10] lastName;
    private static byte[10] surName;
    
    public Info{
    fName = new byte[10];
    lastName = new byte[10];
    surName = new byte[10];
    
    }
    
    public void setFirstName(){
      fName[0] = (byte)0x55; //U
      fName[1] = (byte)0x4D; //M
      fName[2] = (byte)0x45; //E
      fName[3] = (byte)0x52; //R
    }
    
    public void getFirstName(APDU apdu)
    {
      //copy all the bytes from fName buffer to outgoing buffer and send to host app by using 
      apdu.setOutgoingAndSend((short),(short));
    }
    
    }
    Hope it helps.
    These are the basics and if once i understand it so i would be pass the way very easily, so Umer Sir Please let me clear the concepts.....
    Please don't call me Sir. You can call my name ;)

    Regards
    Umer

    Edited by: Umer on Feb 6, 2012 10:36 PM
  • 8. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
    Ok as u wish Umer....

    It makes me clear everything ,{ now its my turn to implemnet it )   thanks for spending your precious time for this article...

    For development i am using NetBeans 7.0.1 ( a latest version) , it support both classic and connected java card. But when i am using it - It hang up again and again when its calling CJCRE (C simulator ). I think I need to go some lower version ,because it is latest and it would not be bug free.

    Can u suggest me any spefic IDE or any specific version which is best for simulation process { because i dont have any real java card } as well as for real java card envoironment { we are trying to arrange it }

    regards:-

    Edited by: rohit pathak on Feb 9, 2012 10:53 PM
  • 9. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,
    rohit pathak wrote:
    It makes me clear everything ,{ now its my turn to implemnet it )   thanks for spending your precious time for this article...
    The best way to thank is just click the help button if it helps and mark it correct if it does. ;)
    Can u suggest me any spefic IDE or any specific version which is best for simulation process { because i dont have any real java card } as well as for >real java card envoironment { we are trying to arrange it }
    According to me for java card applet you should use eclipse and for Host app you should go for Netbeans.
    For real java cards you should get java card from some companies like NXP, Gemalto etc. If you are contacting with some chineas company then please try to get documents of the card as they people are very reluctant to provide the documents.

    Regards
  • 10. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
    hello umer,

    today i made a applet application, and i fired two apdu's over it,
    1- select the applet (00 a4 04 00 Lc applet id Le)
    2- read the data (80 02 00 00 00 04) - i set class =80 and read iNs=02

    but output was strange - for first apdu i get the the data which is != 90 00
    but for second apde - i get the data which i required............ now i am confused if applet is not well selected then how 2nd command give right result.......
    what do u think? how it happen? it is a fault of IDE or something else is happening... if you say then i would show u complete code tomorrow when i was in my office.
  • 11. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,

    Yes it will be better if you share your code and the output trace.

    Regards
  • 12. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
    Umer wrote:
    Hi,

    Yes it will be better if you share your code and the output trace.

    Regards
    java file :-
    amit wrote:
    import javacard.framework.*;

    /**
    >
    >*/
    public class Getname extends Applet {

    final static byte CLASS = (byte) 0x80; // Class of the APDU commands
    final static byte INS_READ = (byte) 0x02; // instruction for the READ APDU command
    final static byte[] text = {(byte) 'A', (byte) 'M', (byte) 'I', (byte) 'T'
                        };
    public static void install(byte[] bArray, short bOffset, byte bLength) {
    new Getname();
    }

    /**
    * Only this class's install method should create the applet object.
    */
    protected Getname() {
    register();
    }

    /**
    * Processes an incoming APDU.
    *
    * @see APDU
    * @param apdu
    * the incoming APDU
    */
    public void process(APDU apdu)
    {
    byte[] cmd_apdu = apdu.getBuffer();
         if (cmd_apdu[ISO7816.OFFSET_CLA] == CLASS)
         { 
    switch(cmd_apdu[ISO7816.OFFSET_INS])
    {     
              case INS_READ:
         if ((cmd_apdu[ISO7816.OFFSET_P1] != 0) || (cmd_apdu[ISO7816.OFFSET_P2] != 0))
         {
    ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
         }
         short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
         short len_text = (short)text.length;
         if (le != len_text)
         {
    ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 + len_text));
         }
         apdu.setOutgoing();
         apdu.setOutgoingLength((short)len_text);
         apdu.sendBytesLong(text, (short)0, (short)len_text);
         break;
         default :
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }
         }
         else
         {       
              ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
         }
    }
    }
    and apdu code is:-

    Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 06, 7d, 0b, b8, d0, e3, c4, Le: 00, SW1: 6e, SW2: 00
    CLA: 80, INS: 02, P1: 00, P2: 00, Lc: 00, Le: 04, 41, 4d, 49, 54, SW1: 90, SW2: 00
    CLA: 80, INS: 02, P1: 00, P2: 00, Lc: 00, Le: 04, 41, 4d, 49, 54, SW1: 90, SW2: 00
    Umer i am using Net beans 7.1, Could you tell me If i moved to Eclipse for java card development then what thing i need to require to create a system for java card development.

    Edited by: rohit pathak on Feb 9, 2012 10:38 PM
  • 13. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    Umer Journeyer
    Currently Being Moderated
    Hi,

    You should also put closing  tag too :)

    Plese try the following code. Hope problem will be removed.
    package getname;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    
    public class Getname extends Applet {
    
         final static byte CLASS = (byte) 0x80; // Class of the APDU commands
         final static byte INS_READ = (byte) 0x02; // instruction for the READ APDU command
         final static byte[] text = {(byte) 'A', (byte) 'M', (byte) 'I', (byte) 'T'
         };
         
         public static void install(byte[] bArray, short bOffset, byte bLength) {
         new Getname();
         }
    
         /**
         * Only this class's install method should create the applet object.
         */
         protected Getname() {
         register();
         }
    
         /**
         * Processes an incoming APDU.
         *
         * @see APDU
         * @param apdu
         * the incoming APDU
         */
         public void process(APDU apdu)
         {
              if (selectingApplet())
              {
                   return;
              }
              byte[] cmd_apdu = apdu.getBuffer();
              if (cmd_apdu[ISO7816.OFFSET_CLA] == CLASS)
              {
              switch(cmd_apdu[ISO7816.OFFSET_INS])
              {
                   case INS_READ:
                        if ((cmd_apdu[ISO7816.OFFSET_P1] != 0) || (cmd_apdu[ISO7816.OFFSET_P2] != 0))
                        {
                             ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
                        }
                        short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
                        short len_text = (short)text.length;
                        if (le != len_text)
                        {
                             ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 + len_text));
                        }
                        apdu.setOutgoing();
                        apdu.setOutgoingLength((short)len_text);
                        apdu.sendBytesLong(text, (short)0, (short)len_text);
                        break;
                        default :
                        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                   }
              }
              else
              {
                   ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
              }
         }
    }
    Trace:
    cm>  /select |getname.app
     => 00 A4 04 00 0B 67 65 74 6E 61 6D 65 2E 61 70 70    .....getname.app
        00                                                 .
     (460394 nsec)
     <= 90 00                                              ..
    Status: No Error
    cm>  /send 8002000004
     => 80 02 00 00 04                                     .....
     (1455 usec)
     <= 41 4D 49 54 90 00                                  AMIT..
    Status: No Error
    Regards
    Umer
  • 14. Re: what about ISO/IEC-7816 file structure, Is this concept is not in jcard.
    914939 Newbie
    Currently Being Moderated
     
    
    if (selectingApplet())
              {
                   return;
              }
    // this method  is use to make a difference between select applet
     //apdu { have to call it before any apdu pass to card, this apdu is isolate to process method }
     //and other apdu { here class and INS is for your choice,
    // it depends how u implement it in process().
    amazing Umer, atleast for me really it's gr8 to have you here..

    you know i am a beginner so it is sure that there would be a no. of question in my mind now!!!!!and I want to share with you for your answer as well try to get it by my own, u already help me a lot , and i would
    be always thankful for this. I am posting some questions here, if you feel it is genuine question , pls reply and if
    you think i am bothering you to ask such a foolish question , u dont!!!!

    QUESTION -1
    As I know about architecture of any application is -
                    //normal java software                          java card                                  java card
                      //  1                                               2                                      3
    1-            application program                        host application                           host application
    2-                     JVM                                   Applets                                       Applets 
    3-              operating system                JCRE(which contain all classes, JVM ....)                 JCRE(act as a O.S too)
    4                    hardware                              Operating system                                 H/W
    5                                                                        hardware
    What do u think- case 2 is right? or 3 is!!!!!!!!!!!
    I think - case 3 is right!!!!
    As i study from several sources , JCRE is complete package - it behaves as a operation system and use the functionality of component it contain. I also think if i will purchase a java card from any vendor , it would have JCRE inside it (means everthing inside it,), i only need to develop the applet according to my requirement and install it by on card installer program


    QUESTION 2- what is the advantage of java card.?
    // I think.
    as i read out , i got the line that it is platform independent and support multiple application. applicaton point of
     view , I am agree but how it is platfrom independent. if we use java card for smart card development, then 
     i will purchase Java card from differnt vendor , all will provide me card with supported jcre inside it, so why
     this is advantage here?
    // in case of window based application , it really make sense  because if i will make any window application with java
    // i can run it in windows , linux , unix and most of os flavours, here i can see the beauty of java language.
     Clear me this and add some other java card advantages, which make java card good
    question 3-
    Now I am capaple to make simple applets, so I want to check the entire java card process atleast once before 
    going in deep of something, I am thinking to implement prepaid card concept , i made it applet for it ,it will 
    contain a page with 2 text box ( 1- for recharge 2- for money deduction ) and two button , with button click i 
    want to select the applet and want to pass the apdu.
     ( a) how i can make host window application ? (i think awt will work for me? , *
    i never make any java window application yet) * 
     ( b) still i dont have any java card , i want to make it by using simulator, is it possible?
      (c) in this scenario what framework i need to study Ex. Import javacard.framework.* for making
     applet or from where i need to start.
    regards:
    rohit pathak

    Edited by: rohit pathak on Feb 9, 2012 10:39 PM
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points