Ich bastle schon lange an Fahrerkarte. Auch schon vor einer Weile in Projekte vorgestellt.
Zur Info:
Hirsute 21.04 amd64
Mein DEB Paket installiert =ok
Mein Python Paket installiert =ok
Später soll alles in ein PPA.
Programm startet, Oberfläche auch, Starter funktionieren auch.
Mu-Editor zeigt keine Fehlermeldung, IDLE auch nicht.
Kartenleser Test = ok
Datei Ausgabe anzeigen = ok
SmarCard Test =ok
SmartCard einstecken, anzeigen = ok
SmartCard wird gefunden auslesen starten und Datei anlegen nicht ok.
Ich sehe das auf dem Kartenleser gelesen wird, er blinkert, es wird aber keine Datei angelegt.
Ich habe in meiner Dropbox alles hinterlegt, wer Interesse hat sich Bilder und Dateien anzusehen?
Link zur Textdatei mit alle Links:
Einfach im Dateibrowser anzeigen lassen.
https://www.dropbox.com/s/z47hpxuc33rx ... zung?dl=0
Im Terminal zeigt sich folgendes, nach Klick auf "Jetzt auslesen":
Code: Alles auswählen
marko@marko-LIFEBOOK-AH530:~$ fahrerkarte.py
insert a card (SIM card if possible) within 30s
connecting to Cherry GmbH SmartTerminal XX44 00 00
ATR 3B DB 96 FF C0 10 31 FE 45 80 67 15 01 B4 03 00 09 00 81 05 21
> A0 A4 00 00 02 7F 10
< [] 6E 00
disconnecting from Cherry GmbH SmartTerminal XX44 00 00
disconnecting from Cherry GmbH SmartTerminal XX44 00 00
Die Schaltfläche "Jetzt auslesen" ruft diese Datei auf "auslesen.py"
Code: Alles auswählen
#! /usr/bin/env python
"""
Sample script that illustrates exclusive card connection decorators.
__author__ = "http://www.gemalto.com"
Copyright 2001-2012 gemalto
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
This file is part of pyscard.
pyscard is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
pyscard 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from __future__ import print_function
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest
from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver
from smartcard.util import toHexString
from smartcard.ExclusiveConnectCardConnection import \
ExclusiveConnectCardConnection
from smartcard.ExclusiveTransmitCardConnection import \
ExclusiveTransmitCardConnection
from datetime import datetime, timedelta
from datetime import date
import os
# define the apdus used in this script
GET_RESPONSE = [0XA0, 0XC0, 00, 00]
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]
# request any card type
cardtype = AnyCardType()
cardrequest = CardRequest(timeout=5, cardType=cardtype)
cardservice = cardrequest.waitforcard()
# attach the console tracer
observer = ConsoleCardConnectionObserver()
cardservice.connection.addObserver(observer)
# attach our decorator
cardservice.connection = ExclusiveTransmitCardConnection(
ExclusiveConnectCardConnection(cardservice.connection))
# connect to the card and perform a few transmits
cardservice.connection.connect()
print('ATR', toHexString(cardservice.connection.getATR()))
try:
# lock for initiating transaction
cardservice.connection.lock()
apdu = SELECT + DF_TELECOM
response, sw1, sw2 = cardservice.connection.transmit(apdu)
if sw1 == 0x9F:
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit(apdu)
finally:
# unlock connection at the end of the transaction
cardservice.connection.unlock()
import sys
if 'win32' == sys.platform:
print('press Enter to continue')
sys.stdin.read(1)
# -*- coding: UTF-8 -*-
"""
Script zum auslesen der Fahrerkarte von DigitalenTachographen
Copyright 2009 Stefan Manteuffel linux@sm-recycling.de
pyscard wir benötigt http://sourceforge.net/projects/pyscard/
pyscard is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
pyscard 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
import wx
from smartcard.wx.APDUHexValidator import APDUHexValidator
from smartcard.wx.SimpleSCardAppEventObserver import SimpleSCardAppEventObserver
from smartcard.CardConnection import CardConnection
from smartcard.Exceptions import NoCardException, CardConnectionException
from smartcard.System import readers
from sys import stdin, exc_info
from time import *
import binascii
import array
from datetime import *
from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.util import *
from smartcard.CardRequest import CardRequest
from smartcard.CardType import ATRCardType
from struct import *
import os
[
ID_TEXT_COMMAND,
ID_TEXTCTRL_COMMAND,
ID_TEXT_RESPONSE,
ID_TEXTCTRL_RESPONSE,
ID_TEXT_SW,
ID_TEXT_SW1,
ID_TEXTCTRL_SW1,
ID_TEXT_SW2,
ID_TEXTCTRL_SW2,
ID_CARDSTATE,
ID_TRANSMIT
] = map( lambda x: wx.NewIdRef(count=1), range(11) )
#ID_ABOUT = 101
#ID_EXIT = 110
#ID_OPEN = 111
lesen = {}
lesen[1] = [0x00, 0xb0, 0x00, 0x00, 0xc8]
lesen[2] = [0x00, 0xb0, 0x00, 0xc8, 0xc8]
lesen[3] = [0x00, 0xb0, 0x01, 0x90, 0xc8]
lesen[4] = [0x00, 0xb0, 0x02, 0x58, 0xc8]
lesen[5] = [0x00, 0xb0, 0x03, 0x20, 0xc8]
lesen[6] = [0x00, 0xb0, 0x03, 0xe8, 0xc8]
lesen[7] = [0x00, 0xb0, 0x04, 0xb0, 0xc8]
lesen[8] = [0x00, 0xb0, 0x05, 0x78, 0xc8]
lesen[9] = [0x00, 0xb0, 0x06, 0x40, 0xc8]
lesen[10] = [0x00, 0xb0, 0x07, 0x08, 0xc8]
lesen[11] = [0x00, 0xb0, 0x07, 0xd0, 0xc8]
lesen[12] = [0x00, 0xb0, 0x08, 0x98, 0xc8]
lesen[13] = [0x00, 0xb0, 0x09, 0x60, 0xc8]
lesen[14] = [0x00, 0xb0, 0x0a, 0x28, 0xc8]
lesen[15] = [0x00, 0xb0, 0x0a, 0xf0, 0xc8]
lesen[16] = [0x00, 0xb0, 0x0b, 0xb8, 0xc8]
lesen[17] = [0x00, 0xb0, 0x0c, 0x80, 0xc8]
lesen[18] = [0x00, 0xb0, 0x0d, 0x48, 0xc8]
lesen[19] = [0x00, 0xb0, 0x0e, 0x10, 0xc8]
lesen[20] = [0x00, 0xb0, 0x0e, 0xd8, 0xc8]
lesen[21] = [0x00, 0xb0, 0x0f, 0xa0, 0xc8]
lesen[22] = [0x00, 0xb0, 0x10, 0x68, 0xc8]
lesen[23] = [0x00, 0xb0, 0x11, 0x30, 0xc8]
lesen[24] = [0x00, 0xb0, 0x11, 0xf8, 0xc8]
lesen[25] = [0x00, 0xb0, 0x12, 0xc0, 0xc8]
lesen[26] = [0x00, 0xb0, 0x13, 0x88, 0xc8]
lesen[27] = [0x00, 0xb0, 0x14, 0x50, 0xc8]
lesen[28] = [0x00, 0xb0, 0x15, 0x18, 0xc8]
lesen[29] = [0x00, 0xb0, 0x15, 0xe0, 0xc8]
lesen[30] = [0x00, 0xb0, 0x16, 0xa8, 0xc8]
lesen[31] = [0x00, 0xb0, 0x17, 0x70, 0xc8]
lesen[32] = [0x00, 0xb0, 0x18, 0x38, 0xc8]
lesen[33] = [0x00, 0xb0, 0x19, 0x00, 0xc8]
lesen[34] = [0x00, 0xb0, 0x19, 0xc8, 0xc8]
lesen[35] = [0x00, 0xb0, 0x1a, 0x90, 0xc8]
lesen[36] = [0x00, 0xb0, 0x1b, 0x58, 0xc8]
lesen[37] = [0x00, 0xb0, 0x1c, 0x20, 0xc8]
lesen[38] = [0x00, 0xb0, 0x1c, 0xe8, 0xc8]
lesen[39] = [0x00, 0xb0, 0x1d, 0xb0, 0xc8]
lesen[40] = [0x00, 0xb0, 0x1e, 0x78, 0xc8]
lesen[41] = [0x00, 0xb0, 0x1f, 0x40, 0xc8]
lesen[42] = [0x00, 0xb0, 0x20, 0x08, 0xc8]
lesen[43] = [0x00, 0xb0, 0x20, 0xd0, 0xc8]
lesen[44] = [0x00, 0xb0, 0x21, 0x98, 0xc8]
lesen[45] = [0x00, 0xb0, 0x22, 0x60, 0xc8]
lesen[46] = [0x00, 0xb0, 0x23, 0x28, 0xc8]
lesen[47] = [0x00, 0xb0, 0x23, 0xf0, 0xc8]
lesen[48] = [0x00, 0xb0, 0x24, 0xb8, 0xc8]
lesen[49] = [0x00, 0xb0, 0x25, 0x80, 0xc8]
lesen[50] = [0x00, 0xb0, 0x26, 0x48, 0xc8]
lesen[51] = [0x00, 0xb0, 0x27, 0x10, 0xc8]
lesen[52] = [0x00, 0xb0, 0x27, 0xd8, 0xc8]
lesen[53] = [0x00, 0xb0, 0x28, 0xa0, 0xc8]
lesen[54] = [0x00, 0xb0, 0x29, 0x68, 0xc8]
lesen[55] = [0x00, 0xb0, 0x2a, 0x30, 0xc8]
lesen[56] = [0x00, 0xb0, 0x2a, 0xf8, 0xc8]
lesen[57] = [0x00, 0xb0, 0x2b, 0xc0, 0xc8]
lesen[58] = [0x00, 0xb0, 0x2c, 0x88, 0xc8]
lesen[59] = [0x00, 0xb0, 0x2d, 0x50, 0xc8]
lesen[60] = [0x00, 0xb0, 0x2e, 0x18, 0xc8]
lesen[61] = [0x00, 0xb0, 0x2e, 0xe0, 0xc8]
lesen[62] = [0x00, 0xb0, 0x2f, 0xa8, 0xc8]
lesen[63] = [0x00, 0xb0, 0x30, 0x70, 0x5c]
#readdatum = ""
#test = 0
class fahrerkarte( wx.Panel, SimpleSCardAppEventObserver ):
'''A simple panel that displays activated cards and readers and can
send APDU to a connected card.'''
def __init__( self, parent ):
wx.Panel.__init__( self, parent, -1 )
SimpleSCardAppEventObserver.__init__( self )
self.layoutControls()
## wxMenuBar
## Setting up the menu.
#filemenu = wx.Menu()
#filemenu.Append(ID_OPEN, "&Open"," Open a file to edit")
#filemenu.AppendSeparator()
#filemenu.Append(ID_ABOUT, "&About"," Information about this program")
#filemenu.AppendSeparator()
#filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
## Creating the menubar.
#menuBar = wx.MenuBar()
#menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
#self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
#wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
#wx.EVT_MENU(self, ID_EXIT, self.OnExit)
#wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
#self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
#self.buttons=[]
#for i in range(0,6):
#self.buttons.append(wx.Button(self, ID_BUTTON1+i, "Button &"+`i`))
#self.sizer2.Add(self.buttons[i],1,wx.EXPAND)
self.Bind( wx.EVT_BUTTON, self.OnTransmit, self.transmitbutton)
# self.Bind( wx.EVT_BUTTON, self.OnAbbruch, self.stopbutton )
# self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
# self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
# callbacks from SimpleSCardAppEventObserver interface
def OnActivateCard( self, card ):
"""Called when a card is activated by double-clicking on the card or reader tree control or toolbar.
In this sample, we just connect to the card on the first activation."""
SimpleSCardAppEventObserver.OnActivateCard( self, card )
def datumlesen( self ):
ID_TEXTCTRL_RESPONSE=self.readdatum
self.feedbacktext1.SetLabel( 'Vorname: ' + 'self.VorName' )
self.feedbacktext2.SetLabel( 'Namame : ' + 'self.NachName' )
self.feedbacktext.SetLabel( 'Letztes Lesedatum: ' + 'self.readdatum' )
self.transmitbutton.Enable()
def OnActivateReader( self, reader ):
SimpleSCardAppEventObserver.OnActivateReader( self, reader )
self.feedbacktext.SetLabel( 'Activated reader: ' + 'reader' )
self.transmitbutton.Disable()
def OnDeactivateCard( self, card ):
"""Called when a card is deactivated in the reader tree control or toolbar."""
SimpleSCardAppEventObserver.OnActivateCard( self, card )
self.feedbacktext.SetLabel( 'Deactivated card: ' + 'card' )
self.transmitbutton.Disable()
def OnDeselectCard( self, card ):
"""Called when a card is selected by clicking on the card or reader tree control or toolbar."""
SimpleSCardAppEventObserver.OnSelectCard( self, card )
self.feedbacktext.SetLabel( 'Deselected card: ' + 'card' )
self.transmitbutton.Disable()
def OnSelectCard( self, card ):
"""Called when a card is selected by clicking on the card or reader tree control or toolbar."""
SimpleSCardAppEventObserver.OnSelectCard( self, card )
self.feedbacktext.SetLabel( 'Selected card: ' )
if hasattr( self.selectedcard, 'connection' ):
self.transmitbutton.Enable()
def OnSelectReader( self, reader ):
"""Called when a reader is selected by clicking on the reader tree control or toolbar."""
SimpleSCardAppEventObserver.OnSelectReader( self, reader )
self.feedbacktext.SetLabel( 'Selected reader: ' + 'reader' )
self.transmitbutton.Disable()
def OnTransmit( self, event ):
if hasattr( self.selectedcard, 'connection' ):
kartelesen(self)
print('Lesen fertig')
datumsetzen(self)
print ('Datum setzen fertig')
event.Skip()
def OnAbbruch(self, event):
# Fahrlinx.Exit()
self.GetParent().Destroy()
# Fahrlinx.Exit()
# main.Exit()
# event.EventObject.Destroy()
# SimpleSCardAppEventObserver.close()
# SimpleSCardApp.Destroy()
# SimpleSCardApp.Exit()
def layoutControls( self ):
# create controls
# statictextCommand = wx.StaticText( self, ID_TEXT_COMMAND, "Cond", wx.DefaultPosition, wx.DefaultSize, 0 )
# self.commandtextctrl = wx.TextCtrl( self, ID_TEXTCTRL_COMMAND, "test",
# wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE,
# validator = APDUHexValidator() )
# statictextResponse = wx.StaticText( self, ID_TEXT_RESPONSE, "Fahrer", wx.DefaultPosition, wx.DefaultSize, 0 )
# ID_TEXTCTRL_RESPONSE=self.readdatum
# self.responsetextctrl = wx.TextCtrl( self, ID_TEXTCTRL_RESPONSE, "test2", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE | wx.TE_READONLY )
# statictextStatusWords = wx.StaticText( self, ID_TEXT_SW, "Status Words", wx.DefaultPosition, wx.DefaultSize, 0 )
#statictextSW1 = wx.StaticText( self, ID_TEXT_SW1, "SW1", wx.DefaultPosition, wx.DefaultSize, 0 )
#self.SW1textctrl = wx.TextCtrl( self, ID_TEXTCTRL_SW1, "test3", wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY )
#statictextSW2 = wx.StaticText( self, ID_TEXT_SW2, "SW2", wx.DefaultPosition, wx.DefaultSize, 0 )
#self.SW2textctrl = wx.TextCtrl( self, ID_TEXTCTRL_SW2, "test4", wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY )
self.feedbacktext1 = wx.StaticText( self, ID_CARDSTATE, "", wx.Point(20, 30), wx.Size(140, -1) )
self.feedbacktext2 = wx.StaticText( self, ID_CARDSTATE, "", wx.Point(500, 600), wx.Size(140, -1) )
self.feedbacktext = wx.StaticText( self, ID_CARDSTATE, "", wx.DefaultPosition, wx.DefaultSize, 0 )
# sampel self.quote = wx.StaticText(self, -1, "Your quote :",wx.Point(20, 30))
# layout controls
boxsizerCommand = wx.BoxSizer( wx.HORIZONTAL )
# boxsizerCommand.Add( statictextCommand, 1, wx.ALIGN_CENTER | wx.ALL, 5 )
# boxsizerCommand.Add( self.commandtextctrl, 5, wx.EXPAND | wx.ALL, 5 )
boxsizerResponse = wx.BoxSizer( wx.HORIZONTAL )
# boxsizerResponse.Add( statictextResponse, 1, wx.ALIGN_CENTER | wx.ALL, 5 )
# boxsizerResponse.Add( self.responsetextctrl, 5, wx.EXPAND | wx.ALL, 5 )
boxsizerSW = wx.BoxSizer( wx.HORIZONTAL )
#boxsizerSW.Add( statictextSW1, 0, wx.ALIGN_CENTER | wx.ALL, 5 )
#boxsizerSW.Add( self.SW1textctrl, 0, wx.EXPAND | wx.ALL, 5 )
#boxsizerSW.Add( statictextSW2, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
#boxsizerSW.Add( self.SW2textctrl, 0, wx.EXPAND|wx.ALL, 5 )
item11 = wx.BoxSizer( wx.HORIZONTAL )
# item11.Add( statictextStatusWords, 0, wx.ALIGN_CENTER | wx.ALL, 5 )
item11.Add( boxsizerSW, 0, wx.EXPAND | wx.ALL, 5 )
boxsizerResponseAndSW = wx.BoxSizer( wx.VERTICAL )
boxsizerResponseAndSW.Add( boxsizerResponse, 0, wx.EXPAND|wx.ALL, 5 )
boxsizerResponseAndSW.Add( item11, 0, wx.EXPAND|wx.ALL, 5 )
#staticboxAPDU = wx.StaticBox( self, -1, "Tool zum auslesen der Europäischen Fahrer" )
#boxsizerAPDU = wx.StaticBoxSizer( staticboxAPDU, wx.VERTICAL )
#boxsizerAPDU.Add( boxsizerCommand, 1, wx.EXPAND | wx.ALL, 5 )
#boxsizerAPDU.Add( boxsizerResponseAndSW, 4, wx.EXPAND | wx.ALL, 5 )
staticboxEvents = wx.StaticBox( self, -1, "" )
boxsizerEvents = wx.StaticBoxSizer( staticboxEvents, wx.VERTICAL )
boxsizerEvents.Add( self.feedbacktext1, 0, wx.ALIGN_LEFT | wx.ALL, 5 )
boxsizerEvents.Add( self.feedbacktext2, 0, wx.ALIGN_LEFT | wx.ALL, 5 )
boxsizerEvents.Add( self.feedbacktext, 0, wx.ALIGN_LEFT | wx.ALL, 5 )
sizerboxTransmitButton = wx.BoxSizer( wx.HORIZONTAL )
sizerboxTransmitButton.Add( [ 20, 20 ] , 0, wx.ALIGN_CENTER|wx.ALL, 5 )
self.transmitbutton = wx.Button( self, ID_TRANSMIT, "Start", wx.DefaultPosition, wx.DefaultSize, 0 )
self.transmitbutton.Disable()
sizerboxTransmitButton.Add( self.transmitbutton, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
sizerboxTransmitButton.Add( [ 20, 20 ] , 0, wx.ALIGN_CENTER|wx.ALL, 5 )
sizerboxstopbutton = wx.BoxSizer( wx.HORIZONTAL )
sizerboxstopbutton.Add( [ 20, 20 ] , 0, wx.ALIGN_CENTER|wx.ALL, 5 )
self.stopbutton = wx.Button( self, ID_TRANSMIT, "Abbruch", wx.Point(200, 211), wx.Size(80, -1))
sizerPanel = wx.BoxSizer( wx.VERTICAL )
# sizerPanel.Add( boxsizerAPDU, 3, wx.EXPAND | wx.ALL, 5 )
sizerPanel.Add( boxsizerEvents, 1, wx.EXPAND | wx.ALL, 5 )
sizerPanel.Add( sizerboxTransmitButton, 1, wx.EXPAND | wx.ALL, 5 )
sizerPanel.Add( sizerboxstopbutton, 1, wx.EXPAND | wx.ALL, 5 )
self.SetSizer( sizerPanel )
self.SetAutoLayout(True)
sizerPanel.Fit(self)
def kartelesen(self):
def berehash(self): # nicht speichern
apdu = [0x80, 0x2a, 0x90, 0x00]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
#EF = "" "HASH of File"
# Signatur des hash codes erstellen
def sighash(self, response): # an Datei anhängen
apdu = [0x00, 0x2a, 0x9e, 0x9a, 0x80]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ss = len(response)
# print "sighash tag ", tag
tagneu = [0, 0, 0, 0, 0]
tagneu[0] = tag[0]
tagneu[1] = tag[1]
tagneu[2] = 1
tagneu[3] = 0
tagneu[4] = ss
a = array.array("B", response )
b = array.array("B", tagneu )
datei.write(b.tostring())
datei.write(a.tostring())
# Auswahl nach Namen für die Kontrollgeräteanwendung
def kgaw(self):
apdu = [0x00, 0xa4, 0x04, 0x0c, 0x06, 0xff, 0x54, 0x41, 0x43, 0x48, 0x4f]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
def datschreiben(datei, response):
# print "response ", response
a = array.array("B", response )
b = array.array("B", tag )
datei.write(b.tostring())
datei.write(a.tostring())
def datschreibenoh(datei, response):
a = array.array("B", response )
datei.write(a.tostring())
datei = open("file.ddd", "wb")
# ICC
#EF = ""
tag = [0x00, 0x02, 0x00, 0x00, 0x19] # + response
apdu = [0x00, 0xA4, 0x02, 0x0C, 0x02, 0x00, 0x02]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0x19]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
# IC
tag = [0x00, 0x05, 0x00, 0x00, 0x08] # + response
apdu = [0x00, 0xA4, 0x02, 0x0C, 0x02, 0x00, 0x05]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ic = response
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0x08]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
kgaw(self)
###Aplication ID
tag = [0x05, 0x01, 0x00, 0x00, 0x0a] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x01]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Perform HASH of File Hash für File berechnen
berehash(self)
if sw1 == 144 and sw2 == 0:
# Datei lesen
apdu = [0x00, 0xb0, 0x00, 0x00, 0x0a ]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
# datei auswählen Identification
tag = [0x05, 0x20, 0x00, 0x00, 0x8f] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x20]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0x00]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
kgaw(self)
# datei auswählen Events_Data
tag = [0x05, 0x02, 0x00, 0x06, 0xc0] # +
response = ""
datschreiben(datei, response)
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x02]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
i=1
while i<=8:
response, sw1, sw2 = self.selectedcard.connection.transmit( lesen[i], CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
datschreibenoh(datei, response)
i = i + 1
else:
i=50
# Der letzte Block wird nicht aus dem Array gelesen, da er eine andere länge hat
apdu =[0x00, 0xb0, 0x06, 0x40, 0x80]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
# kgaw(self)
# datei auswählen Faults_Data
tag = [0x05, 0x03, 0x00, 0x04, 0x80] # +
response = ""
datschreiben(datei, response)
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x03]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
i=1
while i<=5:
response, sw1, sw2 = self.selectedcard.connection.transmit( lesen[i], CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
i = i + 1
else:
i=50
# Der letzte Block wird nicht aus dem Array gelesen, da er eine andere länge hat
apdu =[0x00, 0xb0, 0x03, 0xe8, 0x98]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
kgaw(self)
# datei auswählen Driver_Activity_Data
tag = [0x05, 0x04, 0x00, 0x30, 0xcc] # + response
response = ""
datschreiben(datei, response)
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x04]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
i=1
while i<=62:
response, sw1, sw2 = self.selectedcard.connection.transmit( lesen[i], CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
i = i + 1
else:
i=70
# Der letzte Block wird nicht aus dem Array gelesen, da er eine andere länge hat
apdu =[0x00, 0xb0, 0x30, 0x70, 0x5c]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
# kgaw(self)
# datei auswählen Vehicels_Used
tag = [0x05, 0x05, 0x00, 0x18, 0x3a] # +
response =""
datschreiben(datei, response)
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x05]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
# Lesen als Schleife aus dem Array lesen[]
i=1
while i<=31:
response, sw1, sw2 = self.selectedcard.connection.transmit( lesen[i], CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
i = i + 1
else:
i=70
# Der letzte Block wird nicht aus dem Array gelesen, da er eine andere länge hat
apdu =[0x00, 0xb0, 0x18, 0x38, 0x02]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
kgaw(self)
# datei auswählen Places
tag = [0x05, 0x06, 0x00, 0x04, 0x61] # +
response = ""
datschreiben(datei, response)
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x06]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
# Lesen als Schleife aus dem Array lesen[]
i=1
while i<=5:
response, sw1, sw2 = self.selectedcard.connection.transmit( lesen[i], CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
i = i + 1
else:
i=70
# Der letzte Block wird nicht aus dem Array gelesen, da er eine andere länge hat
apdu =[0x00, 0xb0, 0x03, 0xe8, 0x79]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
kgaw(self)
# datei auswählen Control_Activity_Data
tag = [0x05, 0x08, 0x00, 0x00, 0x2e] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x08]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0x2e]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
kgaw(self)
# datei auswählen Specific_Conditions
tag = [0x05, 0x22, 0x00, 0x01, 0x18] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x22]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Hash berechnen
berehash(self)
# Datei lesen
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0xc8]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
apdu = [ 0x00, 0xb0, 0x00, 0xc8, 0x50]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreibenoh(datei, response)
if sw1 == 144 and sw2 == 0:
# Signatur des hash codes erstellen
sighash(self, response)
#Card Zertifikat
tag = [0xc1, 0x00, 0x00, 0x00, 0xc2] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0xc1, 0x00]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# lesen
apdu = [ 0x00, 0xb0, 0x00, 0x00, 0xc2]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
## CA Zertifikat
tag = [0xc1, 0x08, 0x00, 0x00, 0xc2] # + response
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0xc1, 0x08]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
if sw1 == 144 and sw2 == 0:
# Datei lesen
apdu = [0x00, 0xb0, 0x00, 0x00, 0xc2 ]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
datschreiben(datei, response)
if sw1 == 144 and sw2 == 0:
# Dateinamen zusammensetzten
#
# Identifikation Kartenhalter
NachName = ""
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x20]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
# VorName
apdu = [ 0x00, 0xb0, 0x00, 0x66, 0x01]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
NachName = NachName + chr(response[0])
NachName = NachName + "_"
# NachName
apdu = [ 0x00, 0xb0, 0x00, 0x42, 0x23]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ss = len(response)
i = 0
while i < ss:
bb = response[i]
NachName = NachName + chr(bb)
i = i + 1
NachName = NachName + "_"
# Kartenummer
apdu = [ 0x00, 0xb0, 0x00, 0x01, 0x0e]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
Kartenummer = response
ss = len(response)
i = 0
while i < ss:
bb = response[i]
NachName = NachName + chr(bb)
i = i + 1
dz = (strftime("C_%Y%m%d_%H%M_"))
fn = "/" + dz + NachName + ".DDD"
datei.close()
# print " Alles Erfolgreich"
else:
# print ' keine Fahrerkarte'
datei.close()
dir = os.getcwd()
altfile = dir + "/file.ddd"
neufile = dir + fn
os.rename( altfile, neufile )
def datumsetzen(self):
print('Datum setzen')
apdu = [0x00, 0xa4, 0x04, 0x0c, 0x06, 0xff, 0x54, 0x41, 0x43, 0x48, 0x4f]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
print('response', response, sw1, sw2)
# Datei wählen
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x0e]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
print('response', response, sw1, sw2)
# Datum erzeugen
rd = int(mktime(gmtime()))
a = (rd >> 24) & 255
b = (rd >> 16) & 255
c = (rd >> 8) & 255
d = rd & 255
apdu = [0x00, 0xd6, 0x00, 0x00, 0x04, a,b,c,d]
# Datum Schreiben
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
print('response', response, sw1, sw2)
def datumlesen(self): #führt zum fehler beim lesen. Die Karte muss resetet werden ?
# Datei wählen
apdu = [0x00, 0xa4, 0x04, 0x0c, 0x06, 0xff, 0x54, 0x41, 0x43, 0x48, 0x4f]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x0e]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
# Datum lesen
apdu = [0x00, 0xb0, 0x00, 0x00, 0x04 ]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ct = int(toHexString(response, PACK), 16)
rd = gmtime(ct)
self.readdatum = strftime("%a %d.%m.%Y %H Uhr %M ",rd)
def __init__(self, vorname):
self.vorname = ""
apdu = [0x00, 0xa4, 0x02, 0x0c, 0x02, 0x05, 0x20]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
apdu = [ 0x00, 0xb0, 0x00, 0x66, 0x23]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ss = len(response)
i = 0
while i < ss:
bb = chr(response[i])
if bb == " ":
i = 40
# self.vorname = vorname
# i = i + 1
# print "name 1 ", self.VorName
self.NachName = ""
# NachName
apdu = [ 0x00, 0xb0, 0x00, 0x42, 0x23]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
ss = len(response)
i = 0
while i < ss:
bb = chr(response[i])
if bb == " ":
i = 40
self.NachName = self.NachName + bb
i = i + 1
# print " Die Karte wurde zuletzt gelesen ", self.readdatum
# print " Name ", self.NachName, self.VorName
# Karte zurücksetzen
apdu = [0x00, 0xa4, 0x02, 0x3F, 0x00, 0x05, 0x20]
response, sw1, sw2 = self.selectedcard.connection.transmit( apdu, CardConnection.T1_protocol )
# print " response ", response, sw1, sw2
# self.selectedcard.reconnect()
Marko