Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

store and access the certificates with different applets

JavaCard Applet Development Related Questions and Answers.
Brewling
Posts: 12
Joined: Wed Jul 13, 2016 2:14 am
Points :144
Contact:

store and access the certificates with different applets

Post by Brewling » Tue Aug 02, 2016 8:40 am

Hello!

I need to store the certificates within the admin applet and access with user applet. So I wonder if it is feasible to store the certificate on the java card with one applet and access it with the other one.

I appreciate any answer.

B

Sajaki
Posts: 11
Joined: Tue Jan 05, 2016 4:51 am
Points :106
Contact:

Re: store and access the certificates with different applets

Post by Sajaki » Wed Aug 03, 2016 3:11 am

Yes. you can do that with two applets. If your applets are in the same package, it will be easier. If the applets are in different packages, you need to pay attention to the applet firewall and use SOI.

Brewling
Posts: 12
Joined: Wed Jul 13, 2016 2:14 am
Points :144
Contact:

Re: store and access the certificates with different applets

Post by Brewling » Wed Aug 03, 2016 10:06 pm

Hi, Thank you very much for your help.

My applets are in the same package. Do you have any sample that I can take as a reference?

Sajaki
Posts: 11
Joined: Tue Jan 05, 2016 4:51 am
Points :106
Contact:

Re: store and access the certificates with different applets

Post by Sajaki » Thu Aug 04, 2016 5:28 am

For your reference,

User

Code: Select all

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class Client extends Applet {

    public static void install(byte[] bArray, short bOffset, byte bLength) {
   
        new Client().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

    public void process(APDU apdu) {
        // Good practice: Return 9000 on SELECT
        if (selectingApplet()) {
            return;
        }

        byte[] buf = apdu.getBuffer();
        switch (buf[ISO7816.OFFSET_INS]) {
            case (byte) 0x00:
                byte[] cert = Admin.getInstance().getCertificate();
                short certLen = Admin.getInstance().getCertLength();
                Util.arrayCopyNonAtomic(cert, (short) 0, buf, (short) 0, certLen);
                apdu.setOutgoingAndSend((short) 0, certLen);
                break;
            default:
                // good practice: If you don't know the INStruction, say so:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

}




Admin

Code: Select all

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.AppletEvent;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class Admin extends Applet implements AppletEvent {
    private final static short MAX_CERT_SIZE = 1024;
    private static Admin _instance;
    private byte[] certificate = new byte[MAX_CERT_SIZE];
    private short certLength;

    public static void install(byte[] bArray, short bOffset, byte bLength) {

        _instance = new Admin();
        _instance.register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

    public void process(APDU apdu) {
        // Good practice: Return 9000 on SELECT
        if (selectingApplet()) {
            return;
        }

        byte[] buf = apdu.getBuffer();

        apdu.setIncomingAndReceive();

        switch (buf[ISO7816.OFFSET_INS]) {
            case (byte) 0x00:
                certLength = buf[ISO7816.OFFSET_LC];
                Util.arrayCopy(buf, ISO7816.OFFSET_CDATA, certificate, (short) 0, certLength);
                break;
            default:
                // good practice: If you don't know the INStruction, say so:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

    public byte[] getCertificate() {
        return certificate;
    }

    /**
     * @return the certLength
     */
    public short getCertLength() {
        return certLength;
    }

    public static Admin getInstance() {
        return _instance;
    }

    public void uninstall() {
        _instance = null;
    }

}

Brewling
Posts: 12
Joined: Wed Jul 13, 2016 2:14 am
Points :144
Contact:

Re: store and access the certificates with different applets

Post by Brewling » Thu Aug 04, 2016 10:58 pm

Thanks a ton. Its very helpful to me.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 38 guests

JavaCard OS : Disclaimer