smartcard 0.4.11 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +11 -16
- data/Rakefile +9 -16
- data/lib/smartcard.rb +11 -2
- data/lib/smartcard/iso/pcsc_transport.rb +22 -37
- data/lib/smartcard/pcsc/card.rb +281 -0
- data/lib/smartcard/pcsc/context.rb +160 -0
- data/lib/smartcard/pcsc/ffi_autogen.rb +327 -0
- data/lib/smartcard/pcsc/ffi_functions.rb +50 -0
- data/lib/smartcard/pcsc/ffi_lib.rb +38 -0
- data/lib/smartcard/pcsc/ffi_structs.rb +57 -0
- data/lib/smartcard/pcsc/pcsc_exception.rb +8 -3
- data/lib/smartcard/pcsc/reader_state_queries.rb +167 -0
- data/smartcard.gemspec +9 -7
- data/tasks/ffi_codegen.rb +145 -0
- data/test/pcsc/card_test.rb +68 -0
- data/test/pcsc/context_test.rb +64 -0
- data/test/pcsc/reader_state_queries_test.rb +72 -0
- metadata +42 -42
- data/ext/smartcard_pcsc/extconf.rb +0 -79
- data/ext/smartcard_pcsc/pcsc.h +0 -52
- data/ext/smartcard_pcsc/pcsc_card.c +0 -492
- data/ext/smartcard_pcsc/pcsc_constants.c +0 -195
- data/ext/smartcard_pcsc/pcsc_context.c +0 -290
- data/ext/smartcard_pcsc/pcsc_exception.c +0 -39
- data/ext/smartcard_pcsc/pcsc_io_request.c +0 -129
- data/ext/smartcard_pcsc/pcsc_main.c +0 -11
- data/ext/smartcard_pcsc/pcsc_multi_strings.c +0 -70
- data/ext/smartcard_pcsc/pcsc_namespace.c +0 -18
- data/ext/smartcard_pcsc/pcsc_reader_states.c +0 -331
- data/ext/smartcard_pcsc/pcsc_surrogate_reader.h +0 -207
- data/ext/smartcard_pcsc/pcsc_surrogate_wintypes.h +0 -63
- data/test/pcsc/containers_test.rb +0 -59
- data/test/pcsc/smoke_test.rb +0 -28
- data/tests/ts_pcsc_ext.rb +0 -76
@@ -1,207 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
|
3
|
-
*
|
4
|
-
* Copyright (C) 1999-2005
|
5
|
-
* David Corcoran <corcoran@linuxnet.com>
|
6
|
-
* Ludovic Rousseau <ludovic.rousseau@free.fr>
|
7
|
-
*
|
8
|
-
* $Id: reader.h.in 2572 2007-06-20 07:24:35Z rousseau $
|
9
|
-
*/
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @file
|
13
|
-
* @brief This keeps a list of defines shared between the driver and the application
|
14
|
-
*/
|
15
|
-
|
16
|
-
#ifndef __reader_h__
|
17
|
-
#define __reader_h__
|
18
|
-
|
19
|
-
/*
|
20
|
-
* Tags for requesting card and reader attributes
|
21
|
-
*/
|
22
|
-
|
23
|
-
#define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
|
24
|
-
|
25
|
-
#define SCARD_CLASS_VENDOR_INFO 1 /**< Vendor information definitions */
|
26
|
-
#define SCARD_CLASS_COMMUNICATIONS 2 /**< Communication definitions */
|
27
|
-
#define SCARD_CLASS_PROTOCOL 3 /**< Protocol definitions */
|
28
|
-
#define SCARD_CLASS_POWER_MGMT 4 /**< Power Management definitions */
|
29
|
-
#define SCARD_CLASS_SECURITY 5 /**< Security Assurance definitions */
|
30
|
-
#define SCARD_CLASS_MECHANICAL 6 /**< Mechanical characteristic definitions */
|
31
|
-
#define SCARD_CLASS_VENDOR_DEFINED 7 /**< Vendor specific definitions */
|
32
|
-
#define SCARD_CLASS_IFD_PROTOCOL 8 /**< Interface Device Protocol options */
|
33
|
-
#define SCARD_CLASS_ICC_STATE 9 /**< ICC State specific definitions */
|
34
|
-
#define SCARD_CLASS_SYSTEM 0x7fff /**< System-specific definitions */
|
35
|
-
|
36
|
-
#define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100)
|
37
|
-
#define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101)
|
38
|
-
#define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102)
|
39
|
-
#define SCARD_ATTR_VENDOR_IFD_SERIAL_NO SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103)
|
40
|
-
#define SCARD_ATTR_CHANNEL_ID SCARD_ATTR_VALUE(SCARD_CLASS_COMMUNICATIONS, 0x0110)
|
41
|
-
#define SCARD_ATTR_ASYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
|
42
|
-
#define SCARD_ATTR_DEFAULT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0121)
|
43
|
-
#define SCARD_ATTR_MAX_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0122)
|
44
|
-
#define SCARD_ATTR_DEFAULT_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0123)
|
45
|
-
#define SCARD_ATTR_MAX_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0124)
|
46
|
-
#define SCARD_ATTR_MAX_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0125)
|
47
|
-
#define SCARD_ATTR_SYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0126)
|
48
|
-
#define SCARD_ATTR_POWER_MGMT_SUPPORT SCARD_ATTR_VALUE(SCARD_CLASS_POWER_MGMT, 0x0131)
|
49
|
-
#define SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0140)
|
50
|
-
#define SCARD_ATTR_USER_AUTH_INPUT_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0142)
|
51
|
-
#define SCARD_ATTR_CHARACTERISTICS SCARD_ATTR_VALUE(SCARD_CLASS_MECHANICAL, 0x0150)
|
52
|
-
|
53
|
-
#define SCARD_ATTR_CURRENT_PROTOCOL_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0201)
|
54
|
-
#define SCARD_ATTR_CURRENT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0202)
|
55
|
-
#define SCARD_ATTR_CURRENT_F SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0203)
|
56
|
-
#define SCARD_ATTR_CURRENT_D SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0204)
|
57
|
-
#define SCARD_ATTR_CURRENT_N SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0205)
|
58
|
-
#define SCARD_ATTR_CURRENT_W SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0206)
|
59
|
-
#define SCARD_ATTR_CURRENT_IFSC SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0207)
|
60
|
-
#define SCARD_ATTR_CURRENT_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0208)
|
61
|
-
#define SCARD_ATTR_CURRENT_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0209)
|
62
|
-
#define SCARD_ATTR_CURRENT_CWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020a)
|
63
|
-
#define SCARD_ATTR_CURRENT_EBC_ENCODING SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020b)
|
64
|
-
#define SCARD_ATTR_EXTENDED_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020c)
|
65
|
-
|
66
|
-
#define SCARD_ATTR_ICC_PRESENCE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0300)
|
67
|
-
#define SCARD_ATTR_ICC_INTERFACE_STATUS SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0301)
|
68
|
-
#define SCARD_ATTR_CURRENT_IO_STATE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0302)
|
69
|
-
#define SCARD_ATTR_ATR_STRING SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303)
|
70
|
-
#define SCARD_ATTR_ICC_TYPE_PER_ATR SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304)
|
71
|
-
|
72
|
-
#define SCARD_ATTR_ESC_RESET SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA000)
|
73
|
-
#define SCARD_ATTR_ESC_CANCEL SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA003)
|
74
|
-
#define SCARD_ATTR_ESC_AUTHREQUEST SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA005)
|
75
|
-
#define SCARD_ATTR_MAXINPUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA007)
|
76
|
-
|
77
|
-
#define SCARD_ATTR_DEVICE_UNIT SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0001)
|
78
|
-
#define SCARD_ATTR_DEVICE_IN_USE SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0002)
|
79
|
-
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
|
80
|
-
#define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
|
81
|
-
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0005)
|
82
|
-
#define SCARD_ATTR_DEVICE_SYSTEM_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0006)
|
83
|
-
#define SCARD_ATTR_SUPRESS_T1_IFS_REQUEST SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0007)
|
84
|
-
|
85
|
-
#ifdef UNICODE
|
86
|
-
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
|
87
|
-
#define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_W
|
88
|
-
#else
|
89
|
-
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
|
90
|
-
#define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_A
|
91
|
-
#endif
|
92
|
-
|
93
|
-
/**
|
94
|
-
* Provide source compatibility on different platforms
|
95
|
-
*/
|
96
|
-
#define SCARD_CTL_CODE(code) (0x42000000 + (code))
|
97
|
-
|
98
|
-
/**
|
99
|
-
* TeleTrust Class 2 reader tags
|
100
|
-
*/
|
101
|
-
#define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
|
102
|
-
|
103
|
-
#define FEATURE_VERIFY_PIN_START 0x01 /**< OMNIKEY Proposal */
|
104
|
-
#define FEATURE_VERIFY_PIN_FINISH 0x02 /**< OMNIKEY Proposal */
|
105
|
-
#define FEATURE_MODIFY_PIN_START 0x03 /**< OMNIKEY Proposal */
|
106
|
-
#define FEATURE_MODIFY_PIN_FINISH 0x04 /**< OMNIKEY Proposal */
|
107
|
-
#define FEATURE_GET_KEY_PRESSED 0x05 /**< OMNIKEY Proposal */
|
108
|
-
#define FEATURE_VERIFY_PIN_DIRECT 0x06 /**< USB CCID PIN Verify */
|
109
|
-
#define FEATURE_MODIFY_PIN_DIRECT 0x07 /**< USB CCID PIN Modify */
|
110
|
-
#define FEATURE_MCT_READERDIRECT 0x08 /**< KOBIL Proposal */
|
111
|
-
#define FEATURE_MCT_UNIVERSAL 0x09 /**< KOBIL Proposal */
|
112
|
-
#define FEATURE_IFD_PIN_PROP 0x0A /**< Gemplus Proposal */
|
113
|
-
#define FEATURE_ABORT 0x0B /**< SCM Proposal */
|
114
|
-
|
115
|
-
/* structures used (but not defined) in PCSC Part 10 revision 2.01.02:
|
116
|
-
* "IFDs with Secure Pin Entry Capabilities" */
|
117
|
-
|
118
|
-
#include <inttypes.h>
|
119
|
-
|
120
|
-
/* Set structure elements aligment on bytes
|
121
|
-
* http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
|
122
|
-
#if defined(__APPLE__) | defined(sun)
|
123
|
-
#pragma pack(1)
|
124
|
-
#else
|
125
|
-
#pragma pack(push, 1)
|
126
|
-
#endif
|
127
|
-
|
128
|
-
/** the structure must be 6-bytes long */
|
129
|
-
typedef struct
|
130
|
-
{
|
131
|
-
uint8_t tag;
|
132
|
-
uint8_t length;
|
133
|
-
uint32_t value; /**< This value is always in BIG ENDIAN format as documented in PCSC v2 part 10 ch 2.2 page 2. You can use ntohl() for example */
|
134
|
-
} PCSC_TLV_STRUCTURE;
|
135
|
-
|
136
|
-
/** the wLangId and wPINMaxExtraDigit are 16-bits long so are subject to byte
|
137
|
-
* ordering */
|
138
|
-
#define HOST_TO_CCID_16(x) @host_to_ccid_16@
|
139
|
-
#define HOST_TO_CCID_32(x) @host_to_ccid_32@
|
140
|
-
|
141
|
-
/** structure used with \ref FEATURE_VERIFY_PIN_DIRECT */
|
142
|
-
typedef struct
|
143
|
-
{
|
144
|
-
uint8_t bTimerOut; /**< timeout is seconds (00 means use default timeout) */
|
145
|
-
uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
|
146
|
-
uint8_t bmFormatString; /**< formatting options */
|
147
|
-
uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
|
148
|
-
* bits 3-0 PIN block size in bytes after
|
149
|
-
* justification and formatting */
|
150
|
-
uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
|
151
|
-
* bit 4 set if system units are bytes, clear if
|
152
|
-
* system units are bits,
|
153
|
-
* bits 3-0 PIN length position in system units */
|
154
|
-
uint16_t wPINMaxExtraDigit; /**< 0xXXYY where XX is minimum PIN size in digits,
|
155
|
-
and YY is maximum PIN size in digits */
|
156
|
-
uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
|
157
|
-
* be considered complete */
|
158
|
-
uint8_t bNumberMessage; /**< Number of messages to display for PIN verification */
|
159
|
-
uint16_t wLangId; /**< Language for messages */
|
160
|
-
uint8_t bMsgIndex; /**< Message index (should be 00) */
|
161
|
-
uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
|
162
|
-
uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
|
163
|
-
uint8_t abData[1]; /**< Data to send to the ICC */
|
164
|
-
} PIN_VERIFY_STRUCTURE;
|
165
|
-
|
166
|
-
/** structure used with \ref FEATURE_MODIFY_PIN_DIRECT */
|
167
|
-
typedef struct
|
168
|
-
{
|
169
|
-
uint8_t bTimerOut; /**< timeout is seconds (00 means use default timeout) */
|
170
|
-
uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
|
171
|
-
uint8_t bmFormatString; /**< formatting options */
|
172
|
-
uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
|
173
|
-
* bits 3-0 PIN block size in bytes after
|
174
|
-
* justification and formatting */
|
175
|
-
uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
|
176
|
-
* bit 4 set if system units are bytes, clear if
|
177
|
-
* system units are bits,
|
178
|
-
* bits 3-0 PIN length position in system units */
|
179
|
-
uint8_t bInsertionOffsetOld; /**< Insertion position offset in bytes for
|
180
|
-
the current PIN */
|
181
|
-
uint8_t bInsertionOffsetNew; /**< Insertion position offset in bytes for
|
182
|
-
the new PIN */
|
183
|
-
uint16_t wPINMaxExtraDigit;
|
184
|
-
/**< 0xXXYY where XX is minimum PIN size in digits,
|
185
|
-
and YY is maximum PIN size in digits */
|
186
|
-
uint8_t bConfirmPIN; /**< Flags governing need for confirmation of new PIN */
|
187
|
-
uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
|
188
|
-
* be considered complete */
|
189
|
-
uint8_t bNumberMessage; /**< Number of messages to display for PIN verification*/
|
190
|
-
uint16_t wLangId; /**< Language for messages */
|
191
|
-
uint8_t bMsgIndex1; /**< index of 1st prompting message */
|
192
|
-
uint8_t bMsgIndex2; /**< index of 2d prompting message */
|
193
|
-
uint8_t bMsgIndex3; /**< index of 3d prompting message */
|
194
|
-
uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
|
195
|
-
uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
|
196
|
-
uint8_t abData[1]; /**< Data to send to the ICC */
|
197
|
-
} PIN_MODIFY_STRUCTURE;
|
198
|
-
|
199
|
-
/* restore default structure elements alignment */
|
200
|
-
#if defined(__APPLE__) | defined(sun)
|
201
|
-
#pragma pack()
|
202
|
-
#else
|
203
|
-
#pragma pack(pop)
|
204
|
-
#endif
|
205
|
-
|
206
|
-
#endif
|
207
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
|
3
|
-
*
|
4
|
-
* Copyright (C) 1999
|
5
|
-
* David Corcoran <corcoran@linuxnet.com>
|
6
|
-
*
|
7
|
-
* $Id: wintypes.h 2537 2007-05-22 15:02:26Z rousseau $
|
8
|
-
*/
|
9
|
-
|
10
|
-
/**
|
11
|
-
* @file
|
12
|
-
* @brief This keeps a list of Windows(R) types.
|
13
|
-
*/
|
14
|
-
|
15
|
-
#ifndef __wintypes_h__
|
16
|
-
#define __wintypes_h__
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
extern "C"
|
20
|
-
{
|
21
|
-
#endif
|
22
|
-
|
23
|
-
#if !defined(WIN32)
|
24
|
-
|
25
|
-
#ifndef BYTE
|
26
|
-
typedef unsigned char BYTE;
|
27
|
-
#endif
|
28
|
-
typedef unsigned char UCHAR;
|
29
|
-
typedef unsigned char *PUCHAR;
|
30
|
-
typedef unsigned short USHORT;
|
31
|
-
|
32
|
-
#ifndef __COREFOUNDATION_CFPLUGINCOM__
|
33
|
-
typedef unsigned long ULONG;
|
34
|
-
typedef void *LPVOID;
|
35
|
-
typedef short BOOL;
|
36
|
-
#endif
|
37
|
-
|
38
|
-
typedef unsigned long *PULONG;
|
39
|
-
typedef const void *LPCVOID;
|
40
|
-
typedef uint32_t DWORD;
|
41
|
-
typedef uint32_t *PDWORD;
|
42
|
-
typedef uint16_t WORD;
|
43
|
-
typedef long LONG;
|
44
|
-
typedef const char *LPCSTR;
|
45
|
-
typedef const BYTE *LPCBYTE;
|
46
|
-
typedef BYTE *LPBYTE;
|
47
|
-
typedef DWORD *LPDWORD;
|
48
|
-
typedef unsigned char *LPSTR;
|
49
|
-
|
50
|
-
/* these types were deprecated but still used by old drivers and
|
51
|
-
* applications. So just declare and use them. */
|
52
|
-
typedef LPSTR LPTSTR;
|
53
|
-
typedef LPCSTR LPCTSTR;
|
54
|
-
|
55
|
-
#else
|
56
|
-
#include <windows.h>
|
57
|
-
#endif
|
58
|
-
|
59
|
-
#ifdef __cplusplus
|
60
|
-
}
|
61
|
-
#endif
|
62
|
-
|
63
|
-
#endif
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# Author:: Victor Costan
|
2
|
-
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
3
|
-
# License:: MIT
|
4
|
-
|
5
|
-
require 'smartcard'
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
|
9
|
-
|
10
|
-
class ContainersTest < Test::Unit::TestCase
|
11
|
-
def setup
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
# tests the SmartCard::PCSC::ReaderStates container
|
20
|
-
def test_reader_states
|
21
|
-
reader_states = Smartcard::PCSC::ReaderStates.new(2)
|
22
|
-
reader_states.set_current_state_of!(1, Smartcard::PCSC::STATE_ATRMATCH)
|
23
|
-
reader_states.set_current_state_of!(0, Smartcard::PCSC::STATE_CHANGED)
|
24
|
-
reader_states.set_event_state_of!(0, Smartcard::PCSC::STATE_IGNORE)
|
25
|
-
reader_states.set_event_state_of!(1, Smartcard::PCSC::STATE_PRESENT)
|
26
|
-
reader_states.set_atr_of!(1, "Ruby\0rocks!")
|
27
|
-
reader_states.set_atr_of!(0, "grreat success")
|
28
|
-
reader_states.set_reader_name_of!(0, "PC/SC Reader 0")
|
29
|
-
reader_states.set_reader_name_of!(1, "CCID Reader 1")
|
30
|
-
|
31
|
-
assert_equal Smartcard::PCSC::STATE_ATRMATCH, reader_states.current_state_of(1), 'ReaderStates.set_current_state_of! / current_state_of mismatch'
|
32
|
-
assert_equal Smartcard::PCSC::STATE_CHANGED, reader_states.current_state_of(0), 'ReaderStates.set_current_state_of! / current_state_of mismatch'
|
33
|
-
|
34
|
-
assert_equal Smartcard::PCSC::STATE_IGNORE, reader_states.event_state_of(0), 'ReaderStates.set_event_state_of! / event_state_of mismatch'
|
35
|
-
assert_equal Smartcard::PCSC::STATE_PRESENT, reader_states.event_state_of(1), 'ReaderStates.set_event_state_of! / event_state_of mismatch'
|
36
|
-
|
37
|
-
assert_equal "Ruby\0rocks!", reader_states.atr_of(1), 'ReaderStates.set_atr_of! / atr_of mismatch'
|
38
|
-
assert_equal "grreat success", reader_states.atr_of(0), 'ReaderStates.set_atr_of! / atr_of mismatch'
|
39
|
-
|
40
|
-
assert_equal "PC/SC Reader 0", reader_states.reader_name_of(0)
|
41
|
-
assert_equal "CCID Reader 1", reader_states.reader_name_of(1)
|
42
|
-
|
43
|
-
[[5, IndexError], [2, IndexError], [nil, TypeError]].each do |bad_index_test|
|
44
|
-
assert_raise bad_index_test[1] do
|
45
|
-
reader_states.current_state_of(bad_index_test[0])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# tests the SmartCard::PCSC::IoRequest container
|
51
|
-
def test_io_request
|
52
|
-
io_request = Smartcard::PCSC::IoRequest.new
|
53
|
-
[Smartcard::PCSC::PROTOCOL_T0, Smartcard::PCSC::PROTOCOL_T1, Smartcard::PCSC::PROTOCOL_RAW].each do |t_protocol|
|
54
|
-
io_request.protocol = t_protocol
|
55
|
-
r_protocol = io_request.protocol
|
56
|
-
assert_equal r_protocol, t_protocol, 'IoRequest.protocol= / protocol mismatch'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/test/pcsc/smoke_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# Author:: Victor Costan
|
2
|
-
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
3
|
-
# License:: MIT
|
4
|
-
|
5
|
-
require 'smartcard'
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
|
9
|
-
|
10
|
-
class SmokeTest < Test::Unit::TestCase
|
11
|
-
def setup
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
end
|
16
|
-
|
17
|
-
# smoke-test to ensure that the extension loads and can call into the PC/SC library
|
18
|
-
def test_smoke
|
19
|
-
context = Smartcard::PCSC::Context.new(Smartcard::PCSC::SCOPE_SYSTEM)
|
20
|
-
|
21
|
-
reader_groups = context.list_reader_groups
|
22
|
-
readers1 = context.list_readers reader_groups
|
23
|
-
readers2 = context.list_readers reader_groups.first
|
24
|
-
readers3 = context.list_readers nil
|
25
|
-
|
26
|
-
context.release
|
27
|
-
end
|
28
|
-
end
|
data/tests/ts_pcsc_ext.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# Author:: Victor Costan
|
2
|
-
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
3
|
-
# License:: MIT
|
4
|
-
|
5
|
-
require 'smartcard'
|
6
|
-
require 'pp'
|
7
|
-
|
8
|
-
context = Smartcard::PCSC::Context.new(Smartcard::PCSC::SCOPE_SYSTEM)
|
9
|
-
|
10
|
-
reader_groups = context.list_reader_groups
|
11
|
-
pp reader_groups
|
12
|
-
readers1 = context.list_readers reader_groups
|
13
|
-
pp readers1
|
14
|
-
readers2 = context.list_readers reader_groups.first
|
15
|
-
pp readers2
|
16
|
-
readers3 = context.list_readers nil
|
17
|
-
pp readers3
|
18
|
-
|
19
|
-
context.cancel
|
20
|
-
|
21
|
-
reader0 = readers3.first
|
22
|
-
puts "Waiting for card in reader: #{reader0}\n"
|
23
|
-
reader_states = Smartcard::PCSC::ReaderStates.new(1)
|
24
|
-
reader_states.set_reader_name_of!(0, reader0)
|
25
|
-
reader_states.set_current_state_of!(0, Smartcard::PCSC::STATE_UNKNOWN)
|
26
|
-
while (reader_states.event_state_of(0) & Smartcard::PCSC::STATE_PRESENT) == 0 do
|
27
|
-
context.get_status_change reader_states, Smartcard::PCSC::INFINITE_TIMEOUT
|
28
|
-
puts "Status change: now it's #{reader_states.event_state_of(0)} and we want #{Smartcard::PCSC::STATE_PRESENT}\n"
|
29
|
-
reader_states.acknowledge_events!
|
30
|
-
end
|
31
|
-
|
32
|
-
puts "Connecting to card\n"
|
33
|
-
card0 = Smartcard::PCSC::Card.new(context, reader0, Smartcard::PCSC::SHARE_SHARED, Smartcard::PCSC::PROTOCOL_ANY)
|
34
|
-
|
35
|
-
card0.begin_transaction
|
36
|
-
card0.end_transaction Smartcard::PCSC::DISPOSITION_LEAVE
|
37
|
-
|
38
|
-
begin
|
39
|
-
card0.reconnect Smartcard::PCSC::SHARE_EXCLUSIVE, Smartcard::PCSC::PROTOCOL_ANY, Smartcard::PCSC::INITIALIZATION_RESET
|
40
|
-
rescue RuntimeException => e
|
41
|
-
puts "Card.reconnect threw exception #{e}\n"
|
42
|
-
end
|
43
|
-
|
44
|
-
card_status = card0.status
|
45
|
-
pp card_status
|
46
|
-
puts "ATR Length: #{card_status[:atr].length}\n"
|
47
|
-
|
48
|
-
begin
|
49
|
-
puts "IFD vendor: #{card0.get_attribute Smartcard::PCSC::ATTR_VENDOR_IFD_VERSION}\n"
|
50
|
-
rescue RuntimeError => e
|
51
|
-
puts "Card.get_attribute threw exception #{e}\n"
|
52
|
-
end
|
53
|
-
|
54
|
-
puts "Selecting applet\n"
|
55
|
-
aid = [0x19, 0x83, 0x12, 0x29, 0x10, 0xba, 0xbe]
|
56
|
-
select_apdu = [0x00, 0xA4, 0x04, 0x00, aid.length, aid].flatten
|
57
|
-
send_ioreq = {Smartcard::PCSC::PROTOCOL_T0 => Smartcard::PCSC::IOREQUEST_T0,
|
58
|
-
Smartcard::PCSC::PROTOCOL_T1 => Smartcard::PCSC::IOREQUEST_T1}[card_status[:protocol]]
|
59
|
-
recv_ioreq = Smartcard::PCSC::IoRequest.new
|
60
|
-
select_response = card0.transmit(select_apdu.map {|byte| byte.chr}.join(''), send_ioreq, recv_ioreq)
|
61
|
-
select_response_str = (0...select_response.length).map { |i| ' %02x' % select_response[i].to_i }.join('')
|
62
|
-
puts "Response:#{select_response_str}\n"
|
63
|
-
|
64
|
-
begin
|
65
|
-
# This only works with GemPlus readers... any other suggestions?
|
66
|
-
puts "Testing low-level control\n"
|
67
|
-
ctl_string = [0x82, 0x01, 0x07, 0x00].map {|byte| byte.chr}.join('')
|
68
|
-
ctl_response = card0.control 2049, ctl_string, 4
|
69
|
-
pp ctl_response
|
70
|
-
rescue RuntimeError => e
|
71
|
-
puts "Card.control threw exception #{e}\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
puts "Disconnecting and cleaning up\n"
|
75
|
-
card0.disconnect Smartcard::PCSC::DISPOSITION_LEAVE
|
76
|
-
context.release
|