Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
smartcards [Le 13/08/2011, 14:54] – [javax.smartcardio] SaiyanRiku | smartcards [Le 28/09/2019, 22:37] (Version actuelle) – [Liens externes] lien mort L'Africain | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | {{tag> | ||
+ | ---- | ||
+ | ====== Cartes à puce sous Ubuntu ====== | ||
+ | |||
+ | Les Cartes à puce (smart cards en anglais) sont des cartes intelligentes qui embarquent un microcontrôleur ou un microprocesseur. Le nombre d' | ||
+ | |||
+ | Les exemples les plus populaires de carte à puce sont les cartes de paiement, les cartes vitales, les cartes de transport ou encore les cartes de fidélité distribuées en grandes surfaces.\\ | ||
+ | L' | ||
+ | Cette page traite de deux type de cartes, les cartes PC/SC et les cartes de type [[# | ||
+ | |||
+ | [[wpfr> | ||
+ | La spécification de cette bibliothèque est faite par le PC/SC Workgroup, composé de grands fabricants de carte à puce ou d' | ||
+ | |||
+ | ===== Pré-requis ===== | ||
+ | |||
+ | * Disposer des [[: | ||
+ | * Disposer d'une connexion à Internet configurée et activée. | ||
+ | ===== PC/SC (Personal computer/ | ||
+ | |||
+ | ==== Installation==== | ||
+ | |||
+ | La gestion des lecteurs PC/SC n'est pas native sous Linux, mais peut être très facilement ajoutée par l' | ||
+ | |||
+ | ====Configuration==== | ||
+ | Par la suite, suivant votre lecteur, il vous faudra installer le pilote PC/SC correspondant à votre périphérique. Un certain nombre est déjà fourni dans les [[: | ||
+ | Vous obtiendrez une réponse qui vous permettra de savoir quel paquet installer : | ||
+ | libacr38u - PC/SC driver for the ACR38U smart card reader | ||
+ | libasedrive-serial - PC/SC driver for the Athena ASEDrive IIIe serial smart card reader | ||
+ | libasedrive-usb - PC/SC driver for the Athena ASEDrive IIIe USB smart card reader | ||
+ | libccid - PC/SC driver for USB CCID smart card readers | ||
+ | libgcr410 - PC/SC driver for GemPlus GCR410 serial SmartCard interface | ||
+ | libgempc410 - PC/SC driver for the GemPC 410, 412, 413 and 415 smart card readers | ||
+ | libgempc430 - PC/SC driver for the GemPC 430, 432, 435 smart card readers | ||
+ | pcsc-omnikey - PC/SC driver for Omnikey Cardman Smartcard readers (binary-only) | ||
+ | </ | ||
+ | Installez le paquet correspondant à votre type de carte. | ||
+ | Le paquet **libccid** installé par défaut avec **pcscd** est le pilote PC/SC pour le standard [[wpen> | ||
+ | |||
+ | ==== Utilisation ==== | ||
+ | |||
+ | Pour vérifier que tout fonctionne, vous pouvez utiliser les outils du paquet **[[apt> | ||
+ | * **pcsc_scan** : un petit script d' | ||
+ | * **gscriptor** : un petit logiciel avec interface graphique qui permet d' | ||
+ | |||
+ | |||
+ | ===== javax.smartcardio ===== | ||
+ | |||
+ | L'API Java Smart Card I/O défini par la JSR 268 est une API pour le langage Java permettant la communication avec les smart cards en utilisant l' | ||
+ | |||
+ | Un des ses atouts majeurs et que couplé à une applet Java, elle permet l' | ||
+ | |||
+ | Cette API a été introduit depuis Java 1.6 et est disponible et fonctionnelle avec les [[:java]] et [[: | ||
+ | |||
+ | ==== Exemple d' | ||
+ | |||
+ | <code java> | ||
+ | import javax.smartcardio.*; | ||
+ | import java.util.*; | ||
+ | |||
+ | public class TestSmartCardIO { | ||
+ | |||
+ | public static String toString(byte[] bytes) { | ||
+ | StringBuffer sbTmp = new StringBuffer(); | ||
+ | for(byte b : bytes){ | ||
+ | sbTmp.append(String.format(" | ||
+ | } | ||
+ | return sbTmp.toString(); | ||
+ | } | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | |||
+ | try { | ||
+ | // Show the list of available terminals | ||
+ | // On Windows see HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Calais\Readers | ||
+ | TerminalFactory factory = TerminalFactory.getDefault(); | ||
+ | List terminals = factory.terminals().list(); | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | |||
+ | // Get the first terminal in the list | ||
+ | CardTerminal terminal = (CardTerminal) terminals.get(0); | ||
+ | |||
+ | // Establish a connection with the card using | ||
+ | // " | ||
+ | Card card = terminal.connect(" | ||
+ | System.out.println(" | ||
+ | |||
+ | // Get ATR | ||
+ | byte[] baATR = card.getATR().getBytes(); | ||
+ | System.out.println(" | ||
+ | |||
+ | // Select Card Manager | ||
+ | // - Establish channel to exchange APDU | ||
+ | // - Send SELECT Command APDU | ||
+ | // - Show Response APDU | ||
+ | CardChannel channel = card.getBasicChannel(); | ||
+ | |||
+ | //SELECT Command | ||
+ | // See GlobalPlatform Card Specification (e.g. 2.2, section 11.9) | ||
+ | // CLA: 00 | ||
+ | // INS: A4 | ||
+ | // P1: 04 i.e. b3 is set to 1, means select by name | ||
+ | // P2: 00 i.e. first or only occurence | ||
+ | // Lc: 08 i.e. length of AID see below | ||
+ | // Data: A0 00 00 00 03 00 00 00 | ||
+ | // AID of the card manager, | ||
+ | // in the future should change to A0 00 00 01 51 00 00 | ||
+ | |||
+ | byte[] baCommandAPDU = {(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00}; | ||
+ | System.out.println(" | ||
+ | |||
+ | ResponseAPDU r = channel.transmit(new CommandAPDU(baCommandAPDU)); | ||
+ | System.out.println(" | ||
+ | |||
+ | // Disconnect | ||
+ | // true: reset the card after disconnecting card. | ||
+ | |||
+ | card.disconnect(true); | ||
+ | } catch(Exception ex) { | ||
+ | ex.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Utilisation avec Eclipse ==== | ||
+ | |||
+ | Généralement, | ||
+ | <note important> | ||
+ | |||
+ | Pour pallier ce problème, il faut lever les restrictions d' | ||
+ | * Clic droit sur votre projet puis **Properties** | ||
+ | * Dans la section **Java Build Path**, onglet **Librairies**, | ||
+ | * Dans la fenêtre, ajouter une règle avec le bouton **Add**. | ||
+ | * Dans **Resolution**, | ||
+ | * Enfin valider. | ||
+ | Désormais, vos classes sont accessibles. | ||
+ | |||
+ | ==== Problème de détection des cibles ==== | ||
+ | |||
+ | Si votre cible est correctement détectée avec pcsc_scan mais pas avec Java, ceci est du à un [[https:// | ||
+ | |||
+ | Par défaut, l'API Java cherche **libpcsclite.so** dans les dossiers /// | ||
+ | |||
+ | Pour y remédier, plusieurs solutions, soit vous copiez la bibliothèque au bon endroit : | ||
+ | * Sous architecture x86 : < | ||
+ | * Sous architecture amd64 : < | ||
+ | |||
+ | Soit vous définissez la librairie à l' | ||
+ | java -Dsun.security.smartcardio.library=/ | ||
+ | </ | ||
+ | Soit vous faites le travail dans le code en recherchant le fichier dans /lib dans le code : <code java> | ||
+ | File libPcscLite = new File("/ | ||
+ | if (libPcscLite.exists()) { | ||
+ | System.setProperty(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | SpringCard met à disposition des outils gratuit pour PC/SC sur son site. Notamment un [[http:// | ||
+ | |||
+ | ===== Liens externes ===== | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | // |