JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
store and access the certificates with different applets
store and access the certificates with different applets
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
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
Re: store and access the certificates with different applets
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.
Re: store and access the certificates with different applets
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?
My applets are in the same package. Do you have any sample that I can take as a reference?
Re: store and access the certificates with different applets
For your reference,
User
Admin
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;
}
}
Re: store and access the certificates with different applets
Thanks a ton. Its very helpful to me.
Who is online
Users browsing this forum: No registered users and 54 guests