Hi,
 
I have coded a Java card applet.
It doesn't contain any OP code. It is coded using JCDK only !
I'm trying to apply OP commands like Initialize Update, 
External Authenticate to it, from Host Application .
Can somebody tell me, is it possible to apply OP commands to such an
applet ?
 
I've become successful in selecting Card Manager, 
for Initialize Update it returns 90 00, however for External
Authenticate it returns 63 00.
I'm not using OpenSecureChannel() or verifyExternalAuthenticate()
methods of ProviderSecurityDomain,
I've formed Command APDUs from byte arrays. 
 
Can somebody help me out ?

Following is host application code,

import java.io.InputStream;
import java.io.FileInputStream;
import java.util.Properties;

import opencard.core.terminal.CommandAPDU;
import opencard.core.terminal.ResponseAPDU;
import opencard.core.terminal.CardID;
import opencard.core.terminal.CardTerminalRegistry;

import opencard.core.service.SmartCard;
import opencard.core.service.CardRequest;

import com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminal;
import com.ibm.opencard.terminal.pcsc.PcscError;

import opencard.opt.util.PassThruCardService;
import opencard.opt.applet.AppletID;

import opencard.core.terminal.CardTerminalException;

public class OCFConnection  {

        private Pcsc10CardTerminal cardTerminal;
//represents card reader

        private static final int IFD_TIMEOUT = 10;

        public PassThruCardService commService;
//represents communication channel
        private int n;
//temporary counter.
        private int intATR;
//represents int form of ATR.
        private byte[]  cardATR;
//represents ATR returned by card.
        private CommandAPDU commandAPDU;
//represents instruction & data to be sent to reader.
        private byte bytesw1,bytesw2;
 
        public OCFConnection () {
                /*addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e)
{
                                        dispose();
                                        System.exit(0);
                                }
                });*/

                // get system properties
                Properties systemProperties = System.getProperties ();
            // set system properties for OCF, PC/SC and
PassThruCardServce
                systemProperties.put ("OpenCard.terminals",
        
"com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory");
            systemProperties.put
("OpenCard.services","opencard.opt.util.PassThruCardServiceFactory");
        }

        public void initOCF ()
        {
                // APDU for selecting Card Manager
                byte[]  apduContents =
{(byte)0,(byte)164,(byte)4,(byte)0,(byte)7,
        
(byte)160,(byte)0,(byte)0,(byte)0,(byte)24,
        
(byte)67,(byte)77,(byte)0
                };
                // APDU for Initialize Update
                byte[]  initUpdateAPDU =
{(byte)128,(byte)80,(byte)13,(byte)0,(byte)8,
        
(byte)0,(byte)0,(byte)0,(byte)0,(byte)0,
        
(byte)0,(byte)0,(byte)0,(byte)28
                };
                // APDU for selecting External Authenticate
                byte[]  extAuthAPDU =
{(byte)132,(byte)130,(byte)3,(byte)0,(byte)16,
        
(byte)68,(byte)68,(byte)68,(byte)68,(byte)68,
        
(byte)68,(byte)68,(byte)68,(byte)17,
        
(byte)34,(byte)51,(byte)68,(byte)85,
        
(byte)102,(byte)119,(byte)136,(byte)0
                };
                commandAPDU = new CommandAPDU (apduContents);

                try
                {
                        SmartCard.start ();

                        CardTerminalRegistry cardTerminalRegistry =
CardTerminalRegistry.getRegistry ();

                        cardTerminal =
(Pcsc10CardTerminal)cardTerminalRegistry.cardTerminalForName ("Gemplus
GemPC430 0");

                        CardRequest cardRequest = new CardRequest
(CardRequest.ANYCARD, null, PassThruCardService.class);
                cardRequest.setTimeout (IFD_TIMEOUT);  // set timeout
for IFD
                System.out.println ("wait for smart card - insert smart
card in terminal");
                System.out.println ();

                // wait  for a smart card inserted into the terminal
                SmartCard smartCard = SmartCard.waitForCard
(cardRequest);

                if (smartCard != null)
                {  // no error occur and a smart card is in the terminal
                        commService = (PassThruCardService)
smartCard.getCardService (PassThruCardService.class, true);

                        String stringATR = new String ();

                        System.out.print ("ATR:           ");
                        CardID cardID = smartCard.getCardID ();
                        cardATR = cardID.getATR ();

                        for (n=0; n< cardATR.length; n++) {
                                intATR = (int) (0x000000FF &
cardATR[n]);
// byte to int conversion
                                stringATR = Integer.toHexString
(intATR).toUpperCase ();                                //String
conversion

                                if (stringATR.length () == 1) stringATR
= "0" + stringATR;
                                        System.out.print(stringATR + "
");

                        } // end of for

                        System.out.println ("");
                        }// end of if.
                        System.out.println ();

                    System.out.println ("Command APDU  =
"+commandAPDU.toString ());
                    System.out.println ();

                        //obtain response from card
                        ResponseAPDU responseAPDU =
commService.sendCommandAPDU (commandAPDU);

                        bytesw1 = responseAPDU.sw1 ();
                        bytesw2 = responseAPDU.sw2 ();
                        System.out.println ("sw1 = "+(byte)bytesw1);
                        System.out.println ("sw2 = "+(byte)bytesw2);
                        System.out.println ();

                        System.out.println("Response APDU  =
"+responseAPDU.toString());
                        System.out.println ();

                        commandAPDU = new CommandAPDU (initUpdateAPDU);
                        responseAPDU = commService.sendCommandAPDU
(commandAPDU);

                        bytesw1 = responseAPDU.sw1 ();
                        bytesw2 = responseAPDU.sw2 ();
                        System.out.println ("sw1 = "+(byte)bytesw1);
                        System.out.println ("sw2 = "+(byte)bytesw2);
                        System.out.println ();

                        System.out.println("Response APDU  =
"+responseAPDU.toString());
                        System.out.println ();

                        commandAPDU = new CommandAPDU (extAuthAPDU);
                        responseAPDU = commService.sendCommandAPDU
(commandAPDU);

                        bytesw1 = responseAPDU.sw1 ();
                        bytesw2 = responseAPDU.sw2 ();
                        System.out.println ("sw1 = "+(byte)bytesw1);
                        System.out.println ("sw2 = "+(byte)bytesw2);
                        System.out.println ();

                        System.out.println("Response APDU  =
"+responseAPDU.toString());
                        System.out.println ();

                        smartCard.close ();
                        SmartCard.shutdown ();
                }

                catch (CardTerminalException e)
                {
                        System.out.println (e.getMessage ());
                }

                catch (Exception e)
                {
                        System.out.println (e.getMessage ());
                }

                finally
                {
                        String errorMsg = PcscError.getMessage
((int)57);

                }
        }
        
        public static void main (String args[]) {
                OCFConnection siObject = new OCFConnection ();
                siObject.initOCF ();
        }

}

Thanks in advance.

Awadhoot Aphale
 
 


---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/

! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
!                           [EMAIL PROTECTED]
! containing the word
!                           unsubscribe
! in the body.

Reply via email to