1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/**************************************************************************/
/* */
/* The Why platform for program certification */
/* */
/* Copyright (C) 2002-2011 */
/* */
/* Jean-Christophe FILLIATRE, CNRS & Univ. Paris-sud 11 */
/* Claude MARCHE, INRIA & Univ. Paris-sud 11 */
/* Yannick MOY, Univ. Paris-sud 11 */
/* Romain BARDOU, Univ. Paris-sud 11 */
/* */
/* Secondary contributors: */
/* */
/* Thierry HUBERT, Univ. Paris-sud 11 (former Caduceus front-end) */
/* Nicolas ROUSSET, Univ. Paris-sud 11 (on Jessie & Krakatoa) */
/* Ali AYAD, CNRS & CEA Saclay (floating-point support) */
/* Sylvie BOLDO, INRIA (floating-point support) */
/* Jean-Francois COUCHOT, INRIA (sort encodings, hyps pruning) */
/* Mehdi DOGGUY, Univ. Paris-sud 11 (Why GUI) */
/* */
/* This software is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License version 2.1, with the special exception on linking */
/* described in file LICENSE. */
/* */
/* This software is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* */
/**************************************************************************/
// JAVACARD: will ask regtests to use Java Card API for this program
/*****************************
Very basic Java Card Applet to check non-regression of basic Java Card support
thanks to Peter Trommler <trommler@site.uottawa.ca>
********************/
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.framework.OwnerPIN;
import javacard.security.*;
public class Card extends Applet {
//##################################################
//Instruction Variables
//##################################################
final static byte Card_Class = (byte)0x80;
final static byte Card_Ins_Pin= (byte)0x02;
final static byte Card_Ins_Auth=(byte)0x01;
final static byte Card_Ins_Write= (byte) 0x05;
final static byte Card_Ins_Del = (byte) 0x06;
final static byte Card_Ins_Read = (byte) 0x07;
//##################################################
//Other Parameters
//##################################################
final static byte Key_Length = (byte) 0x84;
final static short Data_Count = 10;
final static short Data_Len = 5;
final static byte Term_Function_Writer =(byte) 0xAA;
final static byte Term_Function_Reader = (byte)0x11;
/**
* Constructor for the Card.
*/
Card(){
// nothing to be done
}
//#####################################################
//Applet Card install
//####################################################
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new Card().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
//####################################################
//Here starts the good part.
//###################################################
public void process(APDU apdu) {
//When the applet is selected, the card will be initialised!
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
//Returns an error if the Class is wrong.
if(buf[ISO7816.OFFSET_CLA]!= Card_Class){
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch (buf[ISO7816.OFFSET_INS]) {
//Here is where the Signature from the terminal will be checked
//and also here is where will be decided to what functions
//the Terminal will have access to.
//Calls the Read Method
case Card_Ins_Read:
// for now just return OK SW1SW2=0x9000
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
return;
}
}
/*
Local Variables:
compile-command: "make SimpleApplet.why3ml"
End:
*/
|