Programming

Smart Card에서 Card Number 읽어 오기

DragonTory 2020. 2. 19. 17:20
반응형

스마트카드 ( IC Smart Card ) 에서 카드 번호를 읽어 오는게 필요 해서 

카드 리더기도 사고 이것 저것 유틸리티 프로그램도 알아 보고 했는데 

정보도 많이 없고 스마트 카드 구조가 복잡 해서 계속 에러만 리턴 하고 

몇일이 지났다.

 

우선 스마트 카드와의 통신을 위한 명령어에 대해 정의 한 표준 문서를

살펴 볼 필요가 있다.

 

1. ISO Standard 파악

 

ISO-7816-4 : 1~9 Annex: A ~ F 까지 읽어 보자.  접촉형 스마트 카드에 대한 명령어 표준.

( 공식 문서는 돈 주고 사서 봐야 하는 것 같으니 패스 하고 여기 사이트를 참고 )

https://cardwerk.com/iso-7816-part-4

 

ISO 7816 part 4 smart card standard APDU commands ATR historical bytes

ISO/IEC 7816 part 4 smart card standard specifies the contents of messages, commands, and responses transmitted by APDU. ISO 7816 4 defines answer to reset ATR historical byte structure, interindustry APDU commands for interchange and access methods to fil

cardwerk.com

 

2.  실제 카드리더기에서 신용 카드 데이터를 살표 보자.

 

실제 신용 카드에서 데이터를 읽어 보여 주는 프로그램 찾기가 정말 힘들었다. 

다들 명령어만 입력 할 수 있는 정도 인데, 명령어를 알아야 사용 하던 하는데 계속 에러만 리턴 되었다.

난 그냥 카드 꼽아서 출력 되는 데이터를 한 번 보고 싶다고...

찾았다.

Smart Card Shell : scsh3 를 실행 하고 JavaScript 명령이나 js 파일을 로드 하는 JavaScript 인터프리터

https://www.openscdp.org/scsh3/index.html

 

Smart Card Shell 3

The Smart Card Shell 3 is an interactive development and scripting tool that allows easy access to smart cards on an APDU level as well as on a file system level. It can be used to develop and test smart card applications, in particular applications integr

www.openscdp.org

Smart Card Shell - Script Collection :  각 카드에 따른 예제 스크립트를 모아 놓고 설명을 보거나 및 다운로드 받을 수 있다.

scsh-scripts 폴더 안에 여러가지 스크립트 들이 들어 있다. 

예) EMV 카드를 접근 하기 위해서 ( Master / Visa / 등등 )

./scsh3 를 실행

-> load("emv/reademv.js"); 을 입력  : 샘플은 Master Card만 읽을 수 있는 듯.

위와 같이 하면 카드 종류, 소유자 이름, 카드 번호,  등등 정보를 볼 수 있다.

https://www.openscdp.org/scripts/tutorial/emv/index.html

 

EMV Tutorial

EMV Tutorial This EMV Tutorial will explain how to use the Smart Card Shell to explore an EMV chip card. Scripts used throughout the tutorial can be found in the emv directory of the script collection. 1. Basics Answer to Reset describes how card and termi

www.openscdp.org

 

ATR 값과 매칭 해 볼 수 있는 스마트 카드 리스트 

http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt

APDU 응답 상태 코드 리스트

https://www.eftlab.com/knowledge-base/complete-list-of-apdu-responses/

 

3. 신용 카드에 오고 가는 명령어와 데이터에 대한 설명이 필요 하다. 

 

위의 emv/reademv.js의 소스 및 리턴 값을 가지고 줄 단위 설명 하고

추가 적으로 여러가지 카드를 가지고 데이터를 읽어 올 수 있는 방법에 대해 설명 해준다. 

( 실제 패킷을 가지고 예를 들어 설명 해줌. )

https://sites.google.com/site/kriengten/smartcard

 

smartcard basic - kriengten

Resetting the cardTo perform any communication with the card, we will need to obtain a card object. A card object is created using the new Card() constructor. The constructor accepts a card reader name as parameter. The predefined variable _scsh3.reader co

sites.google.com

추가적으로 참고 사이트

https://www.intelisecure.com/smart-cards-a-brief-introduction/

 

Smart Cards – A Brief Introduction -

A smart card, chip card, or integrated circuit card (ICC) is any pocket-sized card with embedded integrated circuits.  Nowadays, smart cards are found everywhere, the SIM inside your mobile phone (GSM Smart card), your Bank cards (VISA & Mastercard), your

www.intelisecure.com

https://sites.google.com/site/kriengten/smartcard-reader

 

smartcard reader - kriengten

Installation Procedure:Step 1: Install pcsclite. The latest version of pcsclite is available at http://pcsclite.alioth.debian.org/orsudo apt-get update sudo apt-get install pcscdStep 2: Install libusb library. The latest version of libusb is available at h

sites.google.com

 

4. 실제 코딩에 필요 한 라이브러리

 

PCSC-lite Project : PCSC API 라이브러리 / 문서 / pcscd / pcsc-tools 관련 

https://pcsclite.apdu.fr/

 

 

PCSClite project

pcsc-lite should work but is not tested by me on these systems.

pcsclite.apdu.fr

PC/SC 라이브러리를 사용한 예제 코드

https://ludovicrousseau.blogspot.com/2010/04/pcsc-sample-in-c.html

 

PCSC sample in C

Here is the PCSC sample in C language I promised in PC/SC sample in different languages . C Source code #ifdef WIN32 #undef UNICODE ...

ludovicrousseau.blogspot.com

MS WinScard.h 관련 문서

https://docs.microsoft.com/en-us/windows/win32/api/winscard/

 

Winscard.h header - Win32 apps

01/11/2019 7 minutes to read In this article --> This header is used by Security and Identity. For more information, see: Functions Title Description GetOpenCardNameA The GetOpenCardName function displays the smart card "select card" dialog box. GetOpenCar

docs.microsoft.com

 

5. 기타 사이트 링크

 

ATR Data Parser :

http://www.ruimtools.com/atr.php

JavaCard OS :  Java Card 개발 통합 키트 부터 ATR / APDU Parser 다양한 정보를 얻을 수 있다.

https://javacardos.com/tools

GitHub에서 EMV 카드 처리에 관련된 툴 및 소스에 대한 모음집

https://github.com/topics/emv

Online ADPU / Response Parser 및 카드 별 각종 명령어 및 리턴 패킷을 볼 수 있고 TLV / Error State 리스트 등등 볼 수 있음.

( 단, 로그인 해야지만 Parser는 이용 가능 )

https://iso8583.info/tools/#labels

 

6. 관련 책 추천

Smart Card Programming - Ugo Chirico

: 2014년도 발행? 찾아 보면 pdf도 있는 듯. 알라딘에 책 있어서 약 45천원에 구매.

https://books.google.co.kr/books/about/Smart_Card_Programming.html?id=atjSoAEACAAJ&redir_esc=y

반응형