Erreur de selection applet
Résolu
fala
-
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
voici le code pour le client:
et celui est pour la classe applet
voici le code pour le client:
package terminal.jc; import java.awt.event.MouseEvent; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.net.Socket; import java.util.Scanner; import com.sun.javacard.apduio.Apdu; import com.sun.javacard.apduio.CadT1Client; import com.sun.javacard.apduio.CadTransportException; public class Jf_Admin { final static byte Admin = (byte) 0xB0; public final static byte VERIFIE = (byte) 0x20; public final static byte GET_PATIENT_INFORMATION = (byte) 0x21; public static final byte GET_PATIENT_ADRESSE=0x32; public static final byte GET_PATIENT_NOM=0x33; public static final byte CHANGER_PIN=(byte)0x34; public final static byte LOCK_CARD = (byte) 0x22; public static final byte INS_SELECT= (byte) 0xA4; final static short SW_NO_ERROR = (short) 0x9000; public static final byte LFC_PRE_PERSO = (byte) 0x50; public static final byte LFC_USE = (byte) 0x51; public static final byte LFC_INVALID = (byte) 0x52; public static final byte LFC_DEAD = (byte) 0x53; private static final byte INS_GET_STATE = 0x05; private static final byte INS_CONFIGURE = 0x06; // LifeCycleState /** * @param args * @throws IOException * @throws CadTransportException */ // connection private CadT1Client cad; private Socket sckCarte; Apdu apdu; /** * Méthode permettant d'envoyer une commande APDU * * @param ins le type d'instruction * @param P1 parametre 1 * @param P2 parametre 2 * @param lc taille donnees * @param data donnees * @param le taille retour * @throws IOException * @throws CadTransportException */ private void send(byte ins, byte P1, byte P2, byte lc, byte[] data, byte le) throws IOException, CadTransportException { apdu = new Apdu(); apdu.command[Apdu.CLA] = Admin; apdu.command[Apdu.INS] = ins; apdu.command[Apdu.P1] = P1; apdu.command[Apdu.P2] = P2; apdu.setLc(lc); apdu.setLe(le); apdu.setDataIn(data); cad.exchangeApdu(apdu); } /** * Une fois connecté à la carte, que la commande powerUP a été envoyée et * que la carte est selectionnée, on peut passer au traitement. * * C'est le menu principal. * @throws CadTransportException * @throws IOException */ public void exec() throws CadTransportException, IOException { Scanner sc = new Scanner(System.in); String get; byte[] val; /* On verifie l'etat actuel de la carte */ send(Jf_Admin.INS_GET_STATE,(byte)0x00,(byte)0x00,(byte)0x00,new byte[]{},(byte)0x00); if (apdu.getStatus() != 0x9000) { System.err.println("Erreur Fatale"); return; } /* Personnalisation Carte */ if (apdu.dataOut[0] == Jf_Admin.LFC_PRE_PERSO) { System.out.println(); System.out.println("Application cliente Javacard"); System.out.println("-------- CONFIG ------------"); System.out.println(); System.out.print("Code Pin User : "); get = sc.next(); byte[] recpin = new byte[8]; for(int i = 0 ; i<4 ; i++) { recpin[i] = (byte) (get.getBytes()[i] - 48); } System.out.print("Code Pin : "); get = sc.next(); for(int i = 4 ; i<8 ; i++) { recpin[i] = (byte) (get.getBytes()[i-4] - 48); } send(Jf_Admin.INS_CONFIGURE,(byte)0x00,(byte)0x00,(byte)0x08,recpin,(byte)0x00); } if (apdu.getStatus() == 0x6700) { System.err.println("Les mots de passe doivent être de taille 4."); } else if (apdu.getStatus() != 0x9000) { System.err.println("Erreur Dans la configuration ->"+apdu.getStatus()); return; } else { System.out.println("CONFIG OK"); } if (apdu.getStatus() != 0x9000) { System.err.println("Erreur Fatale"); return; } /* Menu principal */ boolean fin = false; while (!fin) { send(Jf_Admin.INS_GET_STATE,(byte)0x00,(byte)0x00,(byte)0x00,new byte[]{},(byte)0x00); if (apdu.dataOut[0] == Jf_Admin.LFC_DEAD) { System.err.println("CARTE MORTE"); return; } if (apdu.dataOut[0] == Jf_Admin.LFC_INVALID){ System.err.println("CARTE BLOQUEE - Contacter votre Amin."); return; } if (apdu.dataOut[0] == Jf_Admin.LFC_USE) { System.out.println(); System.out.println("Application cliente Javacard"); System.out.println("----------------------------"); System.out.println(); System.out.println("1 - Interroger la Carte"); System.out.println("2 - "); System.out.println("3 - "); System.out.println("4 - "); System.out.println(); System.out.println("Votre choix ?"); int choix = System.in.read(); while (!(choix >= '1' && choix <= '4')) { choix = System.in.read(); } apdu = new Apdu(); apdu.command[Apdu.CLA] = Jf_Admin.Admin; apdu.command[Apdu.P1] = 0x00; apdu.command[Apdu.P2] = 0x00; switch (choix) { case '1': /* Le client verifie le nom */ send(Jf_Admin.GET_PATIENT_NOM,(byte)0x00,(byte)0x00,(byte)0x00,new byte[]{},(byte)0x00); if (apdu.getStatus() != 0x9000) { System.err.println("Une erreur est survenue"); } else { System.out.println("NOM: " + apdu.dataOut[1]); } break; case '2': /* Le client veut créditer la carte : * D'abord, on vérifie s'il a déjà renseigné son code pin (si ce n'est pas le cas, il devra le donner) * ensuite on crédite l'argent */ System.out.print("Valeur : "); val = new byte[]{sc.nextByte()}; send(Jf_Admin.GET_PATIENT_ADRESSE,(byte)0x00,(byte)0x00,(byte)0x01,val,(byte)0x00); if (apdu.getStatus() == 0x6301) { // Code pin pas renseigné System.out.print("Code Pin : "); get = sc.next(); if (get.length() != 4) { System.err.println("Code Pin invalide"); break; } byte[] recpin = new byte[4]; for(int i = 0 ; i<recpin.length ; i++) { recpin[i] = (byte) (get.getBytes()[i] - 48); } send(Jf_Admin.VERIFIE,(byte)0x00,(byte)0x00,(byte)0x04,recpin,(byte)0x00); if (apdu.getStatus() == 0x9000) { send(Jf_Admin.GET_PATIENT_INFORMATION,(byte)0x00,(byte)0x00,(byte)0x01,val,(byte)0x00); if (apdu.getStatus() == 0x9000) { System.out.println("OK"); } else { System.err.println("ERROR -> "+apdu.getStatus()); } } else { System.err.println(apdu.getStatus()+" --> BAD PIN"); } } else if (apdu.getStatus() == 0x9000) { System.out.println("OK"); } else { System.err.println("DONNEES INVALIDE"); } break; case '3': apdu.command[Apdu.INS] = Jf_Admin.CHANGER_PIN; System.out.print("Valeur : "); apdu.setLc(1); apdu.setDataIn(new byte[]{sc.nextByte()}); cad.exchangeApdu(apdu); if (apdu.getStatus() != SW_NO_ERROR) { System.out.println("Erreur : status word different de 0x9000 -> "+apdu.getStatus()); } else { System.out.println("OK"); } break; case '4': fin = true; break; } } } } private void connect() { try { sckCarte = new Socket("localhost", 9025); sckCarte.setTcpNoDelay(true); BufferedInputStream input = new BufferedInputStream(sckCarte.getInputStream()); BufferedOutputStream output = new BufferedOutputStream(sckCarte.getOutputStream()); cad = new CadT1Client(input, output); } catch (Exception e) { System.out.println("Erreur : impossible de se connecter a la Javacard"); return; } } private void select() { apdu = new Apdu(); apdu.command[Apdu.CLA] = 0x00; apdu.command[Apdu.INS] = (byte) 0xA4; apdu.command[Apdu.P1] = 0x04; apdu.command[Apdu.P2] = 0x00; byte[] adminAID = {(byte) 0xF2, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x00, (byte) 0x30, (byte) 0x00, (byte) 0x01}; apdu.setDataIn(adminAID); try { cad.exchangeApdu(apdu); } catch (IOException e) { e.printStackTrace(); } catch (CadTransportException e) { e.printStackTrace(); } if (apdu.getStatus() != SW_NO_ERROR) { System.out.println("Erreur lors de la sélection de l'applet -> "+apdu.getStatus()); System.exit(1); } } private void powerDown() { /* Mise hors tension de la carte */ try { cad.powerDown(); } catch (Exception e) { System.out.println("Erreur lors de l'envoi de la commande Powerdown"); return; } } private void powerUp() { /* Mise en tension de la carte */ try { cad.powerUp(); } catch (Exception e) { System.out.println("Erreur lors de l'envoi de la commande PowerUp"); return; } } public static void main(String[] args) throws IOException, CadTransportException { Jf_Admin pc = new Jf_Admin(); pc.connect(); pc.powerUp(); pc.select(); pc.exec(); pc.powerDown(); } private void InitComponents(){ } private void jbChangerPINMouseClicked(MouseEvent event){ } private void jbDeconnecterMouseClicked(MouseEvent event){ } private void jbViewDataMouseClicked(MouseEvent event){ } public Jf_Admin(){ } }
et celui est pour la classe applet
package tine.admin; import tine.medecin.CodeConstant; import tine.medecin.MedecinInterface; import tine.patient.PatientInterface; import tine.patient.information.PatientInformationInterface; import javacard.framework.AID; import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.OwnerPIN; public class Admin extends Applet { private final AID medecinAID= null; private final AID patientAID = null; private MedecinInterface medecinInterface; private final AID patientInformationAID = null; private PatientInformationInterface patientInformationInterface; private PatientInterface patientInterface; OwnerPIN pin; static byte[] workarray; public Admin(byte[] bArray, short bOffset, byte bLength) { } private void changer_pin(APDU apdu) { } private void get_patient_adresse(APDU apdu) { } private void get_patient_nom(APDU apdu) { } private void get_patient_information(APDU apdu) { } private void DebloquerPatient(APDU apdu) { } public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException { new Admin(bArray,bOffset,bLength).register(bArray,(short) (bOffset + 1),bArray[bOffset]); } public boolean select() { return true; } public void process(APDU apdu) throws ISOException { if(selectingApplet()){ return; } byte[] buf=apdu.getBuffer(); if((buf[ISO7816.OFFSET_CLA]==0) && (buf[ISO7816.OFFSET_INS]== (byte)(0x04))) return; if(buf[ISO7816.OFFSET_CLA]!= CodeConstant.CLA.GetionPatient_CLA) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); switch (buf[ISO7816.OFFSET_INS]) { case CodeConstant.INS.VERIFIE: this.verifie(apdu); break; case CodeConstant.INS.LOCK_CARD: break; case CodeConstant.INS.UNLOCK_CARD: this.DebloquerPatient(apdu); case CodeConstant.INS.GET_PATIENT_INFORMATION: this.get_patient_information(apdu); break; case CodeConstant.INS.GET_PATIENT_NOM : this.get_patient_nom(apdu); break; case CodeConstant.INS.GET_PATIENT_ADRESSE : this.get_patient_adresse(apdu); break; case CodeConstant.INS.CHANGER_PIN: this.changer_pin(apdu); break; default: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } } public void receiveAPDUBody(APDU apdu) throws ISOException { } public void resetPin(){ } private void verifie(APDU apdu) { } }
A voir également:
- Erreur de selection applet
- Erreur 0x80070643 - Accueil - Windows
- Erreur 0x80070643 Windows 10 : comment résoudre le problème de la mise à jour KB5001716 - Accueil - Windows
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
- Erreur 4201 france tv ✓ - Forum Réseaux sociaux
- J'aime par erreur facebook notification - Forum Facebook
La question est ici...
https://forums.commentcamarche.net/forum/affich-31810097-erreur-de-selection-d-un-applet