-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomnikey-detector.py
36 lines (32 loc) · 1.32 KB
/
omnikey-detector.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
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.util import *
import sys
from smartcard.scard import *
import webbrowser
class PrintObserver(CardObserver):
def update(self, observable, (addedcards, removedcards)):
for card in addedcards:
print "+Inserted: ", toHexString(card.atr)
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
assert hresult == SCARD_S_SUCCESS
hresult, readers = SCardListReaders(hcontext, [])
assert len(readers) > 0
reader = readers[0]
hresult, hcard, dwActiveProtocol = SCardConnect(
hcontext,
reader,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
hresult, response = SCardTransmit(hcard, dwActiveProtocol, [0xFF, 0xCA, 0x00, 0x00, 0x00])
webbrowser.open('http://foo.bar/?uid=' + ''.join(str(e) for e in response))
for card in removedcards:
print "-Removed: ", toHexString(card.atr)
try:
print "Insert or remove a smartcard in the system."
print ""
cardmonitor = CardMonitor()
cardobserver = PrintObserver()
cardmonitor.addObserver(cardobserver)
raw_input('Press Enter to exit\n')
except:
print "Unexpected error: ", sys.exc_info()[0]