forked from LudovicRousseau/PCSC-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_PCSC_Part10_features.py
executable file
·63 lines (51 loc) · 2.24 KB
/
get_PCSC_Part10_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
# get_PCSC_Part10_features.py: get and parse CM_IOCTL_GET_FEATURE_REQUEST
# and FEATURE_GET_TLV_PROPERTIES results
# Copyright (C) 2023 Ludovic Rousseau
"""
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from smartcard.pcsc.PCSCPart10 import parseFeatureRequest, parseTlvProperties
from smartcard.System import readers
from smartcard.pcsc.PCSCPart10 import SCARD_SHARE_DIRECT
from smartcard.scard import SCARD_CTL_CODE
CM_IOCTL_GET_FEATURE_REQUEST = SCARD_CTL_CODE(3400)
# for each reader
for reader in readers():
print("Reader:", reader)
card_connection = reader.createConnection()
card_connection.connect(mode=SCARD_SHARE_DIRECT)
data_in = card_connection.control(CM_IOCTL_GET_FEATURE_REQUEST)
features = dict()
for (feature, value) in parseFeatureRequest(data_in):
features[feature] = value
print("CM_IOCTL_GET_FEATURE_REQUEST results:")
for feature in features:
print(" {}: 0x{:X}".format(feature, features[feature]))
print(" Supports Secure PIN Entry (SPE): ", end="")
if "FEATURE_VERIFY_PIN_DIRECT" in features:
print("yes")
else:
print("no")
if "FEATURE_GET_TLV_PROPERTIES" in features:
print("FEATURE_GET_TLV_PROPERTIES results:")
data_in = card_connection.control(features["FEATURE_GET_TLV_PROPERTIES"])
properties = parseTlvProperties(data_in)
for k, v in list(properties.items()):
if isinstance(v, int):
print(" %s: %d or 0x%04X" % (k, v, v))
else:
print(" %s: %s" % (k, v))
print()