8 Replies Latest reply: Mar 1, 2012 6:26 PM by safarmer RSS

    is it possible to simulate whole java card application on simulator?

    rohit007
      Hello all,

      currently i dont have any real java card yet,not either reader . I already made a simple applet and check its working by CJCRE (net beans simulator), it is working fine,
      now i want to move to host application which will communicate with java card via card reader. Is this possible to simulate complete application ( host application + java card applets)?
      I want to check it out that:- which line of java program would be helpful to know that:-
      1-"how real host application will talk to reader"
      2- how it connect and disconnect the reader
      3- how it send apdu to java card by reader
      and much more.
      I am using netbeans 7.1 and it is using CJCRE as a simulator....
        • 1. Re: is it possible to simulate whole java card application on simulator?
          Umer
          rohit pathak wrote:
          Hello all,

          currently i dont have any real java card yet,not either reader . I already made a simple applet and check its working by CJCRE (net beans simulator), it is working fine,
          now i want to move to host application which will communicate with java card via card reader. Is this possible to simulate complete application ( host application + java card applets)?
          I want to check it out that:- which line of java program would be helpful to know that:-
          1-"how real host application will talk to reader"
          2- how it connect and disconnect the reader
          3- how it send apdu to java card by reader
          and much more.
          I am using netbeans 7.1 and it is using CJCRE as a simulator....
          Did you read smartCardIO specs/documentation? It is all written there.
          • 2. Re: is it possible to simulate whole java card application on simulator?
            rohit007
            you mean to say this

            http://askra.de/software/jcdocs/app-notes-2.2.2/apduio.html

            I am quite confused now, i read this but still can not imagine the concept ,

            an applet code is :-
            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 INS_WRITE = (byte) 0x03;  // instruction for the READ APDU command
                 final static byte INS_DY_CO = (byte) 0x04;  // instruction for the READ APDU command
                 final static byte[] text    = {(byte) 'A', (byte) 'M', (byte) 'I', (byte) 'T'};
                 public static byte[] holder;
              
                 public static void install(byte[] bArray, short bOffset, byte bLength) 
                 {
                    new GetName();
                }
            
                protected GetName() 
                 {
                    holder = new byte[5];// allocation of memory in runtime
                    register();
                }
            
                
                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;
                                     
                                
                                     
                            // here we save data from apdu and will keep inside the data byte                    
                                case INS_WRITE: 
                                     
                            short lc = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);  
                            Util.arrayCopy(cmd_apdu, (short) ((ISO7816.OFFSET_CDATA) & 0xff), holder, (short) 0, lc);
                                short len_holder_inside_write= (short) holder.length;
                               apdu.setOutgoing();
                            apdu.setOutgoingLength((short)len_holder_inside_write);
                            apdu.sendBytesLong(holder, (short) 0, (short) len_holder_inside_write);
                            break;
                               
                            case INS_DY_CO:
                            
                                short len_holder= (short) holder.length;
                            apdu.setOutgoing();
                            apdu.setOutgoingLength((short)len_holder);
                            apdu.sendBytesLong(holder, (short) 0, (short) len_holder);
                            break;
                         
                                default :  
                                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                        }  
                      }  
                     else 
                     {        
                            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
                     }  
                }
            }
            now i think i need to make a another java file which would contain a main class, Is this both file would be inside a single java card project. and how these both would be connect to each other.

            for manually run a applet- there were two steps 1-

            C:\java_card_kit-2_2\samples\src\demo>jcwde jcwde-getname.app
            Java Card 2.2 Workstation Development Environment (version 0.18).
            Copyright 2002 Sun Microsystems, Inc. All rights reserved.
            jcwde is listening for T=0 Apdu's on TCP/IP port 9,025.

            and in second terminal we wrote-

            C:\java_card_kit-2_2\samples\src\demo>apdutool -nobanner -noatr getname.scr > ge
            tname.scr.jcwde.out

            Here it is clear that, if i will use javacardio then no need to pass the apdu from a file .....but i am confuse about how it possible, ie. is both file lie in same project , because i m using simulator so i need to run these both file simoltaneously........give me some roughly steps to implement this.
            • 3. Re: is it possible to simulate whole java card application on simulator?
              Umer
              rohit pathak wrote:
              you mean to say this

              http://askra.de/software/jcdocs/app-notes-2.2.2/apduio.html
              No, I mentioned it for you in the pervious threads about 3-5 times and mentioning it again it is: http://docs.oracle.com/javase/6/docs/jre/api/security/smartcardio/spec/javax/smartcardio/package-summary.html
              an applet code is :-


              now i think i need to make a another java file which would contain a main class, Is this both file would be inside a single java card project. and how these both would be connect to each other.

              for manually run a applet- there were two steps 1-

              C:\java_card_kit-2_2\samples\src\demo>jcwde jcwde-getname.app
              Java Card 2.2 Workstation Development Environment (version 0.18).
              Copyright 2002 Sun Microsystems, Inc. All rights reserved.
              jcwde is listening for T=0 Apdu's on TCP/IP port 9,025.

              and in second terminal we wrote-

              C:\java_card_kit-2_2\samples\src\demo>apdutool -nobanner -noatr getname.scr > ge
              tname.scr.jcwde.out

              Here it is clear that, if i will use javacardio then no need to pass the apdu from a file .....but i am confuse about how it possible, ie. is both file lie in same project , because i m using simulator so i need to run these both file simoltaneously........give me some roughly steps to implement this.
              I really could not get about which files you are asking and what you are going to implement.... Please try to explain your problem ..
              • 4. Re: is it possible to simulate whole java card application on simulator?
                rohit007
                my link was...

                http://askra.de/software/jcdocs/app-notes-2.2.2/apduio.html

                ok can i say that, above link will be used when we work over simulation , ie no real reader and card exist,????? I can also say this because this contain some methods like:-
                powerDown()
                          Powerdown a card or simulator and then disconnect, Because real envoirnment does not need to power down and up, it happen manually there
                and your link will be work when we work over real java card environment................right? (but i dont have any card)
                so if i am saying write then your link would not be real use now, because i have no other option than use simulator.
                what do u think?
                • 5. Re: is it possible to simulate whole java card application on simulator?
                  Umer
                  rohit pathak wrote:
                  my link was...

                  http://askra.de/software/jcdocs/app-notes-2.2.2/apduio.html

                  ok can i say that, above link will be used when we work over simulation , ie no real reader and card exist,????? I can also say this because this contain some methods like:-
                  powerDown()
                  Powerdown a card or simulator and then disconnect, Because real envoirnment does not need to power down and up, it happen manually there
                  and your link will be work when we work over real java card environment................right? (but i dont have any card)
                  so if i am saying write then your link would not be real use now, because i have no other option than use simulator.
                  what do u think?
                  Well I never used this link so can't say anything about it.
                  • 6. Re: is it possible to simulate whole java card application on simulator?
                    rohit007
                    ok umer .

                    I think that - to using this Package javax.smartcardio, I should have real java card, right?
                    • 7. Re: is it possible to simulate whole java card application on simulator?
                      rohit007
                      Umer wrote:
                      rohit pathak wrote:
                      my link was...

                      http://askra.de/software/jcdocs/app-notes-2.2.2/apduio.html
                      Well I never used this link so can't say anything about it.
                      Inside the folder java card 2.2 there are full specification of this.. if you want to see the program, where this concept used
                      go
                      Re: RSAEncryption
                      I understand the program but how we interact two program simoltaneously????????????????

                      Edited by: rohit pathak on Feb 14, 2012 5:39 PM

                      Edited by: rohit pathak on Feb 14, 2012 5:40 PM
                      • 8. Re: is it possible to simulate whole java card application on simulator?
                        safarmer
                        HI,

                        smartcardio is for a real card over PC/SC. You need another API for simulators. It may be possible to create a provider for smartcardio that works with simulators but I have not gotten around to this (yet).

                        As for the two applications (host and card) it is a client server model. The host sends commands to a smartcard (or a simulator) and they have a conversation exchanging APDU's.

                        Cheers,
                        Shane