Register   Login   About   Study   Enterprise   Share
Internet / AI Technology University (ITU/AITU)
Fast Login - available after registration







|

Top Links: >> 80. Technology >> 10. Java Extensions >> 10.1. Java Card >> 10.1.4. Writing VirtualCurrency JavaCard Applet
Current Topic: 10.1.4.1. VirtualCurrency Applet Standard Methods
You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
VirtualCurrency Applet Standard Methods
The VirtualCurrency private constructor creates the ownerPin object and calls the update() method on the object. Installation parameters passed to the update() method will initialize the PIN value. The last thing the constructor does is register the applet.

The source below includes the install(), select(), and deselect() methods. The static install() method receives installation parameters from the JCRE and passes these parameters to the private constructor applet described above. The applet remains in the suspended (inactive) state until it is explicitly selected by the JCRE.

When the JCRE receives a SELECT APDU command from the CAD, it calls the selected method on the applet. If any other applet was previously selected, the JCRE deselects that applet before selecting the new one.

/** The JCRE calls the install() method with installation parameters
* The install() method calls the private constructor and
* passes the parameters to the constructor
*/
public static void install(byte [] byteArray, short byteOffset, byte byteLength) {
new VirtualCurrency(byteArray, byteOffset, byteLength);
}

/** The applet will remain in the suspended (not active) state
* till it will be explicitly selected by the JCRE.
* The JCRE receives a SELECT APDU command from the CAD and
* calls the select method on the applet.
* The select() method checks if the pin is not blocked.
* The select() method returns false or reject selection if the pin is blocked.
* Otherwise the select() method returns true.
*/
public boolean select() {
// check if PIN is blocked
if(ownerPin.getTriesRemaining() == 0) {
return false;
}
return true;
}

/** The JCRE calls the deselect() method when on the currently selected applet
* in the case the JCRE receives a SELECT APDU command with the different applet AID.
* The deselect() method resets the pin value.
* It could also perform any cleanup operation if necessary.
* Keep in mind that Java Card has no garbage collection services.
*/
public void deselect() {
ownerPin.reset();
}

The select() method checks if the security PIN can be identified. The select() method returns false or rejects the selection if the PIN is blocked. Otherwise, the select() method returns true.

The JCRE calls the deselect() method on the currently selected applet if it receives a SELECT APDU command with a different applet AID. The deselect() method in our example just resets the PIN value. It may also perform any other cleanup operation, if necessary. Keep in mind that the JavaCard has no garbage collection services.
The next source extract shows the process() method of the VirtualCurrency applet, which handles operations on the applet data. The JCRE calls the process() method after the applet has been selected.

The JCRE passes all APDU commands (starting with the SELECT APDU command) to the process() method. The process() method retrieves a command and related data from the APDU byte array, calls a proper processing method, generates and sends a response back to the JCRE, and so on.

