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

Tags: Java

Similar Questions

  • Error using APDU buffer for update methods (encrypt/decrypt/sign)

    Hi all

    I get an Exception system and the error code is 3 which is ILLEGAL_TRANSIENT. I pass data between two cmdlets using the APDU buffer. The 1st applet is the applet currently selected, which transmits the data to the applet 2nd to perform cryptographic operations. Encrypt/decrypt and sign all work well using init() & doFinal() when the data is small enough to be transformed into a go. The problem is when I try to use update() for larger data, I get the error ILLEGAL_TRANSIENT (I get this for a signing operation, but guess I'll get the same thing to encrypt/decrypt as well)

    The JCRE (section 6.1.5 of the 2.2.1 version) specification explains this error as an attempt to access a transitional type CLEAR_ON_DESELECT object when the current context is not the context of the currently selected applet. The APDU buffer comes from the applet 1, which is the applet currently selected, so I think that's why I see this error. However, it does not make sense to me that I am able to do all calls except the update using the APDU buffer - clearly the update call tries to use the buffer passed to somehow illegal - but that shouldn't be my problem, I thought I'd...

    Any help/comments would be appreciated.

    Swati

    In addition, when you create the instance of the encryption algorithm you set externalAccess true? This is necessary to access the applet properly through ITSELF.

    The doc of the API:

    externalAccess true indicates that the instance will be shared between applet multiple instances and that the instance of the encryption algorithm is also available (via a shared interface) when the owner of the instance of the encryption algorithm is not the currently selected applet. If true the implementation doesn't have to allocate internal data CLEAR_ON_DESELECT transitional space.

    See you soon,.
    Shane

  • How to make apdu.getBuffer () return buf which is greater than 133 bytes.

    {} public void process (APDU apdu)

    Byte [] buf = new byte [256];

    buf = apdu.getBuffer ();

    GOOD PRACTICE: BACK 9000 ON SELECT

    If (selectingApplet()) {}

    return;

    }

    apdu.setIncomingAndReceive ();

    switch (buf [ISO7816. {} OFFSET_INS])

    case (byte) 0 x 01:

    It is my method of process. I have a command APDU length 200 bytes I want the buffer to read and store in a local byte array. However, apdu.getBuffer () only entering the first 133 bytes of data.

    According to javadocs:

    "The APDU object is owned by the Java Card runtime environment. The APDU class maintains a byte array buffer which is used to transfer incoming APDU header and data bytes as well as outgoing data. The buffer length must be at least 133 bytes (5 bytes of header and 128 bytes of data). The Java Card runtime environment must reset the APDU buffer before each new message received from the CAD. »

    Given the length of the buffer is greater than 133 bytes, why he declined the remaining bytes?

    I use jCardSim on NetBeans IDE, version 2.2.2 of the java card.

    Also, could someone explain to me what exactly does apdu.setIncomingAndReceive ()? My code is able to build/run with and without it.

    Thank you

    Hello

    your code is not correct.

    never allow something outside the constructors and methods of customization that you know are called only once

    It will destroy your card as a 'new' allocates data to the eeprom.

    setIncomingAndReceive also toggle the protocol handler for receive mode (t = 1 and without contact, sends ACK in T = 0)

    then he makes the data available in the buffer

    the buffer is at LEAST 133 bytes, but it may be more

    If your command apdu contains more data, then these data are already in the buffer

    read the Lc offset to know the actual length.

    BTW, the comment of 'good practice' indicates that you use a code of example jcop as-is without understanding... I saw so many times!

    good luck, javacard is not as simple as java desktop... think "on-Board Unit 8-bit! You're not going malloc() in the main loop of arduino, right?

  • 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

  • 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
    
  • 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:
    (...)
    
  • global tables

    Hello

    As I understand it, there are two overall picture in the JCRE implementation. They are Baker to Install method and the APDU buffer.
    Do you know what their sizes? And because they are together, it is possible to store credentials in the class with this code.

    REF of Byte [] = Baker

    The JCRE rises exception if there is such a code in a program applet? And how to prevent the storage of references in class / instance variables as mention in JCRE spec (section 6.2.2)

    Thank you

    Hello

    As mentioned in my first post, they are usually the same buffer. You can test it in your code with apdu.getBuffer () .length.

    See you soon,.
    Shane

  • 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

  • SIO and Byte [] or [short]

    Hello

    Anyone know if it is possible to send a byte [] array to the shareable method? (I tried but my back applet for a table 'Byte' 6F00 and works when I get back 'short')
    I think that there is a protection to avoid attacks of malicious programs.

    Get more information about it?

    I work with JC 2.2.1 and TOP IM GX4 card.

    Kind regards
    Nico

    You can only change a global buffer during a call SELF. The global buffer, only that you have access is the APDU buffer. Your SELF must take a buffer as a parameter (depending on the API JCRE calls) that you give an offset to copy to as second parameter. Then return the length of the data copied to your SELF and on the copy of the call data in the buffer to the required offset.

    You are right that it is a security feature of the JCRE.

    See you soon,.
    Shane

  • import of biometrics and to implement

    Hello

    On my card there is a "org.javacardforum.javacard.biometry" package and I would use it. I downloaded the folder [http://www.javacardforum.org/Documents/Biometry/biometry.html].
    I found .exp, but there is no file .jar
    Do you know where I can find this .jar file? should I contact the manufacturer of the card?

    Thank you

    When you pass an object to a SELF must be accessible in other context applets. This means that the arrays of bytes must be passed using a global buffer (the APDU buffer).

    Copy the table to the APDU buffer and pass the buffer of the APDU to the SELF.

    See you soon,.
    Shane

  • exception on verfiying PIN

    I used this function for checking the PIN code. But today I'm trying to merge the two applets to finish my work. Check the PIN started cause problem.
    /*****************************************************************/
         private void verify(APDU apdu) 
         {
              byte[] buffer = null;
              byte byteRead = 0;
              try
              {
              buffer = apdu.getBuffer();
              
              // receive the PIN data for validation.
              byteRead = (byte)(apdu.setIncomingAndReceive());
     
              // check pin
              // the PIN data is read into the APDU buffer
              // starting at the offset ISO7816.OFFSET_CDATA
              // the PIN data length = byteRead
              if (pin.check(buffer, ISO7816.OFFSET_CDATA,byteRead) == false)
                   ISOException.throwIt(SW_VERIFICATION_FAILED);
              }
              catch( Exception exception)
              {
                   ISOException.throwIt(byteRead);
              }
              
         } // end of verify method
    /*****************************************************************/
    cm>  /send A006000005010203040500
     => A0 06 00 00 05 01 02 03 04 05 00                   ...........
     (670992 nsec)
     <= 6F 00                                              o.
    Status: No precise diagnosis
    When I put
    byteRead = (byte)(apdu.setIncomingAndReceive());
    outside the try exception unhandled it means
    the problem is with this statement. so please tell me what is the problem here?
    and start again his value that he gives
    0x0000
    . This means that incoming data have a problem.
    on call
    ISOException.throwIt(exception.getReason());
    the resutl is
    cm>  /send A006000005010203040500
     => A0 06 00 00 05 01 02 03 04 05 00                   ...........
     (454950 nsec)
     <= 00 01                                              ..
    Status: 0x0001
    Published by: Muhammad Umer on April 18, 2011 17:55

    Just to let you know it's because you're allowed to call setIncomingAndReceive() time in an APDU to indicate you read data. A card works in half-duplex mode, then you will need to indicate whether you are reading or writing :)

    The doc of the APDU API covers this.

    See you soon,.
    Shane

  • 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

  • Sending the command apdu with an array of bytes as CDATA

    Hello
    I learn the java card as part of my final year project. So far I think I can do the most basic things, but I stuck a special moment.

    I know that there are different manufacturers to create an apdu command object and a number of these manufacturers take an array of bytes as CDATA values.

    My problem is, how do I access this data table in the side of the card because apdu.getBuffer () returns an array of integers (bytes)? And what is actually on apdu.getBuffer () [ISO7816. (Instead of OFFSET_CDATA)] when you send the apdu command object using such constuctor?

    concerning

    Published by: 992194 on 6 March 2013 06:12

    992194 wrote:
    (..) I should have mentioned earlier that my card use jc 2.2.1 version, and from different places, I've read that this version does not support ExtendedLength facilities.

    Indeed.

    I also understand the semantics of apdu.getBuffer () [ISO7816. OFFSET_CDATA] is the first byte of the data command. My question is, these command data was initially provided as an array of bytes. Something like this:

    + new CommandAPDU(CLA, INS, P1, P2, DATA_ARRAY, Le) +.

    For example, when you call:

    ubyte [] buffer = apdu.getBuffer)

    So it means that the values of bytes inside the tableau_donnees argument automatically occupy locations + buffer [ISO7816. OFFSET_CDATA] + inside the buffer?

    Yes. The length would be (abstract) (buffer [ISO7816. (OFFSET_LC] & 0xFF) . Notice the & 0xFF is a must greater than 127 bytes.

    Or there is a mechanism to extract the table tableau_donnees itself?

    Laughing out loud

    In fact, in the interest of performance and portability in environments with low memory, usual coding style must pass buffer , an offset that and length; rather than take an object, which would require a copy. Welcome to the real world of Java Card.

  • Commit the buffer

    Hello world

    I want to test the effectiveness of the implementation of the headers in the buffer validation. To do this, I need a function that doesn't use JCSystem.beginTransaction () and JCSystem.commitTransaction () in JC API 222, fill a table. Here is the code I am using
    //Variables Initialization
    MaxCapacity = JCSystem.getMaxCommitCapacity();
    Arraysize = (short)(9/10*MaxCapacity);
    ExpectedUnusedCapacity = (short)(MaxCapacity - Arraysize);
    InBuffer = new byte[Arraysize];
              
    //Testing the efficiency of the commit buffer
    JCSystem.beginTransaction();
    random.generateData(InBuffer, (short)0,(short) InBuffer.length); //getting in trouble here since generateData function seems to use JCSystem.beginTransaction/commitTransaction
    UnusedCapacity = JCSystem.getUnusedCommitCapacity();
    JCSystem.commitTransaction();
    EfficiencyRatio = UnusedCapacity /ExpectedUnusedCapacity ;
    Such a function exists? If this isn't the case, you have an idea to test this application?

    See you soon,.
    Cyril

    You must wrap your code in a try/catch that you have an unhandled exception. With the help of arryCopy within a transaction is a valid test. You code is probably greater than the capacity of validation of transaction and throw a TransactionException. You should try to copy the less data.

    The following code works fine for me with a buffer of 1024 bytes and copies 16 bytes in there.

    case 0x01:
        JCSystem.beginTransaction();
        short space = JCSystem.getUnusedCommitCapacity();
        Util.arrayCopy(buf, (short) 0, buffer, (short) 0, inlen);
        space -= JCSystem.getUnusedCommitCapacity();
        JCSystem.commitTransaction();
    
        Util.setShort(buf, (short) 0, space);
        apdu.setOutgoingAndSend((short) 0, (short) 2);
        break;
    

    Output:

     => 00 01 00 00 10 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00
     <= 00 19 90 00
    

    See you soon,.
    Shane

  • 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

Maybe you are looking for

  • MacBook Pro 13 inch 2015 overheating new

    Hey everyone, I have this problem with my Macbook Pro. I had the Mac for 7 months, but since I bought it I had overheating problems. Data sheet: Intel Core i5 2.7 GHz 256 GB SSD 8 GB Ram Intel Iris 6100 GPU The problem is noticeable when you play (i.

  • No App tab

    I've just updated to FireFox 5.0 and I try the app tab. I followed the instructions on how to do, which was, click the arrow at the top right, then drag the tab pages to the empty spot. But... There was no empty space to drag them up. So now, I can't

  • Approval of apps for GoogleTV

    Exactly WHO approves applications to use with Google TV? (1) what is the review process?(3) what is eligible/ineligible apps for GTV?(4) WHERE is the complete list of applications to GTV? Maybe an Expert/Sony Rep could specify above.

  • HP Compaq dc5750 microtour: upgrading ram and video card

    Hello, can I change ddr2 ddr3 with the seizure of the same motherboardchange the video card with DDR3, now I have a saphire radeon hd 4350.Thank you

  • HP 8540w supports 8 GB RAM modules?

    I'm doing an upgrade of RAM on my HP EliteBook 8540w. This is the version with 2 memory slots. I want to use 16 GB total, so I wonder if it supports 8 GB modules?