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:29] – [PC/SC (Personal computer/Smart Card)] SaiyanRiku | smartcards [Le 21/03/2024, 17:42] (Version actuelle) – [javax.smartcardio] Fôte de Gramère Jean-Dom | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Smart cards sous Linux ====== | + | {{tag> |
| + | ---- | ||
| - | ===== Présentation | + | ====== Cartes à puce sous Ubuntu ====== |
| - | Les Smart cards (carte | + | Les Cartes |
| - | Les exemples les plus populaire | + | Les exemples les plus populaires |
| + | L' | ||
| + | Cette page traite de deux type de cartes, les cartes PC/SC et les cartes de type [[# | ||
| - | ===== Interface | + | [[wpfr> |
| + | La spécification de cette bibliothèque est faite par le PC/SC Workgroup, composé de grands fabricants de carte à puce ou d' | ||
| - | L'utilisation | + | ===== Pré-requis ===== |
| + | |||
| + | * Disposer des [[: | ||
| + | * Disposer | ||
| + | ===== PC/SC (Personal computer/Smart Card) ===== | ||
| - | ==== PC/SC (Personal computer/ | + | ==== Installation==== |
| - | Personal computer/ | + | La gestion des lecteurs |
| - | La spécification de cette bibliothèque | + | |
| - | === Installation | + | ====Configuration==== |
| - | + | Par la suite, suivant votre lecteur, il vous faudra installer le pilote | |
| - | La gestion des lecteurs PC/SC n'est pas natif sous Linux, mais peut être très facilement ajouté par l' | + | Vous obtiendrez une réponse qui vous permettra de savoir quel paquet installer : |
| - | + | ||
| - | < | + | |
| - | sudo apt-get install pcscd libpcsclite1 | + | |
| - | </ | + | |
| - | + | ||
| - | Par la suite suivant votre lecteur, il vous faudra installer le driver | + | |
| - | + | ||
| - | <code> | + | |
| - | $> apt-cache search "PC/SC driver" | + | |
| libacr38u - PC/SC driver for the ACR38U smart card reader | 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-serial - PC/SC driver for the Athena ASEDrive IIIe serial smart card reader | ||
| Ligne 37: | Ligne 35: | ||
| pcsc-omnikey - PC/SC driver for Omnikey Cardman Smartcard readers (binary-only) | 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> | ||
| - | Le paquet **libccid** installé par défaut avec **pcscd** est le driver PC/SC pour le standard CCID. Il permet la reconnaissance d'un grand nombre de lecteurs génériques basés sur ce standard. | + | ==== Utilisation ==== |
| - | === Test === | + | 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' | ||
| - | Pour vérifier que tout fonctionne, vous pouvez utiliser l' | ||
| - | < | + | ===== javax.smartcardio ===== |
| - | sudo apt-get install pcsc-tools | + | |
| - | pcsc_scan | + | 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 est que, couplée à 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' | ||
| + | |||
| + | < | ||
| + | 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(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
| - | Celui vous listera les lecteurs reconnu et les cartes détectés sur ceux-ci avec quelques informations supplémentaires. | + | ==== Utilisation avec Eclipse |
| - | ==== javax.smartcardio | + | |
| - | ===== Outils ===== | + | 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 ===== | ===== Liens externes ===== | ||
| + | * [[https:// | ||
| + | * [[http:// | ||
| + | |||
| + | ---- | ||
| - | [[http:// | + | // |
| - | [[http://www.springcard.com/ | + | |