/**
* The JCRE calls the process() method after the applet has been selected.
* The JCRE passes all APDU commands (starting with the SELECT APDU command) to the process() method.
* The process() method retrieves a command and related data from the APDU byte array,
* calls a proper processing method, generates and sends response back to the JCRE, etc.
*
* The process() method reads the APDU data into a byteArray and
* starts with verification that the command is not SELECT and
* the APDU packets targets this (not another) applet.
* If this verification is successful the method continues with analysis of the command byte.
* In the switch statement (inside the process() method) the applet calls
* one of six operation-methods, according to the command in the APDU packet,
* and returns control to the JCRE.
* @param apdu
*/
public void process(APDU apdu) {
// read apdu in the byteArray
byte[] byteArray = apdu.getBuffer();

// The SELECT APDU command will also come to the process method in the APDU
// The process method does nothing on the SELECT command
if (byteArray[ISO7816.OFFSET_CLA] == SELECT_APDU_COMMAND) {
return;
}

// check CLA byte should match the applet code
if (byteArray[ISO7816.OFFSET_CLA] != VirtualCurrency_CLA) {
return; // or throws javacard.framework.ISOException
}

// check access authentication
if (! ownerPin.isValidated() ) {
ISOException.thorwIt (SW_PIN_VERIFICATION_REQUIRED);
}

// check requested service
switch (byteArray[ISO7816.OFFSET_INS]) {
case CHECK_PIN: checkPIN(apdu);
return;

case GET_ALL_GROUP_PRIVILEGES: getAllGroupPrivileges(apdu);
return;

case GET_GROUP_ROLES: getGroupRoles(apdu);
return;

case SET_GROUP_ROLES: setGroupRoles(apdu);
return;

case GET_VIRTUAL_SCORE: getVirtualScore(apdu);
return;

case ADD_SCORE: addScore(apdu);
return;

case SUBTRACT_SCORE: subtractScore(apdu);
return;

case GET_IDENTITY: getIdentity(apdu);
return;

default: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
} // end of proccess method

Was it clear so far?

In our example, the process() method reads the APDU data into a buffer and starts with several verifications. The method checks if the current command is not the SELECT_APDU command, which also comes to the process() method. Then, the process() method checks the CLA byte to verify that the APDU packets target this and not another applet.

Then, if previous verifications were successful, the applet can start processing. It is a good idea to start with yet another check. This time, we check access authentication using the OwnerPin method isValidated(). The applet would throw an ISOException if there were an access problem.

The process() method continues with its analysis of the command byte of the APDU. In the switch statement inside the process() method, the applet calls one of six operation methods, according to the command in the APDU packet, and returns control to the JCRE.

| Check Your Progress | Propose QnA | Have a question or comments for open discussion?
Comments
2016-01-06_13:05 by Michael Koren
Hello, Kristina! Our hospital is using Glucostabilizer software for insulin drips with the good results, but for meals we are also relying on supplementing the drip with SQ meal boluses. Mikhail Koren dr.koren@yahoo.com
<br/>    /** The JCRE calls the install() method with installation parameters
<br/>     * The install() method calls the private constructor and 
<br/>     * passes the parameters to the constructor
<br/>     */
<br/>    public static void install(byte [] byteArray, short byteOffset, byte byteLength) {
<br/>        new VirtualCurrency(byteArray, byteOffset, byteLength);
<br/>    }
<br/>
<br/>    /** The applet will remain in the suspended (not active) state 
<br/>     * till it will be explicitly selected by the JCRE. 
<br/>     * The JCRE receives a SELECT APDU command from the CAD and 
<br/>     * calls the select method on the applet. 
<br/>     * The select() method checks if the pin is not blocked. 
<br/>     * The select() method returns false or reject selection if the pin is blocked. 
<br/>     * Otherwise the select() method returns true.
<br/>     */
<br/>    public boolean select() {
<br/>        // check if PIN is blocked
<br/>        if(ownerPin.getTriesRemaining() == 0) {
<br/>            return false;
<br/>        }
<br/>        return true;
<br/>    }
<br/>
<br/>    /** The JCRE calls the deselect() method when on the currently selected applet 
<br/>     * in the case the JCRE receives a SELECT APDU command with the different applet AID. 
<br/>     * The deselect() method resets the pin value. 
<br/>     * It could also perform any cleanup operation if necessary. 
<br/>     * Keep in mind that Java Card has no garbage collection services. 
<br/>     */
<br/>    public void deselect() {
<br/>        ownerPin.reset();
<br/>    }
<br/>

The select() method checks if the security PIN can be identified. The select() method returns false or rejects the selection if the PIN is blocked. Otherwise, the select() method returns true.

The JCRE calls the deselect() method on the currently selected applet if it receives a SELECT APDU command with a different applet AID. The deselect() method in our example just resets the PIN value. It may also perform any other cleanup operation, if necessary. Keep in mind that the JavaCard has no garbage collection services.
The next source extract shows the process() method of the VirtualCurrency applet, which handles operations on the applet data. The JCRE calls the process() method after the applet has been selected.

The JCRE passes all APDU commands (starting with the SELECT APDU command) to the process() method. The process() method retrieves a command and related data from the APDU byte array, calls a proper processing method, generates and sends a response back to the JCRE, and so on.
<br/>    /**
<br/>     * The JCRE calls the process() method after the applet has been selected. 
<br/>     * The JCRE passes all APDU commands (starting with the SELECT APDU command) to the process() method. 
<br/>     * The process() method retrieves a command and related data from the APDU byte array, 
<br/>     * calls a proper processing method, generates and sends response back to the JCRE, etc. 
<br/>     *
<br/>     * The process() method reads the APDU data into a byteArray and 
<br/>     * starts with verification that the command is not SELECT and 
<br/>     * the APDU packets targets this (not another) applet. 
<br/>     * If this verification is successful the method continues with analysis of the command byte. 
<br/>     * In the switch statement (inside the process() method) the applet calls 
<br/>     * one of six operation-methods, according to the command in the APDU packet, 
<br/>     * and returns control to the JCRE. 
<br/>     * @param apdu
<br/>     */
<br/>    public void process(APDU apdu) {
<br/>        // read apdu in the byteArray 
<br/>        byte[] byteArray = apdu.getBuffer();
<br/>    
<br/>        // The SELECT APDU command will also come to the process method in the APDU
<br/>        // The process method does nothing on the SELECT command
<br/>        if (byteArray[ISO7816.OFFSET_CLA] == SELECT_APDU_COMMAND) {
<br/>            return;
<br/>        }
<br/>    
<br/>        // check CLA byte should match the applet code 
<br/>        if (byteArray[ISO7816.OFFSET_CLA] != VirtualCurrency_CLA) {
<br/>            return; // or throws javacard.framework.ISOException
<br/>        }
<br/>
<br/>        // check access authentication
<br/>        if (! ownerPin.isValidated() ) {
<br/>           ISOException.thorwIt (SW_PIN_VERIFICATION_REQUIRED);
<br/>        }
<br/>
<br/>        // check requested service
<br/>        switch (byteArray[ISO7816.OFFSET_INS]) {
<br/>            case CHECK_PIN: checkPIN(apdu);
<br/>            return;
<br/>
<br/>            case GET_ALL_GROUP_PRIVILEGES: getAllGroupPrivileges(apdu);
<br/>            return;
<br/>
<br/>            case GET_GROUP_ROLES: getGroupRoles(apdu);
<br/>            return;
<br/>
<br/>            case SET_GROUP_ROLES: setGroupRoles(apdu);
<br/>            return;
<br/>
<br/>            case GET_VIRTUAL_SCORE: getVirtualScore(apdu);
<br/>            return;
<br/>
<br/>            case ADD_SCORE: addScore(apdu);
<br/>            return;
<br/>
<br/>            case SUBTRACT_SCORE: subtractScore(apdu);
<br/>            return;
<br/>
<br/>            case GET_IDENTITY: getIdentity(apdu);
<br/>            return;
<br/>
<br/>            default: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
<br/>        }
<br/>     } // end of proccess method
<br/>    
<br/>






Was it clear so far?


In our example, the process() method reads the APDU data into a buffer and starts with several verifications. The method checks if the current command is not the SELECT_APDU command, which also comes to the process() method. Then, the process() method checks the CLA byte to verify that the APDU packets target this and not another applet.

Then, if previous verifications were successful, the applet can start processing. It is a good idea to start with yet another check. This time, we check access authentication using the OwnerPin method isValidated(). The applet would throw an ISOException if there were an access problem.

The process() method continues with its analysis of the command byte of the APDU. In the switch statement inside the process() method, the applet calls one of six operation methods, according to the command in the APDU packet, and returns control to the JCRE.


| Check Your Progress | Propose QnA | Have a question or comments for open discussion?

Comments

2016-01-06_13:05 by Michael Koren

Hello, Kristina!

Our hospital is using Glucostabilizer software for insulin drips with the good results, but for meals we are also relying on supplementing the drip with SQ meal boluses.

Mikhail Koren
dr.koren@yahoo.com


Have a suggestion? - shoot an email
Looking for something special? - Talk to me
Read: IT of the future: AI and Semantic Cloud Architecture | Fixing Education
Do you want to move from theory to practice and become a magician? Learn and work with us at Internet Technology University (ITU) - JavaSchool.com.

Technology that we offer and How this works: English | Spanish | Russian | French

Internet Technology University | JavaSchool.com | Copyrights © Since 1997 | All Rights Reserved
Patents: US10956676, US7032006, US7774751, US7966093, US8051026, US8863234
Including conversational semantic decision support systems (CSDS) and bringing us closer to The message from 2040
Privacy Policy