file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html



Similar documents
INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Homework/Program #5 Solutions

Graphical User Interfaces

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

Advanced Network Programming Lab using Java. Angelos Stavrou

CS 335 Lecture 06 Java Programming GUI and Swing

Programming with Java GUI components

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

Java Appletek II. Applet GUI

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Using A Frame for Output

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

Chapter 2 Introduction to Java programming


How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (

Essentials of the Java(TM) Programming Language, Part 1

Java Applet and Terminal Application for Financial transactions

Konzepte objektorientierter Programmierung

Fachbereich Informatik und Elektrotechnik Java Swing. Advanced Java. Java Swing Programming. Programming in Java, Helmut Dispert

An Overview of Java. overview-1

Tutorial Reference Manual. Java WireFusion 4.1

Analysis Of Source Lines Of Code(SLOC) Metric

JiST Graphical User Interface Event Viewer. Mark Fong

Extending Desktop Applications to the Web

Essentials of the Java Programming Language

Communicating with a Barco projector over network. Technical note

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

JIDE Action Framework Developer Guide

Course/Year W080/807 Expected Solution Subject: Software Development to Question No: 1

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

CS506 Web Design and Development Solved Online Quiz No. 01

CS108, Stanford Handout #33. Sockets

Lösningsförslag till tentamen

Creating a Simple, Multithreaded Chat System with Java

How Scala Improved Our Java

Karsten Lentzsch JGoodies SWING WITH STYLE

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Exercise 1: Set up the Environment

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

Swing. A Quick Tutorial on Programming Swing Applications

Mail User Agent Project

Skills and Topics for TeenCoder: Java Programming

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

ACR122 NFC Contactless Smart Card Reader

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal

Dev Articles 05/25/07 11:07:33

Java GUI Programming. Building the GUI for the Microsoft Windows Calculator Lecture 2. Des Traynor 2005

How to Convert an Application into an Applet.

JAVA Program For Processing SMS Messages

APPLICATION PROGRAMMING INTERFACE

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

public class demo1swing extends JFrame implements ActionListener{

SEEK project - Access to Secure Elements on Android. Frank Schäfer

The Design and Implementation of Multimedia Software

Installing Java (Windows) and Writing your First Program

Open Mobile API Test Specification for Transport API

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

The Basic Java Applet and JApplet

Introduction to the Java Programming Language

Bluetooth HID Profile

Reverse engineering smart cards

Tema: Encriptación por Transposición

WRITING DATA TO A BINARY FILE

Quick Installation. A Series of Intelligent Bar Code Reader with NeuroFuzzy Decoding. Quick Installation

How To Write A Program For The Web In Java (Java)

Change Log. 2 per vices corporation

.OR.AT.ATTORNEY.AUCTION.BARGAINS.BAYERN.BERLIN.BLACKFRIDAY.BOUTIQUE.BRUSSELS.BUILDERS

Intel Retail Client Manager Audience Analytics

GUI Event-Driven Programming

Java Program Coding Standards Programming for Information Technology

Crash Course in Java

Medientechnik. Übung MVC

Install Java Development Kit (JDK) 1.8

Hagenberg Linz Steyr Wels. API Application Programming Interface

CardWerk SmartCard API (Professional)

AN1754 APPLICATION NOTE

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Barcode Reader Connection Guide (COGNEX SLMP Connection)

OpenCard Framework 1.2 Programmer s Guide

GUI Components: Part 2

Programming with the Dev C++ IDE

RVS Seminar Deployment and Performance Analysis of JavaCards in a Heterogenous Environment. Carolin Latze University of Berne

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Smart Card Application Development Using the Java Card Technology

Interoperability Specification for ICCs and Personal Computer Systems

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

11. Applets, normal window applications, packaging and sharing your work

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Continuous Integration Part 2

Computing Concepts with Java Essentials

How to develop your own app

Topic 11 Scanner object, conditional execution

Transcription:

file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 1 von 5 ScanCmds.java ------------------------------------------------------------------------------- ScanCmds Demontration of scanning the supported commands of a smart card using the OCF 1.2 with PC/SC to transmit the data? file: ScanCmds.java uses: ICC.java This program uses the PassThruCardService from OCF opencard.opt.util package. Additional informations and reference implementation: www.opencard.org. Testet with Towitoko Chipdrive micro on USB port and the appropriate PC/SC driv from Towitoko on Windows 98. Testet with Omnikey CardMan Dongle 6020 on USB po and the appropriate PC/SC drivers from Omnikey on Windows 2000. Testet with JBuilder 6 and JDK 1.3.1. Uses OCFPCSC1.DLL, OCFPCSC1.DLL, pcsc-wrapper-src.jar, base-core.jar, base-opt from OCF 1.2 The content of the file "opencard.properties" must be changed to: OpenCard.terminals = com.ibm.opencard.terminal.pcsc10.pcsc10cardterminalfactor For understanding the mechanisms of OCF it is useful to look first into the SimpleOCF example. This program was tested with a GSM 11.11 Smart Card. The scan needs about 30 sec for scanning the available classes and instructions of a SIM. REMARKS: The PC/SC return code 0000045d will be thrown if a case 3 or case 4 command is scanned, because in this case the ICC expect some data after the APDU header. A scan of P1, P2 and P3 makes no sense because there is no unambiguou returncode if such a parameter is wrong or not supported. WARNING: The usage of this programm is at your own risk. The execution of this program could damage your smart card because of calling all available commands and there migth be commands actived which kill the card. Use only test cards to work with this programm. This source code is under GNU general public license (see www.opensource.org f Please send corrections and ideas for extensions to Wolfgang Rankl (www.wrankl Copyright 2003-2004 by Wolfgang Rankl, Munich 2. Sept. 2004 - V 5, rw: migrate to a Swing based GUI, add min/max value for ans instruction byte, add not scanned classes list, add Commands.java for decoding of smart card command add GPL statement,remark to 0000045d problems, division between user interface and smart card funct 4th published version 15. Dez. 2003 - V 4, rw: minor clarifications, add GPL statement remark to 0000045d problems, 3rd published version 23. Jan. 2003 - V 3, rw: simplifications byte to int conversion, test with new card reader, review of the source code, 2nd publishe 14. Oct. 2002 - V 2, rw: improved documentation, 1st published version 10. Oct. 2002 - V 1, rw: initial runnable version ------------------------------------------------------------------------------- package scpack; import java.awt.*; import java.awt.event.*; import java.text.*; import java.util.*; import javax.swing.*;

file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 2 von 5 public class ScanCmds extends JFrame implements ActionListener { static final boolean DEBUG = false; true: show the APDUs during scanning static final int FIRST_BYTE_ATR = 0; index to the first byte of the ATR static final int CLA_MIN = 0xA0; static final int CLA_MAX = 0xA9; static final int INS_MIN = 0x00; static final int INS_MAX = 0x90; minimum class byte value for scanning maximum class byte value for scanning minimum instruction byte value for scann maximum instruction byte value for scann static final byte[] NOTSCAN_INS = {(byte)0x01, (byte)0x03}; not scanned ins public static JTextArea ta = new JTextArea(15, 100); /** build the UI with all the components ScanCmds() { ----- create text area with scroll pane ta.settabsize(4); ta.setfont(new Font("Monospaced", 0, 12)); Courier, 12 point size ta.setbackground(new Color( 0, 0, 0)); black blue ta.setforeground(new Color(200, 255, 100)); yellowgreen getcontentpane().add(new JScrollPane(ta), BorderLayout.CENTER); ----- create panel with buttons JPanel buttonpanel = new JPanel(new GridLayout(20, 1)); JButton button1 = new JButton("Exit"); button1.addactionlistener(this); buttonpanel.add(button1); getcontentpane().add(buttonpanel, BorderLayout.EAST); } ScanCmds /** dispatcher which the main parts of the programm * @param event event for the pressed button public void actionperformed(actionevent event) { boolean loopbreak; byte[] atr; int result; long starttime, deltatime, noofwrites; showtext("\n-------------------------------------------\n"); String cmd = event.getactioncommand(); if (cmd.equals("exit")) { showtext("exit button pressed\n"); System.exit(0); } if } actionperformed /** show text in the text window * @param text text string to show on the display public static void showtext(string text) { ta.settext(ta.gettext() + text); } showtext public static String IntTo2CharHexString(int x) { converts a integer to the format "xx", x = hex digit String s; s = Integer.toHexString(x).toUpperCase(); if (s.length() == 1) s = "0" + s;

file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 3 von 5 } IntTo2CharHexString /** format a ATR * @param atr ATR byte string with the raw ATR data in hex * @return ATR string with the ATR in hex public static String formatatr(byte[] atr) { w = "ATR: "; for (n = 0; n < atr.length; n++) { x = (int) (0x000000FF & atr[n]); if (w.length()== 1) w = "0" + w; } for } formatatr /** format a command APDU * @param CmdAPDU byte string with the raw command APDU * @param LenCmdAPDU length of the raw command APDU bytw string * @return formated string with the command APDU public static String formatcmdapdu(byte[] CmdAPDU, int LenCmdAPDU) { s = "IFD->ICC: "; for (n = 0; n < LenCmdAPDU; n++) { x = (int) (0x000000FF & CmdAPDU[n]); if (w.length() == 1) w = "0" + w; } for } formatcmdapdu /** format a response APDU * @param RspAPDU byte string with the raw response APDU * @param LenRspAPDU length of the raw response APDU bytw string * @return formated string with the response APDU public static String formatrspapdu(byte[] RspAPDU, int LenRspAPDU) { s = "ICC->IFD: "; for (n = 0; n < LenRspAPDU; n++) { x = (int) (0x000000FF & RspAPDU[n]); if (w.length()== 1) w = "0" + w; } for } formatrspapdu

file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 4 von 5 public static void main(string [] args) { boolean scan; byte[] atr; int x, cla, ins, result; --- build the GUI and set the parameters ScanCmds scmds = new ScanCmds(); scmds.setlocation(0, 0); scmds.pack(); scmds.settitle("scan Smart Card Commands"); scmds.setvisible(true); showtext("start Program: ScanCmds\n\n"); ICC icc = new ICC(); try { showtext("activate smart card\n\n"); icc.start(); atr = icc.start(); if (atr[first_byte_atr]!= 0) { no error occur, a smart card is in the terminal, ATR received showtext ("ATR [hex]: " + formatatr(atr) + "\n"); this is the main loop for scanning all the commands within the presele showtext("\nstart CLA and INS scan\n"); for (cla = CLA_MIN; cla <= CLA_MAX; cla++) { try all classes ins = INS_MIN; showtext("test cla=" + IntTo2CharHexString(cla) + " "); showtext("ins=" + IntTo2CharHexString(ins) + "\n"); result = icc.sendcmd(cla, ins); set class and instruction if (result!= ICC.CLA_NOT_FOUND) { found a supported class try now the instructions range with this c showtext("\t\t\t\t\tfound cla=" + IntTo2CharHexString(cla) + "\n"); for (ins = INS_MIN; ins <= INS_MAX; ins++) { scan = true; for (x = 0; x < NOTSCAN_INS.length; x++) { if (NOTSCAN_INS[x] == ins) scan = false; } for if (scan == true) { showtext("test cla=" + IntTo2CharHexString(cla) + " "); showtext("ins=" + IntTo2CharHexString(ins) + "\n"); result = icc.sendcmd(cla, ins); set class and instruction if (result == ICC.INS_FOUND) { found a supported instruction showtext("\t\t\t\t\t\t\tfound ins=" + IntTo2CharHexString(ins) showtext(commands.decodecmd(cla, ins) + "\n"); } if INS found } if scan } for INS loop } if CLA found } for CLA loop showtext("\ndeactivate smart card\n"); icc.stop(); } if } try catch (Exception except) { showtext("\n\ncaught exception '" + except.getclass() + "' - " + except. } catch } main } class -------------------------------------------------------------------------------

file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 5 von 5 ScanCmds.java