javacard.framework.APDU sendBytes.Length method

In the javacard.framework.APDU class, I found that in several methods such as sendBytes.length (short short bOff, leng) or ' public void sendBytesLong (byte [] outData, bOff short, short len), they say:

«Requiring the uneditable buffer allows the implementation reduce overhead costs by transmitting the last part of the answer with the bytes of State Protocol.»

I do not quite understand. Why is it related to the reduction of overhead of Protocol? And what is "bytes of State"?

Your response, so useful or not, is very much appreciated

Jason

Hello

My interpretation of this is that the bytes of State (otherwise known as status word) can be sent with the last block of data. This way the card OS passes only to the CAD/IFD once rather than twice. Transmission (as for transmission on the network) has a slight overhead. When it comes to a system with a clock as a java card speed, a large number of small overhead can easily accumulate to become big overhead :)

See you soon,.
Shane

Tags: Java

Similar Questions

  • JavaCard.Framework.Dispatcher

    Hi guys

    I host the features of javacard.framework.Dispatcher concern

    As far as I know, according to the Javacard API spec 2.2.1 the functionality for this class are described as below:

    + "A dispatcher is used to build an application by combining several services. +

    + The dispatcher maintains a register of Service objects. A Service is classified by type of processing it performs: +.

    + A pre-processing service preprocesses the data entry for the command processing. It is associated with the phase PROCESS_INPUT_DATA. +
    + Processing order service treats the input data and generates output data. It is associated with the phase PROCESS_COMMAND. +
    + Post processing service post-draft generated output data. It is associated with the phase PROCESS_OUTPUT_DATA. +

    + The dispatcher simply distributes object incoming APDU containing the order processing for the registered services. "+

    It seems ambiguous to me. :|

    On the other hand, I don't know when this class is called. This class specification 2.1.1 Javacard API is written in Java and contains a main() method. Thus, it confuses me a lil' bit

    Suppose I have an applet to Hello. This applet is an example, included in the Javacard 2.2.1 API specification
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.Util;
    
    
    public class HelloWorld extends Applet {
         
         private byte[] echoBytes;
        private static final short LENGTH_ECHO_BYTES = 256;
        
        protected HelloWorld(){
             echoBytes = new byte[LENGTH_ECHO_BYTES];
             register();
        }
        
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              // GP-compliant JavaCard applet registration
              new HelloWorld();
         }
    
         public void process(APDU apdu) {
              
    
              byte[] buffer = apdu.getBuffer();
              short bytesRead = apdu.setIncomingAndReceive();
              short echoOffset = (short)0;
              
              while ( bytesRead > 0 ) {
                Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
                echoOffset += bytesRead;
                bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
            }
              
              apdu.setOutgoing();
              apdu.setOutgoingLength( (short) (echoOffset + 5) );
    
            // echo header
            apdu.sendBytes( (short)0, (short) 5);
            // echo data
            apdu.sendBytesLong( echoBytes, (short) 0, echoOffset );
              
         }
    }
    Importation, we all see clearly that there are only 4 classes of the API that can be called for the treatment of this applet. However, the dispatcher is used during this process? If so, please tell me the stream in which Dispatcher is a node.

    Jason Gosling wrote:
    So, you think you agree with my colleague that this class is implicitly executed as it is outside of the JCRE bootstrap?

    That's right.

    safarmer wrote:
    My best guess is that the code comes from a reference implementation

    What do you mean "a reference implementation? As you know, I develop the operating system (JCRE, API,...) for the card and my API code is mainly based on this. That is why, in your opinion, is this reliable code?

    I mean that Sun is resource offered to licensees that may contain an implementation to compare your JCRE/FRENCH_TRAVELLER_64 for. While it provides all the functionality required, it cannot be the best implementation or even run on your card. As long as you evaluate the usefulness of the code, you should be OK.

    See you soon,.
    Shane

  • 6F00 SW Although everything works correctly

    Hi all
    Maybe someone can help me with the following problem:
    I have written an applet that makes mutual stimulus / response. Everything works, even if I get the answer '6F00 '.
    I also used a try-catch block for exceptions regarding safety, without success.
    package challengeresponse;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.JCSystem;
    import javacard.framework.Util;
    import javacard.security.AESKey;
    import javacard.security.KeyBuilder;
    import javacard.security.RandomData;
    import javacardx.crypto.Cipher;
    
    
    public class ChallengeResponse extends Applet {
         
         // Instruction- and class-bytes
         final static byte CLASS = (byte) 0x80;
         final static byte INS_START = (byte) 0x01;
         final static byte INS_CHAL_READER = (byte) 0x02;
         
         // bArray contains (length of AID, AID, length of App. priv., App. priv., installation parameters)
         final static byte INST_PARAM_OFFSET = (byte) 0x0F;
         final static byte[] PADDING = {0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F};
        
        private AESKey aeskey;
        private byte[] id;
        private byte[] challenge_card_stored;
        private RandomData challenge_card_sent;
        private Cipher cipher;
        
         private ChallengeResponse(byte bArray[], short bOffset, byte bLength) {
           
              // Extract AES key form installation parameters and build it
              aeskey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128, false);
              aeskey.setKey(bArray,(short) INST_PARAM_OFFSET);
              
              // Extract ID from installation parameters
              id = new byte[5];
              Util.arrayCopy(bArray, (short) (INST_PARAM_OFFSET + 16), id, (short) 0, (short) 5);
              
              // Use transient arrays for security reasons
              challenge_card_stored = JCSystem.makeTransientByteArray((short)8, JCSystem.CLEAR_ON_DESELECT);
              challenge_card_sent = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
              cipher = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_ECB_NOPAD,false);
              
              // Register in card manager 
              register();
         }
    
         public static void install(byte bArray[], short bOffset, byte bLength)
                   throws ISOException {
              
              // Install method has arguments (AES key, ID) in bArray
              new ChallengeResponse(bArray,bOffset,bLength);
         }
    
         public void process(APDU apdu) throws ISOException {
              
              byte[] apdu_buffer = apdu.getBuffer();
    
              // return if APDU is SELECT command
              if (selectingApplet())
                   return;
              
            switch(apdu_buffer[ISO7816.OFFSET_INS]) {
                   
                 case INS_START:
                        
                        // When start command is received do:
                        
                        // Create challenge and write it into apdu buffer and challenge_card_stored array as reference
                        challenge_card_sent.generateData(apdu_buffer,(short)(ISO7816.OFFSET_CDATA), (short)8); 
                        Util.arrayCopy(apdu_buffer,(short)(ISO7816.OFFSET_CDATA),challenge_card_stored,(short)0,(short)8); 
                                   
                        // Write padding
                     Util.arrayCopy(PADDING, (short)0, apdu_buffer, (short)(ISO7816.OFFSET_CDATA+8), (short)8);
                        
                        // Encrypt message
                     cipher.init(aeskey, Cipher.MODE_ENCRYPT);
                     cipher.doFinal(apdu_buffer, (short)ISO7816.OFFSET_CDATA, (short)16, apdu_buffer, (short)ISO7816.OFFSET_CDATA); 
                                 
                        // Send message AES{challenge_card_stored,PADDING}
                        apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)16);
                      
                 case INS_CHAL_READER:
    (...)
    I get the 6f00 answer when I send the INS_START command, the other commands (which I omitted here) work.

    Thanks in advance!

    You should remember the operators of break in a switch-case statement.

    switch(apdu_buffer[ISO7816.OFFSET_INS]) {
    
                 case INS_START:
    
                        // When start command is received do:
    
                        // Create challenge and write it into apdu buffer and challenge_card_stored array as reference
                        challenge_card_sent.generateData(apdu_buffer,(short)(ISO7816.OFFSET_CDATA), (short)8);
                        Util.arrayCopy(apdu_buffer,(short)(ISO7816.OFFSET_CDATA),challenge_card_stored,(short)0,(short)8); 
    
                        // Write padding
                     Util.arrayCopy(PADDING, (short)0, apdu_buffer, (short)(ISO7816.OFFSET_CDATA+8), (short)8);
    
                        // Encrypt message
                     cipher.init(aeskey, Cipher.MODE_ENCRYPT);
                     cipher.doFinal(apdu_buffer, (short)ISO7816.OFFSET_CDATA, (short)16, apdu_buffer, (short)ISO7816.OFFSET_CDATA); 
    
                        // Send message AES{challenge_card_stored,PADDING}
                        apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)16);
                      break;
                 case INS_CHAL_READER:
    (...)
    
  • Elliptive Curve Cryptography using ALG_EC_FP

    Hello

    I am a beginner in this area.

    I'm trying the key pair to generate ECC to sign and verify by using the program above, but with the ALG_EC_FP and the KeyBuilder size LENGTH_EC_FP_256. But it fails on the call to genKeyPair() with the return value of 1, indicating that its an illegal value. Can you please help me why I get this error?

    I use 2.4.2 JCOP card of R2.

    The classified, A, B, G, S, R, W, K, N values are as shown below.

    Byte [] valA = {(byte) 0xFF, (byte) (byte), 0xFF 0xFF, (byte) 0xFF,}
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 01,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    {(byte) 0xFF, (byte) (byte), 0xFF 0xFF, (byte) 0xFC};
    Byte [] valFP = {(byte) 0xFF, (byte) (byte), 0xFF 0xFF, (byte) 0xFF,}
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 01,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    {(byte) 0xFF, (byte) (byte), 0xFF 0xFF, (byte) 0xFF};
    Byte [] valB = {(byte) 0x5A, (byte) 0xC6, (byte) 0 x 35, (byte) 0xDB,}
    (byte) (byte), 0xAA 0x3A, (byte) 0 x 93, (byte) 0xE7,.
    (byte) (bytes), 0xB3 0xEB, (byte) 0xBD, 0, (byte) x 55,.
    (byte) 0 x 76, (byte) 0 x 98, (byte) 0 x 86, (byte) 0xBC.
    (byte) 0 x 65, (byte) (byte) 0 0x1D x 06, (byte) 0xB0,.
    (byte) 0xCC, (byte) 0 x 53, (byte) (byte), 0xB0 0xF6,
    (byte) 0x3B (byte) 0xCE, (byte) (byte), 0x3C 0x3E,
    {(byte) 0 x 27, (byte) (byte) 0 0xD2 x 60, (byte) 0x4B};
    Choices of Byte [] = {(byte) 0 x 04, (byte) (byte) 0 0x6B x 17, (byte) 0xD1, (byte) 0xF2,}
    (byte) (byte), 0xE1 0x2C, (byte) 0 x 42, (byte) 0 x 47,.
    (byte) (byte), 0xF8 0xBC (bytes) 0xE6, (byte) 0xE5.
    (byte) 0 x 63, (byte) (byte) 0 0xA4 x 40, (byte) 0xF2,.
    (byte) 0 x 77, (byte) 0 x 03, (byte) 0x7D, (byte) 0 x 81,.
    (byte) 0x2D, (byte) (byte) 0 0xEB x 33, (byte) 0xA0,
    (byte) (byte), 0xF4 0xA1, (byte) 0 x 39, (byte) 0 x 45,
    (byte) 0xD8, (byte) 0 x 98, (byte) (byte) 0 0xC2 x 96,
    (byte) (byte), 0x4F 0xE3, (byte) 0 x 42, (byte) 0xE2.
    (byte) 0xFE, (byte) 0x1A, (byte) (byte), 0x7F 0x9B,.
    (byte) 0x8E, (byte) 0xE7, (byte) (byte), 0xEB 0x4A,
    (byte) (byte), 0x7C 0x0F (bytes) 0x9E, (byte) 0 x 16,
    (byte) (byte), 0x2B 0xCE, (byte) 0 x 33, (byte) 0 x 57,.
    (byte) 0x6B (byte) 0 x 31, (byte) (byte), 0x5E 0xCE,.
    (byte) (byte), 0xCB 0xB6, (byte) 0 x 40, (byte) 0 x 68,
    {(byte) 0 x 37, (byte) (byte) 0 0xBF x 51, (byte) 0xF5};
    Byte [] valN = {(byte) 0xFF, (byte) (byte), 0xFF 0xFF, (byte) 0xFF,}
    (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00, (byte) 0 x 00,.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    (byte) 0xFF, (byte) 0xFF, (byte) (byte), 0xFF 0xFF.
    (byte) 0xBC (bytes) 0xE6, (byte) (byte), 0xFA 0xAD,
    (byte) 0xA7 (byte) 0 x 17, (byte) (byte) 0 0x9E x 84,
    (byte) 0xF3 (bytes) 0xB9, (byte) (byte), 0xCA 0xC2,
    {(byte) 0xFC, (byte) 0 x 63, (byte) 0 x 25, 0 (byte) x 51,};

    Byte [] valW = {(byte) 0 x 04, (byte) 0x6B (byte) 0 x 17, (byte) (byte), 0xD1 0xF2,}
    (byte) (byte), 0xE1 0x2C, (byte) 0 x 42, (byte) 0 x 47,.
    (byte) (byte), 0xF8 0xBC (bytes) 0xE6, (byte) 0xE5.
    (byte) 0 x 63, (byte) (byte) 0 0xA4 x 40, (byte) 0xF2,.
    (byte) 0 x 77, (byte) 0 x 03, (byte) 0x7D, (byte) 0 x 81,.
    (byte) 0x2D, (byte) (byte) 0 0xEB x 33, (byte) 0xA0,
    (byte) (byte), 0xF4 0xA1, (byte) 0 x 39, (byte) 0 x 45,
    (byte) 0xD8, (byte) 0 x 98, (byte) (byte) 0 0xC2 x 96,
    (byte) (byte), 0x4F 0xE3, (byte) 0 x 42, (byte) 0xE2.
    (byte) 0xFE, (byte) 0x1A, (byte) (byte), 0x7F 0x9B,.
    (byte) 0x8E, (byte) 0xE7, (byte) (byte), 0xEB 0x4A,
    (byte) (byte), 0x7C 0x0F (bytes) 0x9E, (byte) 0 x 16,
    (byte) (byte), 0x2B 0xCE, (byte) 0 x 33, (byte) 0 x 57,.
    (byte) 0x6B (byte) 0 x 31, (byte) (byte), 0x5E 0xCE,.
    (byte) (byte), 0xCB 0xB6, (byte) 0 x 40, (byte) 0 x 68,
    {(byte) 0 x 37, (byte) (byte) 0 0xBF x 51, (byte) 0xF5};
    Byte [] valS = {(byte) (byte), 0xC4 0x9D, (byte) 0 x 36, (byte) 0 x 08,}
    (byte) 0 x 86, (byte) 0xE7, (byte) 0 x 04, (byte) 0 x 93,.
    (byte) 0x6A, (byte) 0 x 66, (byte) 0 x 78, (byte) 0xE1,.
    (byte) 0 x 13, (bytes), 0x9D (byte) 0 x 26, (byte) 0xB7,.
    {(byte) 0 x 81, (byte) (byte), 0x9F 0x7E, (byte) 0 x 90};
    short k = 0 x 01 (short);

    any help in this regard will be highly appreciated.
    Thanks in advance
    NARA

    Example here of JCOP training

    package com.nxp.id.test.ecc.gfp;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.JCSystem;
    import javacard.framework.Util;
    import javacard.security.CryptoException;
    import javacard.security.ECKey;
    import javacard.security.ECPrivateKey;
    import javacard.security.ECPublicKey;
    import javacard.security.KeyAgreement;
    import javacard.security.KeyBuilder;
    import javacard.security.KeyPair;
    import javacard.security.Signature;
    
    public class EccTest extends Applet {
         private static final short VERSION_INFO_MAJOR_MINOR = (short)0x0001;
    
         private short keyLength;
         private static final byte INS_SET_KEYLENGTH = (byte)0x01;
         private static final byte INS_SET_p = (byte)0x02;
         private static final byte INS_SET_A = (byte)0x03;
         private static final byte INS_SET_B = (byte)0x04;
         private static final byte INS_SET_P = (byte)0x05;
         private static final byte INS_SET_M = (byte)0x06;
         private static final byte INS_SET_T = (byte)0x07;
         private static final byte INS_SET_Q = (byte)0x08;
         private static final byte OBJECT_DELETION = (byte)0x0A;
         private static final byte DEFINE_KEY = (short)0x0B;
         private static final byte DO_KA_TEST = 0x0C;
         private static final byte DO_SIG_TEST = 0x0D;
         private static final byte DO_KEY_GEN = 0x0E;
         private static final byte DO_GET_POINT = 0x0F;
    
         private KeyPair keyPairECC;
         private KeyAgreement keyAgreement;
         private ECPrivateKey ecPrivateKey;
         private ECPublicKey ecPublicKey;
         private ECKey keyContext;
         private Signature sig;
    
        EccTest() {
            keyContext = ecPrivateKey; // initially
            sig = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
        }
    
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              new EccTest().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         }
    
         public void process(APDU apdu) {
              byte[] buf = apdu.getBuffer();
    
              if (selectingApplet()) {
                Util.setShort(buf, (short) 0, VERSION_INFO_MAJOR_MINOR);
                apdu.setOutgoingAndSend((short) 0, (short) 2);
                   return;
              }
              short publicPartLength =0;
    
              try {
                   switch (buf[ISO7816.OFFSET_INS]) {
                        case DEFINE_KEY:
                             if (buf[ISO7816.OFFSET_CDATA] == (byte) 0x01)
                                  keyContext = ecPublicKey;
                             else
                                  keyContext = ecPrivateKey;
                             break;
                        case INS_SET_KEYLENGTH: // resets ECC keys with new key length
                             keyLength = Util.getShort(buf, ISO7816.OFFSET_CDATA);
                           keyPairECC = new KeyPair(KeyPair.ALG_EC_FP, keyLength);
                           ecPrivateKey = (ECPrivateKey) keyPairECC.getPrivate();
                           ecPublicKey = (ECPublicKey) keyPairECC.getPublic();
    //                       keyPairECC.genKeyPair();
    //                         keyLength = Util.getShort(buf, ISO7816.OFFSET_CDATA);
                             break;
                        case INS_SET_p:
                             keyContext.setFieldFP(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
    
                        case INS_SET_A:
                             keyContext.setA(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
    
                        case INS_SET_B:
                             keyContext.setB(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
    
                        case INS_SET_P:
                             keyContext.setG(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
    
                        case INS_SET_M:
                             keyContext.setR(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
    
                        case INS_SET_T:
                             ((ECPrivateKey) keyContext).setS(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
                        case INS_SET_Q:
                             ((ECPublicKey) keyContext).setW(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC]);
                             break;
                        case OBJECT_DELETION:
                              if (JCSystem.isObjectDeletionSupported()) {
                                   JCSystem.requestObjectDeletion();
                              }
                              break;
                        // key agreement example --> common secret
                        case DO_KA_TEST:
                             if(!ecPrivateKey.isInitialized())
                                  ISOException.throwIt(ISO7816.SW_DATA_INVALID);
                             keyAgreement = KeyAgreement.getInstance(KeyAgreement.ALG_EC_SVDP_DH, false);
                             // APDU buffer organization: | 28 byte secret | 53 byte public |
                             // set EC private key
                             keyAgreement.init(ecPrivateKey);
                             // set public part (rest is same as private)
                             publicPartLength = ecPublicKey.getW(buf, (short) 20);
                             // generate common secret which can be used for key agreement
                             keyAgreement.generateSecret(buf, (short) 20, publicPartLength, buf, (short) 0);
                             // output common secret
                             apdu.setOutgoingAndSend((short) 0, (short) 20);
                             break;
                        case DO_KEY_GEN:
                        try {
                             keyPairECC.genKeyPair();
                        } catch (CryptoException e) {
                             ISOException.throwIt((short) (ISO7816.SW_UNKNOWN | e.getReason()));
                        }
                             break;
                        case DO_SIG_TEST:
                             // TASK
                             sig.init(ecPrivateKey, Signature.MODE_SIGN);
                             // ..
                             break;
                        case DO_GET_POINT:
                             short responseLength;
                             if(buf[ISO7816.OFFSET_P1] == (byte)0x01){
                                  responseLength = ecPublicKey.getW(buf, (short) 0);
                             } else {
                                  responseLength = ecPrivateKey.getS(buf, (short) 0);
                             }
                             apdu.setOutgoingAndSend((short) 0, responseLength);
                             break;
                        default:
                             ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                   }
              } catch (CryptoException ce) {
                   ISOException.throwIt((short) (ISO7816.SW_UNKNOWN | ce.getReason()));
              }
         }
    } 
    

    and the script

    /select |eccGfpApp
    # set key length to 256 bits
    /send 80010000020100
    
    # select EC public key, bp_256r1
    /send 800B00000101 9000
    
    # populate p == FP
    /send 80020000#(A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377) 9000
    
    # populate a == A
    /send 80030000#(7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9) 9000
    
    # populate b == B
    /send 80040000#(26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6) 9000
    
    # populate G == P
    /send 80050000#(048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997) 9000
    
    # populate m == R
    /send 80060000#(A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7) 9000
    
    # populate W == Q
    #/send 80080000#(049FCDB28D12F0550D7053D6E4AC6BB848BD4A881DD3007AF18B156DB307733A2E3965BC1F479293DD48E7BD294BBFE3D5679D795630CDAEEBCD8AC909C6A2410A) 9000
    
    # select EC private key
    /send 800B00000102 9000
    
    # populate p == FP
    /send 80020000#(A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377) 9000
    
    # populate a == A
    /send 80030000#(7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9) 9000
    
    # populate b == B
    /send 80040000#(26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6) 9000
    
    # populate P == P
    /send 80050000#(048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997) 9000
    
    # populate m == M
    /send 80060000#(A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7) 9000
    
    # populate S == T
    #/send 80070000#(346EF57569A83AD0DEF40DA12858B6870F4031ABD61052A02F38C37A44FD0E6B) 9000
    
    # test key agreement, output is the shared secret
    #/send 800C0000 *9000
    
    # on-card key generation
    /send 800E0000 9000
    
    /send 800F010000 *9000
    /send 800F020000 *9000
    

    and the newspaper run on JCOP 2.4.2 R2

    /select |eccGfpApp
     => 00 A4 04 00 09 65 63 63 47 66 70 41 70 70 00       .....eccGfpApp.
     (265197 nsec)
     <= 00 01 90 00                                        ....
    Status: No Error
    /send 80010000020100
     => 80 01 00 00 02 01 00                               .......
     (1172 usec)
     <= 90 00                                              ..
    Status: No Error
    /send 800B00000101 9000
     => 80 0B 00 00 01 01                                  ......
     (308301 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80020000#(A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377) 9000
     => 80 02 00 00 20 A9 FB 57 DB A1 EE A9 BC 3E 66 0A    .... ..W.....>f.
        90 9D 83 8D 72 6E 3B F6 23 D5 26 20 28 20 13 48    ....rn;.#.& ( .H
        1D 1F 6E 53 77                                     ..nSw
     (333754 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80030000#(7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9) 9000
     => 80 03 00 00 20 7D 5A 09 75 FC 2C 30 57 EE F6 75    .... }Z.u.,0W..u
        30 41 7A FF E7 FB 80 55 C1 26 DC 5C 6C E9 4A 4B    0Az....U.&.\l.JK
        44 F3 30 B5 D9                                     D.0..
     (284492 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80040000#(26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6) 9000
     => 80 04 00 00 20 26 DC 5C 6C E9 4A 4B 44 F3 30 B5    .... &.\l.JKD.0.
        D9 BB D7 7C BF 95 84 16 29 5C F7 E1 CE 6B CC DC    ...|....)\...k..
        18 FF 8C 07 B6                                     .....
     (263555 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80050000#(048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997) 9000
     => 80 05 00 00 41 04 8B D2 AE B9 CB 7E 57 CB 2C 4B    ....A......~W.,K
        48 2F FC 81 B7 AF B9 DE 27 E1 E3 BD 23 C2 3A 44    H/......'...#.:D
        53 BD 9A CE 32 62 54 7E F8 35 C3 DA C4 FD 97 F8    S...2bT~.5......
        46 1A 14 61 1D C9 C2 77 45 13 2D ED 8E 54 5C 1D    F..a...wE.-..T\.
        54 C7 2F 04 69 97                                  T./.i.
     (259860 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80060000#(A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7) 9000
     => 80 06 00 00 20 A9 FB 57 DB A1 EE A9 BC 3E 66 0A    .... ..W.....>f.
        90 9D 83 8D 71 8C 39 7A A3 B5 61 A6 F7 90 1E 0E    ....q.9z..a.....
        82 97 48 56 A7                                     ..HV.
     (770548 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 800B00000102 9000
     => 80 0B 00 00 01 02                                  ......
     (189250 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80020000#(A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377) 9000
     => 80 02 00 00 20 A9 FB 57 DB A1 EE A9 BC 3E 66 0A    .... ..W.....>f.
        90 9D 83 8D 72 6E 3B F6 23 D5 26 20 28 20 13 48    ....rn;.#.& ( .H
        1D 1F 6E 53 77                                     ..nSw
     (366596 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80030000#(7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9) 9000
     => 80 03 00 00 20 7D 5A 09 75 FC 2C 30 57 EE F6 75    .... }Z.u.,0W..u
        30 41 7A FF E7 FB 80 55 C1 26 DC 5C 6C E9 4A 4B    0Az....U.&.\l.JK
        44 F3 30 B5 D9                                     D.0..
     (250829 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80040000#(26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6) 9000
     => 80 04 00 00 20 26 DC 5C 6C E9 4A 4B 44 F3 30 B5    .... &.\l.JKD.0.
        D9 BB D7 7C BF 95 84 16 29 5C F7 E1 CE 6B CC DC    ...|....)\...k..
        18 FF 8C 07 B6                                     .....
     (439668 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80050000#(048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997) 9000
     => 80 05 00 00 41 04 8B D2 AE B9 CB 7E 57 CB 2C 4B    ....A......~W.,K
        48 2F FC 81 B7 AF B9 DE 27 E1 E3 BD 23 C2 3A 44    H/......'...#.:D
        53 BD 9A CE 32 62 54 7E F8 35 C3 DA C4 FD 97 F8    S...2bT~.5......
        46 1A 14 61 1D C9 C2 77 45 13 2D ED 8E 54 5C 1D    F..a...wE.-..T\.
        54 C7 2F 04 69 97                                  T./.i.
     (409290 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 80060000#(A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7) 9000
     => 80 06 00 00 20 A9 FB 57 DB A1 EE A9 BC 3E 66 0A    .... ..W.....>f.
        90 9D 83 8D 71 8C 39 7A A3 B5 61 A6 F7 90 1E 0E    ....q.9z..a.....
        82 97 48 56 A7                                     ..HV.
     (273408 nsec)
     <= 90 00                                              ..
    Status: No Error
    /send 800E0000 9000
     => 80 0E 00 00                                        ....
     (3320 msec)
     <= 90 00                                              ..
    Status: No Error
    /send 800F010000 *9000
     => 80 0F 01 00 00                                     .....
     (5311 msec)
     <= 04 5D DD 76 03 F2 E8 E0 51 83 57 8B D8 6E 2B 31    .].v....Q.W..n+1
        A1 7C 1F CB 9B 67 3F 2A C9 02 6C F6 B6 98 83 CD    .|...g?*..l.....
        5D 23 5A 85 E7 5D C8 C3 E2 A2 8F EB 34 8D 11 0F    ]#Z..]......4...
        29 00 79 A8 64 47 B4 13 94 53 DD 8D F3 FA D6 83    ).y.dG...S......
        E1 90 00                                           ...
    Status: No Error
    /send 800F020000 *9000
     => 80 0F 02 00 00                                     .....
     (6416 msec)
     <= 7B F1 87 B3 8E 79 F2 1D B9 6A CA 02 FB 7F 80 C8    {....y...j......
        27 15 6F F9 EC 88 C9 E3 51 FB AD DB 51 58 84 B6    '.o.....Q...QX..
        90 00                                              ..
    Status: No Error
    
  • GPShell: How to use the instParam - correctly?

    Nice day
    I want (in fact to have memory of Bachelor) to pass arguments in the install command. (Later it takes the key AES and the ID of the card).
    For testing purposes, I wrote the following abbreviated applet:
    package challengeresponse;
    
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.Util;
    import javacard.framework.APDU;
    
    
    
    public class ChallengeResponse extends Applet {
         
         // Instruction- and class-bytes
         final static byte CLASS = (byte) 0x80;
         final static byte INS_START = (byte) 0x01;
            static byte[] testdata;
        
         private ChallengeResponse(byte bArray[], short bOffset, byte bLength) {
           
              testdata = new byte[2];
              Util.arrayCopy(bArray, (short)0, testdata, (short)bOffset, (short)bLength);
              
              register();
                    
         }
    
         public static void install(byte bArray[], short bOffset, byte bLength)
                   throws ISOException {
              
              new ChallengeResponse(bArray,bOffset,bLength);
         
         }
    
         public void process(APDU apdu) throws ISOException {
              
              byte[] apdu_buffer = apdu.getBuffer();
              apdu.setIncomingAndReceive();
            
              switch(apdu_buffer[ISO7816.OFFSET_INS]) {
              
              case INS_START:
                   
                   // When start-command is received do:
                   
                   Util.arrayCopy(testdata, (short)0, apdu_buffer, (short)ISO7816.OFFSET_CDATA, (short)2);
                   apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)2);
                   
    
              default:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                   
              }
              
    
         }
    
    }
    This should send just what I give is not the applet as a parameter, install it?
    And I install it using gpshell with the following file:
    mode_211
    enable_trace
    enable_timer
    
    establish_context
    card_connect
    select -AID a000000003000000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    delete -AID D0D1D2D3D4D50101
    delete -AID D0D1D2D3D4D501
    delete -AID 0202030405060708090303
    delete -AID 02020304050607080900
    install -file C:\Users\Mark\workspace\ChallengeResponse\bin\challengeresponse\javacard\challengeresponse.cap -nvDataLimit 2000 -instParam C9021234 -priv 2
    
    card_disconnect
    release_context
    The instParam should mean:
    C9: instructions for the applet
    02: length (2 bytes) data
    12 34: data

    However, I get the following response:
    install_for_install_and_make_selectable() returns 0x80206A80 (6A80: Wrong data /
     Incorrect values in command data.)
    Do I did wrong? Help, please!

    Besides why you expect 1234 as a response?

    oB is the length of your HELP
    02 the first byte of your HELP

  • JCOP41 applet installation

    Hello world

    I need to install an applet on a map of JCOP41 but I still get the same error when trying to load the applet on the javacard.

    I'll give you sources if you want to test.

    First the code of my applet:
    package myapplet;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISOException;
    
    public class MyApplet extends Applet {
    
         private MyApplet() {
         }
    
         public static void install(byte bArray[], short bOffset, byte bLength)
                   throws ISOException {
              new MyApplet().register();
         }
    
         // @Override
         public void process(APDU arg0) throws ISOException {
              // TODO Auto-generated method stub
         }
    }
    I know, it's empty, it's just to test.

    Then I generate the corresponding cap file myapplet.cap.

    Finally, I want to install this CAP on the JCOP file by using a script similar to the helloworld example:
    mode_211
    enable_trace
    enable_timer
    
    establish_context
    card_connect
    select -AID a000000003000000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    install -file myapplet.cap -nvDataLimit 2000 -instParam 00 -priv 2
    # getdata
    # close_sc // Close secure channel
    # putkey // Put key
      // options:
      //          -keyind Key index
      //          -keyver Key version
      //          -key Key value in hex
    card_disconnect
    release_context
    And I still get the same error. Here is the full trace:
    mode_211
    enable_trace
    enable_timer
    establish_context
    command time: 0 ms
    card_connect
    command time: 16 ms
    select -AID a000000003000000
    Command --> 00A4040008A000000003000000
    Wrapped command --> 00A4040008A000000003000000
    Response <-- 6F658408A000000003000000A5599F6501FF9F6E06405163452900734A06072A864
    886FC6B01600C060A2A864886FC6B02020101630906072A864886FC6B03640B06092A864886FC6B0
    40215650B06092B8510864864020103660C060A2B060104012A026E01029000
    command time: 46 ms
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 80CA006600
    Wrapped command --> 80CA006600
    Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864
    886FC6B03640B06092A864886FC6B040215650B06092B8510864864020103660C060A2B060104012
    A026E01029000
    Command --> 8050000008585BC86E6E0EAF1300
    Wrapped command --> 8050000008585BC86E6E0EAF1300
    Response <-- 00000177003766952799FF02004B4B698858850FD504E54074EC8C709000
    Command --> 848201001056194DA38EA07C5256CDFB3F540EB038
    Wrapped command --> 848201001056194DA38EA07C5256CDFB3F540EB038
    Response <-- 9000
    command time: 250 ms
    install -file myapplet.cap -nvDataLimit 2000 -instParam 00 -priv 2
    Command --> 80E60200210A0102030405060708090008A000000003000000000AEF08C6020108C8
    0207D00000
    Wrapped command --> 84E60200290A0102030405060708090008A000000003000000000AEF08C6
    020108C80207D000751F5C332DA8F18E00
    Response <-- 009000
    Command --> 80E80000EFC481FE8200FE010014DECAFFED01020400010A01020304050607080900
    02001F0014001F000F00150012000C0018000A000800000041000000000000020100040015020301
    07A0000000620101000107A000000062000103000F010B0102030405060708090000000806000C00
    800300FF00070100000015070018000110188C00007A02308F00013D8C00028B00037A00207A0800
    0A000000000000000000000500120004068003000100000006000001038003010900080000000405
    0604030B004101000100000000000003FF820001000A00050000000000090008000C000B00000000
    07010015000F00010000
    Wrapped command --> 84E80000F7C481FE8200FE010014DECAFFED01020400010A010203040506
    0708090002001F0014001F000F00150012000C0018000A0008000000410000000000000201000400
    1502030107A0000000620101000107A000000062000103000F010B01020304050607080900000008
    06000C00800300FF00070100000015070018000110188C00007A02308F00013D8C00028B00037A00
    207A08000A0000000000000000000005001200040680030001000000060000010380030109000800
    000004050604030B004101000100000000000003FF820001000A00050000000000090008000C000B
    0000000007010015000F00010000F4839C8BB3E25AC1
    Response <-- 6A80
    load() returns 0x80206A80 (6A80: Wrong data / Incorrect values in command data.)
    It seems that the installation will fail, but I don't know why. What bothers me is that the helloworld.cap file provided as example works, but none of the .cap files I generate me don't. There maybe something wrong with how I generate these files.

    Any idea about the error returned?

    Thank you

    When you have compiled cmdlet against javacard 2.2.1 was normal or empty applet? If it was empty applet that was not loaded due to bug GPShell, normal applet is not charged bacause of incorrect version

  • Send bytes of card to the Terminal

    Hi guys

    When I studied the sendBytes.Length method in which card sends data to the terminal, I found that in each shipment, the card sends an ACK to the terminal as well. These acknowledgments are reported as below

    private public static final byte ACK_NONE = (byte) 0.
    private public static final byte ACK_INS = (byte) 1;
    private public static final byte ACK_NOT_INS = (byte) 2;

    An example of sending within the acknowledgement: t0SndData (this.buffer, bOff, the, (byte) 0);

    t0SndData (byte [] paramArrayOfByte, short paramShort1, short paramShort2, paramByte bytes)

    -this.buffer (paramArrayOfByte): buffer that contains the data being sent
    -bOff (paramShort1): data sent in the buffer offset
    -The (paramShort2): length of the data being sent
    -0 (paramByte): ACK

    ~ ~ > My question: what are these acknowledgements? What is the meaning of each ACK above?

    One of your concerns is always very appreciated ^^

    Hi guys.
    I think that belongs to the basic rule for the sequence of the smart card.

    terminal---------------------------------------------------Card

    Send the header (5 bytes) APDU---> card check these 5 bytes (CLA, INS, P1, P2, P3)

    <---------------------------------------------------Card send="" ack="" to="" inform="" that="" smartcard="" understand="" the="">

    <------------------data--------------------------->Terminal Forms data or card is INS and P3 (lc or the)

    There are 3 situation: No ACK if no terminal need response card, or Lc or the
    have 2 kinds of ACK: ACK or ~ ACK (to send or receive each individual byte or send/receive all bytes).
    If you understand me, man!

  • problem of memory during installation of the applet

    Hello everyone,

    I try to install an applet on TOP javacard IM GX4 card, but I have a memory problem...

    This is my code of the applet:
    package codeSimpleCompteur;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    
    public class Test extends Applet {
    
           final byte CLA_MONAPPLET = (byte) 0xB0;
           final byte INS_INCREMENTER_COMPTEUR = 0x00;
           final byte INS_DECREMENTER_COMPTEUR = 0x01;
           final byte INS_INTERROGER_COMPTEUR = 0x02;
           private byte compteur;
           byte[] tab;
         
         public Test() {
              compteur = 5;          
         }
         
         public static void install(byte bArray[], short bOffset, byte bLength)
              throws ISOException {
              new Test().register(bArray, bOffset, bLength);          
         }
    
         public void process(APDU apdu) throws ISOException {
              byte[] buffer = apdu.getBuffer();
              
              if (this.selectingApplet()){
                   return;
              }
              
              if (buffer[ISO7816.OFFSET_CLA] != CLA_MONAPPLET) {
                   ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
              }
              
              switch (buffer[ISO7816.OFFSET_INS]) {
              
              
                   case INS_INCREMENTER_COMPTEUR:
                        compteur++;          
                        break;
         
    
                   case INS_DECREMENTER_COMPTEUR:
                        compteur--;
                        break;
                   
                   case INS_INTERROGER_COMPTEUR:
                        tab = new byte[5];
                        tab[0] = compteur;          
                        apdu.setOutgoing();
                        apdu.setOutgoingLength((short)tab.length);
                        apdu.sendBytesLong(tab,(short) 0, (short) tab.length);
                        break;
              
                      default:
                        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
              }
         }
    }
    and when I try to install it I have this error:
    install -file codeSimpleCompteur.cap
    file name codeSimpleCompteur.cap
    Command --> 80E602001C09A00000006203010C0108A000000018434D000006EF04C60202700000
    Wrapped command --> 84E60200286364A6E5E0D338639BBC807D11E7639A6D1A163A3195C79C076B3E6818C0EE2E59066D9AEAAC01ED00
    Response <-- 009000
    Command --> 80E80000EFC4820265010013DECAFFED010204020109A00000006203010C0102001F0013001F000E000B0056000C00B0000A0023000000BD00000000000001010004000B01020107A000000062010103000E010AA00000006203010C0101003306000C0080030B00010701000000430700B0000210188C00111810B0880018038801180488021805880318068804181006880518078806180888071810078808180888097A04308F000B3D8C000C181D1E8B000D7A0421198B000E2D188B000F60037A1A032510B06A08116E008D00101A042573004800000002000D00180023183D840904415B88097038183D840904435B8809
    Wrapped command --> 84E80000F812D71F1AFC82A2FDB501FF71CCEB5E29DE80D33AFFE71FF49288374F89CF6B56C0988032BB379C47534C47E9E3B3F4F45B86B7B564BB2489542CE853946DC877E011CFB1F802FEABB62D9CF84BD723763D3ED8D6E11AA9F7042912DD81EFA827BC88ED3D8938053A2AA38D52FACE16A4852DE7EE63FF85B4265AA002B31E6B63D3A4A3301B88F2A07C6E5C770235369CC984A490365AFD2A1F8FCA02C3E7E3D3DFB65088D66EBD2E167B7199EEE94FD8F9B8C034E27E2FF7C34685D82B5EDC04A8ED6D8B19EBFBBEA73863CFD0BC75C6CD42AC85975908E01477BA2DCB0FD0386C1E552BEFF92DCED548980B830D0A47767FB6BF51176BEB
    Response <-- 009000
    Command --> 80E80001EF702D181029900B870AAD0A03AE0938198B00123B19AD0A928B001319AD0A03AD0A928B00147008116D008D00107A08000A0000000000000000000005005600150200000102000002020000030200000402000005020000060200000702000008020000090200000A0200000001000000060000010380030203800A0103800303068007010680030003800A0703800A0903800A0509002300140B04040404050404050440050605090203090703000B0531040607051037080A080B00BD010001000000000B00030000000000002E011000000180030210000002800303100000038003041000000480030510000005
    Wrapped command --> 84E80001F80AA622FE5D6E75C8EC596F1B01771A23433D84FAA0E45CCF6FD98FC5AF63A1B6C71E8FAFE640E743D30BB5B628255AE9942A60A803599555942C44520B2D2B27F5981029F781D5544A0031518D3399C91F000C7AFE086ED091CF012676CE35A00A5676F087B9F3D3E6C42AEAF2CEE4848E9B751A2C9665AE16F98EEB5D2A160F8B12D9DD7B1A5849579ECF8006289B40454E3E8A8C12451FDA75F575448E41E6BDE1374C50717C872E06439A5F625267A757CB5B247D0C7A363AB3F8F85E40D696D277212E45EF6BE71F6CC43FE4BDD4ED7D6C5FB6C5F785A6926BCD71A30F381C7A11135314721EBD4AC80AE911AB23B8CF0323658AEC8F
    Response <-- 009000
    Command --> 80E880028B8003061000000680030710000007800308100000088003091000000980030A0200000A8003008100010030003000000000010900330032000E0000000007010043003E006B000000000015002C002C002C002C002C002C002C002C002C002C002EFFFF00300032002E00350037003000390037003B013001B0011004B43101200241014004B441066800A100
    Wrapped command --> 84E88002988B26EA862F2CEBBB9D85FAE96EEEA8CC7C9134BDFBC258587EC8A31D0721E35DEE8F8E80B24ADADE5B4871A291FC1A3396CE9F510A650EAB195D352E696F3450325FCEFE18DDF94C86BE8B8A268956AECA9C4E83DC6B91AF0BA0D03E9E78896769146B41578ED560409049D01202A027AF7EF73985FB65F4C0C47B45F400F4B9EDE2BC344EF09DD437D7429043821EC3EC5A6AC6CE99912400
    Response <-- 009000
    Command --> 80E60C002609A00000006203010C010AA00000006203010C01010AA00000006203010C0101010002C9000000
    Wrapped command --> 84E60C0030FE5C8C290BD6BF2BEFF1C59495E884045AB4418BAFBF48D6C41A9BACD25DE3462262C0B503564CCE38087340DAB6C8DF00
    Response <-- 6A84
    install_for_install_and_make_selectable() returns 0x80206A84 (6A84: Not enough memory space.)
    get_Status return:
    OP201_get_status() returned 18 items
    
    List of applets (AID state privileges)
    a0000000620001     1     0
    a0000000620002     1     0
    a0000000620003     1     0
    a0000000620101     1     0
    a000000062010101     1     0
    a0000000620102     1     0
    a0000000620201     1     0
    a00000015100     1     0
    a0000001320001     1     0
    a0000000030000     1     0
    a000000018100101     1     0
    a000000018100106     1     0
    a000000018100201     1     0
    a00000001830080100000000000000ff     1     0
    a00000001830080100000000000000fe     1     0
    a00000001830060200000000000000ff     1     0
    a00000001830060100000000000000ff     1     0
    a00000001830030100000000000000ff     1     0
    I can't uninstall this applet, and I'm not sure that the problem is memory space...
    you have an idea about this? There is an option with GPshell know the size of free memory on the card?

    concerning
    Alexis

    your instruction register (blabla) is bad.

    This function receives the INSTALL APDU buffer (to install [and maybe make selectable]).

    bOffset points to the offset in the table where the length of using the instance is stored in LV format (see globalplatform).

    Register() expected
    -the table where the help applet is stored
    -the offset in which it is stored
    -the duration of the assistance

    example: you are somewhere in the apdu
    ..... 06 112233445566...

    bOffset corresponds to the shift in Baker at the "06" value
    AID has length 06 and started the next byte.

    If you need to write

    Register (Baker, (short)(bOffset+1), Baker [bOffset]);

    By change, register() without parameters is done automatically.

    can you guess your mistake now? Register (Baker, bOffset, bLength) indicates that the cmdlet HELP length is the length of the full buffer, starting at an offset of zero in the buffer zone. It is a bad mistake of length to HELP, combined with excess of array subscript if the french_traveller_64 trying to copy using!

    concerning

  • APDU buffer

    Hi guys

    Thank you guys a few questions related to sending and receiving data

    1. in the context of the Javacard API, I'm quite confused with the love of the method "receiveBytes(short bOff)" (from class APDU).

    a. this method receives the data and highlights the APDU buffer memory, starting at the offset bOff
    b. this method retrieves incoming APDU buffer data, starting at the offset bOff

    Who is right?

    2 to send data, it is necessary to copy the data in the APDU buffer before sending? We can send data directly in a table?

    Example: the method 'sendBytesLong (byte [] outData, bOff short, short len). Why send directly from the table "outData"? Why do need to copy on APDU buffer?

    1. in the context of the Javacard API, I'm quite confused with the love of the method "receiveBytes(short bOff)" (from class APDU).

    a. this method receives the data and highlights the APDU buffer memory, starting at the offset bOff
    b. this method retrieves incoming APDU buffer data, starting at the offset bOff

    Who is right?

    This method retrieves the OS map data and fills the APDU buffer (1).

    2 to send data, it is necessary to copy the data in the APDU buffer before sending? We can send data directly in a table?

    You can do either. If you have a large buffer in the EEPROM you can work with more data than the size of the APDU buffer (usually 261 bytes), but it is slower. If you have less than this amount, you can use the APDU buffer directly. Depending on where the sending of data are you can use.

    Example: the method 'sendBytesLong (byte [] outData, bOff short, short len). Why send directly from the table "outData"? Why do need to copy on APDU buffer?

    These questions seem to contradict. If you mean why the JCRE in the APDU buffer copy internally, it is perhaps because the OS map needs to have the data in a particular entry JCRE point to transmit data.

    See you soon,.
    Shane

  • Question related to the bays of transients

    Hello

    I have a memory error loading simple a helloworld applet that uses a transient 256bytes array in the constructor.

    I use a yubikey neo (atr FE: 3B FA 13 00 00 81 31 15 59 75 62 69 6 b 65 79 4th 45 4F A6), JCDK 2.2.2 and the Eclipse plugin. The PAC file is loaded using YPG.

    I can load only one instance of the applet (AA010203040506070809 help for example) correctly, but I get a memory error when I try to load a second copy (for example with the help of BB010203040506070809).

    Error message when loading the applet is: APDU response: 6 to 84.

    I'm sure that this error is due to the presence of an array of transitional: If this line is deleted, I can easily load multiple instance of the applet (the PAC file is only 3kbyte and I can easily load a cap of 30kbyte file).

    I don't understand why the memory error when loading of the applet (and not during execution) since the transient table is allocated in the RAM (as far as I understand).

    Secondly, two tables of 256 bytes doesn't seem much to me, since the yubikey has about 2915 byte memory transient available (depending on JavaCard support test).

    Obviously, I'm missing something but I don't know what.

    Here is the code of the applet (helloworld Sun modified with a line of the constructor):

    {code}

    /*

    * Copyright 2005 Sun Microsystems, Inc. All rights reserved.

    * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

    */

    // /*

    Workfile: @(#) HelloWorld.java 1.7

    Version: 1.7

    Date: 01/03/06

    //

    Archive: /Products/Europa/samples/com/sun/javacard/samples/HelloWorld/HelloWorld.java

    Change: 03/01/06 19:01:06

    Original author: Mitch Butler

    // */

    package helloworld;

    Javacard.framework import. *;

    /**

    */

    public class helloworld extends Applet

    {

    Private byte [] echoBytes;

    private final static short LENGTH_ECHO_BYTES = 256;

    Private byte [] transientarray;

    /**

    * Only installation method of this class should create the object of the cmdlet.

    */

    HelloWorld() protected

    {

    echoBytes = new ubyte [LENGTH_ECHO_BYTES];

    transientarray = 256 JCSystem.makeTransientByteArray ((short), JCSystem.CLEAR_ON_RESET); / / Transitional table causes the error of memory when loading the

    Register();

    }

    /**

    * Install this applet.

    @param Baker table that contains the installation settings

    @param bOffset starting in Baker offset

    @param bLength the length in bytes of the data parameter Baker

    */

    Public Shared Sub install (byte [] Baker, short bOffset, bLength bytes)

    {

    new helloworld();

    }

    /**

    * Treats an incoming APDU.

    * @see APDU

    @param apdu incoming APDU

    ISOException @exception with the bytes of response according to ISO 7816-4

    */

    Public Sub process (APDU apdu)

    {

    ubyte buffer [] = apdu.getBuffer ();

    short bytesRead = apdu.setIncomingAndReceive ();

    short echoOffset is 0 (short).;

    While (bytesRead > 0) {}

    Util.arrayCopyNonAtomic (buffer, ISO7816. OFFSET_CDATA, echoBytes, echoOffset, bytesRead);

    echoOffset += bytesRead;

    bytesRead = apdu.receiveBytes (ISO7816. OFFSET_CDATA);

    }

    apdu.setOutgoing ();

    apdu.setOutgoingLength ((short) (echoOffset + 5));

    header of the echo

    apdu.sendBytes ((short) 0, (short) 5);

    the echo data

    apdu.sendBytesLong (echoBytes, (short) 0, echoOffset);

    }

    }

    {code}

    Hello

    I don't see any problems either.

    The limit could come from the yubikey itself, cards may have a limit on the number of instances they allow by the applet. I already saw this, and this info is rarely available until you have problems and ask the provider of card/object.

    It seems not to be the case because "it works" without the transient table.

    There are some things you can try:

    1)

    Very often the buffer APDU itself can be used volatile buffer, without transitional additional.

    2)

    I try to use JCSystem.CLEAR_ON_DESELECT instead of JCSystem.CLEAR_ON_RESET.

    These may not be implemented, or maybe a bug. The difference is that all CLEAR_ON_DESELECT references are "stacked" for each instance, instead of reserve more memory for each instance.

    3)

    Even if you create more than one instance, the PAC file is loaded only once, same as a class in a real JVM, and each instance uses only memory to store references and objects of "instance". However, static fields are (obviously) only stored as a single, shared by all instances.

    It is possible to declare your 'static' transitional object and return only once, as you would for a singleton object, when the reference is found to be "null". This is possible because usually, instance that a cmdlet is alive at a given time, and this memory is a buffer of time anyway, so we don't care if it belongs to the class or instance.

    There is a catch though, as the reference to that object is bound to the class (package) and not to the instance. If this object reference is retained even if you delete all instances (and you will find it again once you re - create another instance). It will be only deleted when you delete the package.

    If this is a problem, the solution is explicitly to count the number of instances created: increment a static field in the constructor and it decrement in uninstall() reminder provided by the AppletEvent of JC 2.2.x interface.

  • RSA key generation fails on JCARD 2.2.2

    Hello

    I am a beginner in JCard programming (2 days of experience...) and I'm trying to deploy an application on an emulated map ARB who generates an RSA key pair and sends the public key via the client application of RMI, home somehow, when I run the init method of the client application, I get this exception:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.javacard.impl.NativeMethods.getCurrentContext (B)

    at com.sun.javacard.impl.NativeMethods.getCurrentContext (Native Method)

    at com.sun.javacard.impl.PrivAccess.getCurrentAppID(PrivAccess.java:454)

    to javacard.framework.CardRuntimeException. < init > (CardRuntimeException.java:46)

    to javacard.security.CryptoException. < init >(DashoA10*..: 25).

    at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.throwIt (unknown Source)

    at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.throwException (unknown Source)

    at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.getObject (unknown Source)

    at com.sun.javacard.rmiclientlib.JCRemoteRefImpl.parseAPDU (unknown Source)

    at com.sun.javacard.rmiclientlib.JCRemoteRefImpl.invoke (unknown Source)

    at sid2.CompteurImpl_Stub.initialiser (unknown Source)

    to sid2. ClientRmi.main (ClientRmi.java:36)

    and here is the code of my called JCard cmdlet:

    sid2 package;

    import java.rmi.RemoteException;

    Import javacard.framework.UserException;

    Import javacard.framework.service.CardRemoteObject;

    Javacard.security import. *;

    Import javacardx.crypto.Cipher;

    public class compteurimpl extends CardRemoteObject implements {ICompteur}

    private bytes counter = 120;

    RSAPrivateKey rsa_PrivateKey;

    RSAPublicKey rsa_PublicKey;

    Rsa_KeyPair key pair;

    Encryption by cipherRSA;

    {public setPub Sub (byte [], byte [] mod expo)

    rsa_PublicKey.setExponent (expo, (short) 0, (short) expo.length);

    rsa_PublicKey.setModulus (mod, (short) 0, (short) mod.length);

    }

    public byte [] getPub() {}

    Byte [] ret = null;

    rsa_PublicKey.getModulus (ret, (short) 0);

    rsa_PublicKey.getExponent (retirement, short ()(ret.length+1));

    return ret;

    }

    Public Sub initialiser(byte v) throws RemoteException, {UserException}

    rsa_KeyPair = new pair of keys (KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);

    rsa_KeyPair.genKeyPair ();

    rsa_PublicKey = rsa_KeyPair.getPublic () (RSAPublicKey);

    rsa_PrivateKey = rsa_KeyPair.getPrivate () (RSAPrivateKey);

    counter = v;

    }

    }

    anyone can point out what I'm doing wrong here? Thank you

    PS: I already tried some basic stuff and it works beautifully, as having a variable on a Jcard and incrementing, get and put.

    Hello

    You can view the documentation, but memory emulator CREF only supports 512-bit keys.

    The code below has also the question that you want to copy to a buffer zero. You must allocate a buffer, or use a buffer allocated previously as the APDU buffer. This method allocates memory for you.

    public byte [] getPub() {}

    Byte [] ret = null;

    rsa_PublicKey.getModulus (ret, (short) 0);

    rsa_PublicKey.getExponent (retirement, short ()(ret.length+1));

    return ret;

    }

    -Shane

  • Try to get a sample of authentication applet works.

    package GenSignVerify;

    Javacard.framework import. *;

    Javacard.security import. *;

    /**

    */

    SerializableAttribute public class GenSignVerify extends Applet {}

    /**

    * Only installation method of this class should create the object of the cmdlet.

    */

    public GenSignVerify() {}

    Register();

    }

    /**

    * Install this applet.

    *

    @param Baker

    * the table that contains the installation settings

    @param bOffset

    * starting in Baker offset

    @param bLength

    lengthwise in bytes of the data parameter Baker

    */

    {} Public Shared Sub install (byte [] Baker, short bOffset, bLength bytes)

    GP-compatible recording of JavaCard applet

    new GenSignVerify();

    }

    /**

    * Treats an incoming APDU.

    *

    * @see APDU

    @param apdu

    Incoming APDU

    * @exception ISOException

    * with the bytes of response according to ISO 7816-4

    */

    {} public void process (APDU apdu)

    Byte [] buf = apdu.getBuffer ();

    Byte [] testSig = new byte [256];

    Byte [] test = new byte [] {0x01, 0x02, 0x03, 0x04};

    Key of the key pair = null;

    SIG Signature;

    /*

    check the command SELECT UDPA

    If ((buf [ISO7816. OFFSET_CLA] == 0) & &

    (buf [ISO7816. OFFSET_INS] = (byte) (0xA4))) {}

    return;

    }*/

    If (selectingApplet ())

    {

    return;

    }

    apdu.setIncomingAndReceive ();

    switch (buf [ISO7816. {} OFFSET_INS])

    case (byte) 0 x 01:

    if(Keys == null)

    {

    keys = new pair of keys (KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_AES_256);

    keys.genKeyPair ();

    }

    INITIALIZE THE SIGNATURE AND SIGN

    GIS = Signature.getInstance (Signature.ALG_RSA_SHA_PKCS1, false);

    SIG.init (Keys.getPrivate (), Signature.MODE_SIGN);

    short Len = sig.sign (test, (short) 0, (short) test.length, testSig, 0 (short));

    VERIFY THE SIGNATURE

    SIG.init (Keys.getPublic (), signature. MODE_VERIFY);

    GIS. Verify (testing, (short) 0, (short) test.length, testSig, (byte) 0, len);

    apdu.setOutgoing ();

    apdu.setOutgoingLength (len);

    apdu.sendBytesLong (testSig, (short) 0, len);

    break;

    0xCA, case (byte):

    break;

    by default:

    good practice: If you don't know the statement, say:

    ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);

    }

    }

    }

    and this is the .scr file

    Test script for the Applet "GenSignVerify".

    power-up;

    Select GenSignVerify //aid/19550633C5/99

    0 x 00 0xa4 0x04 0x00 X 06 X 19 0 0 0 X 0 X 06 55 0 X 33 0XC5 0X9A 0x7F;

    Send the APDU with chain J C 3

    0 x 80 0xCA 0x00 0x00 0 x 03 0x4A 0x43 0 x 33 0x7F;

    Must return SW1:6 D, SW2:00-> statement not supported since INS = D2

    0 x 80 0xD2 0x00 0x00 0 x 03 0x4B 0x4D 0 x 33 0x7F;

    To enter the key of the case and gen, sign and verify data

    0x00 0x01 0x00 0x00 0 x 00 0x7F;

    powerdown;

    When I build and run this is my output:

    Received ATR = 0x3b 0xf0 0x11 0 x 00-0xff 0x00

    CLA: 00, INS: a4, P1: 04, P2: Lc, 00:06, 19, 55, 06, 33, c5, 9A, the: 00, SW1: 90, SW2: 00

    CLA: 80, INS: ca, P1: 00, P2: Lc, 00:03, 4, 43, 33, the: 00, SW1: 90, SW2: 00

    CLA: 80, INS: d2, P1: 00, P2: Lc, 00:03, 4B, 4 d, the 33,: 00, SW1: 6 d, SW2: 00

    CLA: 80, INS: P1 01: 00, P2: LK, 00:01:45, the: 00, SW1: 6f, SW2: 00

    run:

    BUILD successful (total time: 6 seconds)

    The last line is where is my mistake. 6F00 indicates that there is no specific diagnosis. I don't know where I went wrong in my code. Any help or advice would be appreciated. Thank you!

    According to this - https://forums.oracle.com/message/10589893 , you should use KeyBuilder.LENGTH_RSA_512 when you use a Java Card sim card. So now the correct code is:

    package GenSignVerify;

    Javacard.framework import. *;

    Javacard.security import. *;

    /**

    *

    Raja * @author

    */

    SerializableAttribute public class GenSignVerify extends Applet {}

    private key pair key = null;

    SIG Signature private;

    Byte [] testSig = new byte [256];

    Byte [] test = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};

    Check Byte [] = {0x00};

    public GenSignVerify() {}

    CREATE THE SIGNATURE OBJECT

    GIS = Signature.getInstance (Signature.ALG_RSA_SHA_PKCS1, false);

    }

    {} Public Shared Sub install (byte [] Baker, short bOffset, bLength bytes)

    GP-compatible recording of JavaCard applet

    new GenSignVerify () .register (Baker, (short) (bOffset + 1), Baker [bOffset]);

    }

    {} public void process (APDU apdu)

    value Boolean = false;

    GOOD PRACTICE: BACK 9000 ON SELECT

    If (selectingApplet()) {}

    return;

    }

    Byte [] buf = apdu.getBuffer ();

    switch (buf [ISO7816. {} OFFSET_INS])

    case (byte) 0 x 01:

    If (key == null) {}

    try {}

    CREATE THE RSA KEY PAIR

    keys = new pair of keys (KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_512);

    }

    {} catch (EC CryptoException)

    short-reason = ce.getReason ();

    }

    START THE PROCESS OF GENERATION OF CARD KEYS

    keys.genKeyPair ();

    }

    INITIALIZE WITH THE PRIVATE KEY

    SIG.init (Keys.getPrivate (), Signature.MODE_SIGN);

    BUFFER INCOMING SIGN

    short Len = sig.sign (test, (short) 0, (short) test.length, testSig, 0 (short));

    INIT WITH PUBLIC KEY

    SIG.init (Keys.getPublic (), Signature.MODE_VERIFY);

    VERIFY THE SIGNATURE

    value = sig.verify (test, (short) 0, (short) test.length, testSig, (byte) 0, len);

    IF AUDITED CORRECTLY, RETURNS 1, OTHERWISE RETURN 0

    If {(value)

    Check [0] = (byte) 0 x 01;

    }

    apdu.setOutgoing ();

    apdu.setOutgoingLength ((short) verify.length);

    apdu.sendBytesLong (check, (short) 0, (short) verify.length);

    break;

    0xCA, case (byte):

    break;

    by default:

    good practice: If you don't know the statement, say:

    ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);

    }

    }

    }

    With the same script APDU, I get the following result:

    Received ATR = 0x3b 0xf0 0x11 0 x 00-0xff 0x00

    CLA: 00, INS: a4, P1: 04, P2: Lc, 00:06, 19, 55, 06, 33, c5, d0, the: 00, SW1: 90, SW2: 00

    CLA: 80, INS: ca, P1: 00, P2: Lc, 00:03, 4, 43, 33, the: 00, SW1: 90, SW2: 00

    CLA: 80, INS: d2, P1: 00, P2: Lc, 00:03, 4B, 4 d, the 33,: 00, SW1: 6 d, SW2: 00

    CLA: 00, INS: P1 01: 00, P2: Lc, 00:00, the: 01, 01, SW1: 90, SW2: 00

    Hope that helps someone who is stuck...

  • 9000 SW

    Hi guys

    When I build a project with the SDK Javacard 2.1.1 there SW 9000 (OK)

    However, when I study the code of this API (you can download the source code for SUN to address [1]), there is no place showing 9000 Manager.

    In particular, when I study the APDU, method 'sendBytes.Length' class-> it is only 61xx sent to Terminal and there is no 9000 Envoy when the transmission is complete

    Can U tell me what part in the present code API showing the manipulation of 9000?

    -----------------------------------------------------

    https://CDs.Sun.com/is-bin/INTERSHOP.Enfinity/WFS/CDs-CDS_Developer-site/en_US/-/USD/ViewProductDetail-start?ProductRef=7231-javacard_devkit-2.1.1-oth-JPR@CDs-CDS_Developer [1]

    You can watch another piece of code. SW_NO_ERROR is set to no treatment of an APDU and no exception occurs. As you know, how to set the SW in an applet to something other than 0 x 9000 is to throw an ISOException with the SW you need. Look at the code bellow.

        /**
         * Main entry point invoked by VM when card is reset.
         */
         static void main()
         {
             if (!initDone) cardInit();      // card initialization (first time only)
             cardReset();                    // session initialization (each card reset)
             short sw = 0;
    
            // main loop
             while (true) {
                PrivAccess.resetSelectingAppletFlag();
                 theAPDU.complete(sw); // respond to previous APDU and get next
                 try {
                     processDispatcherAPDU(); // Dispatcher handles the SELECT APDU
                     // dispatch to the currently selected applet
                     if (PrivAccess.getSelectedAppID()==PrivAccess.APP_NULL) {
                       // if no applet selected
                       ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
                       }
                    PrivAccess.getSelectedApplet().process(theAPDU);
                      // abort transaction if applet forgot to commit it
                      if (JCSystem.getTransactionDepth() != 0) {
                         TransactionException.throwIt(TransactionException.IN_PROGRESS);
                         }
                      sw = ISO7816.SW_NO_ERROR;
                 } catch (ISOException ex) {
                     // get SW from ISOException reason
                     sw = ex.getReason();
                 } catch (Throwable e) {
                     // any other exception is unknown reason
                     sw = ISO7816.SW_UNKNOWN;
                 }
    
                  // abort transaction if still in progress
                  if (JCSystem.getTransactionDepth() != 0) {
                     JCSystem.abortTransaction();
                 }
                }
         }
    

    Once where a SW occupies about something else, that is if there is an error. I guess the send61xx method also checks if there is more data and sends a 61xx if necessary. You question was where is the 9000 series. Well that is :)

    See you soon,.
    Shane

    Published by: safarmer on July 26, 2011 12:09 AM

  • Example problem simple e-wallet with smart card real

    Hi people,

    I develop a javacard applet. Before loading and installation of this applet on our javacard, I tested this procedure with the example of electronic purse widely available on the internet. I think most guys should test this example you were the javacard beginner.

    I think that my problem here corresponds to the bones of chip instead of the applet code, but as not experienced in the world of javacard, I need your help.

    Here is the code of e-wallet (which is correctly compiled, converted, loaded and instantiated/installed on card)
    package companyname.sampleapplet;
    
    
    import javacard.framework.*;
    
    public class Epurse extends Applet {
      private short balance;
      public static final byte CLA = (byte)0x80;
      public static final byte insCredit = (byte)0xA1;
      public static final byte insDebit = (byte)0xA2;
      public static final byte insGetBalance = (byte)0xA3;
      public static final byte insSetPin = (byte)0xB1;
      public static final byte insGetAuth = (byte)0xB2;
      public static final byte insDelog = (byte)0xB3;
      
      OwnerPIN pin;
      
      public boolean select () {
        return (true);
      }
      
      public void deselect(){     
        pin.reset();
      } 
    
      public Epurse() {
        super();
        this.balance = 0;
        pin = new OwnerPIN((byte)3, (byte)8);
        pin.update( new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}, (byte)0, (byte)4); //default PIN is 00 00 00 00
      }
    
      public static void install (byte [] bArray, short bOffset, byte bLength  ) throws ISOException {
        Epurse = new Epurse();
        s.register();
      }
    
      public void process(APDU apdu) throws ISOException{
        byte[] buffer = apdu.getBuffer();
        if (selectingApplet()) return;
        if(buffer[0]!=CLA) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 
        ISOException.throwIt(ISO7816.SW_FILE_INVALID);
      
        switch (buffer[ISO7816.OFFSET_INS]){
        case insCredit :
             if(pin.isValidated()) credit(apdu, buffer); 
             else 
              ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
             break;
        case insDebit : 
             if(pin.isValidated()) 
               debit(apdu, buffer);
             else 
               ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
             break;
        case insGetBalance : 
             if(pin.isValidated()) 
               getbal(apdu, buffer); 
             else 
               ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
             break;
        case insGetAuth : 
             checkPIN(apdu, buffer);
             break;
        case insSetPin : 
             if(pin.isValidated()) 
               setPIN(apdu, buffer);
             else 
               ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
             break;
        case insDelog :
             pin.reset(); 
             break;     
        default:
             ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
        }    
      }
    
      private void credit(APDU apdu, byte[] buffer ) {
        
      }
      private void debit(APDU apdu, byte[] buffer ) {
     
      }
      private void getbal(APDU apdu, byte[] buffer) {
      
      }
    
      private void checkPIN(APDU apdu, byte[] buffer){
        short Le = apdu.setIncomingAndReceive();
        byte[] data = new byte[Le];
        try{
          for (short i=0; i<Le; i++)
          {
            data[i] = buffer[(short)(i+ISO7816.OFFSET_CDATA)];
          }
          if (pin.check(data, (short)0, (byte)Le)) return;
          else 
         ISOException.throwIt(ISO7816.SW_RECORD_NOT_FOUND);//6A83 //6985->SW_CONDITIONS_NOT_SATISFIED
        } catch(NullPointerException e) {
            ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); //6982
        } catch(ArrayIndexOutOfBoundsException a) {
            ISOException.throwIt(ISO7816.SW_FILE_FULL); //6A84
        }
      }
    
      private void setPIN(APDU apdu, byte[] buffer){
    
      }
    }
    My problem is:
    -applet SELECT command is executed successfully
    - BUT the command check pin (80 00 00 04 01 02 03 04 B2) fails (which it should ask the cmdlet to execute the checkPIN method) fails with the error code 6983 (authentication) blocked

    Edited: it seems to me that even I remove control PIN for this application of electronic wallet for every shipment of order pay-per-view, I always get this status word: * 6983 *.

    In your experience, what reason causes the card to return this status word?

    Can't wait to hear from you
    Best regards
    JDL

    Jean-Damien LEVIEL wrote:
    if(buffer[0]!=CLA) ISOException.throwIt (ISO7816.SW_CLA_NOT_SUPPORTED);
    ISOException.throwIt (ISO7816.SW_FILE_INVALID);

    This always throws an exception.

    Adriaan

  • Exception for the DAC device

    Hello
    I am trying to run the PurseClient.java sample in Eclipse, but I get the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/Sun/javacard/apduio/CadDevice
    to com.sun.javacard.clientlib.ApduIOCardAccessor. < init >(Unknown Source)
    at PurseClient.main (PurseClient.java:33)
    Caused by: java.lang.ClassNotFoundException: com.sun.javacard.apduio.CadDevice
    java.net.URLClassLoader to $1.run (unknown Source)
    at java.security.AccessController.doPrivileged (Native Method)
    at java.net.URLClassLoader.findClass (unknown Source)
    at java.lang.ClassLoader.loadClass (unknown Source)
    to Sun.misc.Launcher$appclassloader$ AppClassLoader.loadClass (unknown Source)
    at java.lang.ClassLoader.loadClass (unknown Source)
    ... 2 more

    I don't know what the problem is, I run ARB-i demoee (the name of my EEPROM image) and then I run client eclipse award.

    The error is on line 33:

    /*
     * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
     * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
     */
    
    import java.rmi.*;
    import javacard.framework.*;
    
    import com.sun.javacard.clientlib.*;
    import com.sun.javacard.rmiclientlib.*;
    
    import java.util.ResourceBundle;
    
    public class PurseClient {
        
        private static final byte[] RMI_DEMO_AID = {
            (byte)0xa0, (byte)0x00, (byte)0x00,
            (byte)0x00, (byte)0x62, (byte)0x03,
            (byte)0x01, (byte)0xc, (byte)0x8,
            (byte)0x01
        };
        
        public static void main(String[] argv) throws RemoteException{
            
            ResourceBundle msg
            = ResourceBundle.getBundle("MessagesBundle");
            
            CardAccessor ca = null;
            
            try {
                
                // open and powerup the card
                ca = new ApduIOCardAccessor();
                
                // create a "filter" for RMI protocol
                JCRMIConnect jcRMI = new JCRMIConnect(ca);
                
                // select the Java Card applet
                if(argv.length == 0) {
                    jcRMI.selectApplet( RMI_DEMO_AID, JCRMIConnect.REF_WITH_CLASS_NAME );
                }
                else {
                    jcRMI.selectApplet( RMI_DEMO_AID, JCRMIConnect.REF_WITH_INTERFACE_NAMES );
                }
                
                // obtain the initial reference
                System.out.print(msg.getString("msg01")+" ");
                Purse myPurse = (Purse) jcRMI.getInitialReference();
                if(myPurse != null) {
                    System.out.println(msg.getString("msg02"));
                }
                else {
                    throw new Exception(msg.getString("msg03"));
                }
                
                // get the balance amount
                System.out.print(msg.getString("msg04"));
                short balance = myPurse.getBalance();
                System.out.println(msg.getString("msg05") + balance);  // prints 0
                
                System.out.println(msg.getString("msg06"));
                myPurse.credit((short)30);
                System.out.println(msg.getString("msg07"));
                myPurse.debit((short)15);
                
                System.out.print(msg.getString("msg08"));
                balance = myPurse.getBalance();
                System.out.println(msg.getString("msg05") + balance);  // prints 5
                
                System.out.println(msg.getString("msg09"));
                myPurse.setAccountNumber(new byte[]{5,4,3,2,1});  // expecting OK
                
                System.out.print(msg.getString("msg10"));
                byte[] acct_number = myPurse.getAccountNumber();
                printArray(acct_number);  // prints 5 4 3 2 1
                
                System.out.println(msg.getString("msg11"));
                myPurse.setAccountNumber(new byte[]{6,7,8,9,10,11});
                
            }
            catch(UserException e) {
                System.out.println(msg.getString("msg12") + e.toString());
                System.out.println(msg.getString("msg13") + Integer.toHexString(0x00FFFF & e.getReason()));
            }
            catch (Exception e){
                System.out.println(e);
            }
            finally {
                try{
                    if(ca!=null){
                        ca.closeCard();
                    }
                }
                catch (Exception ignore){
                    // System.out.println(ignore);
                }
            }
        }
        
        private static void printArray(byte[] arr) {
            for(int i=0; i<arr.length; ++i) System.out.print(" " + arr);
    System.out.println();
    }

    }
    [\code]

    in opencard.properties. You must set:

    OpenCard.terminals = de.cardcontact.opencard.terminal.jcwdpsim.JCWDPSimCardTerminalFactory|JCWDPSimulation|JCWDPSIM|0|localhost|9025
    

    See you soon,.
    Shane

Maybe you are looking for

  • Why gmail is always compact?

    I can't change the compact comfortable or uncomfortable in gmail. How can I change? Gmail tools do not work for a size change.

  • several parcels of a 1 d array

    Hello I'm taking a picture 1 d of 6 elements Acha a graph with several plots, one for each element... and I'mstuck.  Anyone know how I can do this? Thank you very much!

  • How to put icons on the screen clickable muliple

    Hello I need to put several clickable icons on the screen and at the bottom of the icons I have to put the text describe the function of the icon... for this I think field Bitmap, but I can't seem to understand how to display text (describe the funct

  • some

    Hi allI use under versionConnected to Oracle Database 11g Express Edition Release 11.2.0.2.0SQL > SELECT DEPTNODEPT 23. WHERE DEPTNO = SOME (SELECT FROM EMP DEPTNO);DEPTNO------102030Please tell me the use of some in the query.Thank you

  • Question to the first image in a clickable column/line

    HelloI hope someone can help. I created a page in lines and columns. All images are a hyperlink in each cell. For some reason, the first image of each line is not clickable, while the rest of them are. I've been in the Inspector, and I can't find the