diff --git a/pace-gui/src/pinpad.glade b/pace-gui/src/pinpad.glade index e39d80d..c9afe68 100644 --- a/pace-gui/src/pinpad.glade +++ b/pace-gui/src/pinpad.glade @@ -60,10 +60,20 @@ 3 + + + True + <span fgcolor="red" font_weight="bold" font="11">Keine Karte gefunden</span> + True + + + 4 + + True - 5 + 4 3 True @@ -74,11 +84,46 @@ True + + + + 4 + True + True + True + + 1 2 + + + 7 + True + True + True + + + + 2 + 3 + + + + + Entf + True + True + True + + + + 3 + 4 + + 2 @@ -90,36 +135,6 @@ 1 2 - 1 - 2 - - - - - 3 - True - True - True - - - - 2 - 3 - 1 - 2 - - - - - 4 - True - True - True - - - - 2 - 3 @@ -133,36 +148,8 @@ 1 2 - 2 - 3 - - - - - 6 - True - True - True - - - - 2 - 3 - 2 - 3 - - - - - 7 - True - True - True - - - - 3 - 4 + 1 + 2 @@ -176,23 +163,8 @@ 1 2 - 3 - 4 - - - - - 9 - True - True - True - - - - 2 - 3 - 3 - 4 + 2 + 3 @@ -206,8 +178,51 @@ 1 2 - 4 - 5 + 3 + 4 + + + + + 3 + True + True + True + + + + 2 + 3 + + + + + 6 + True + True + True + + + + 2 + 3 + 1 + 2 + + + + + 9 + True + True + True + + + + 2 + 3 + 2 + 3 @@ -221,64 +236,13 @@ 2 3 - 4 - 5 + 3 + 4 - - - Entf - True - True - True - - - - 4 - 5 - - - - - PUK - True - True - False - True - rdioCAN - - - 2 - 3 - - - - - PIN - True - True - False - True - rdioCAN - - - 1 - 2 - - - - - CAN - True - True - False - True - True - - - 4 + 5 diff --git a/pace-gui/src/pinpad.py b/pace-gui/src/pinpad.py index f375336..20562e2 100644 --- a/pace-gui/src/pinpad.py +++ b/pace-gui/src/pinpad.py @@ -2,6 +2,7 @@ import sys, os import subprocess +from threading import Thread, Event try: import pygtk pygtk.require("2.0") @@ -14,7 +15,7 @@ except: sys.exit(1) #glade_dir is set by the build system -from pinpad_globals import glade_dir +from pinpad_globals import * class PinpadGTK: """This a simple GTK based GUI to enter a PIN""" @@ -63,6 +64,11 @@ class PinpadGTK: font = pango.FontDescription("Monospace") txtOutput.modify_font(pango.FontDescription("sans 24")) + #Look for card and set the label accordingly + lbl_cardStatus = self.builder.get_object("lbl_cardStatus") + self.cardChecker = cardChecker(lbl_cardStatus, ePA_ATR) + gobject.idle_add(self.cardChecker.start) + #Change the font for the buttons #For this you have to retrieve the label of each button and change #its font @@ -88,7 +94,12 @@ class PinpadGTK: self.window.show() if (self.window): - self.window.connect("destroy", gtk.main_quit) + self.window.connect("destroy", self.shutdown) + + def shutdown(self, widget): + self.cardChecker.stop() + self.cardChecker.join() + gtk.main_quit() def digit_clicked(self, widget): c = widget.get_label() @@ -102,14 +113,11 @@ class PinpadGTK: #Check which radio button is checked, so we know what kind of secret to #use for PACE - rdio = self.builder.get_object("rdioCAN") - rdioGrp = rdio.get_group() - rdioActive = [r for r in rdioGrp if r.get_active()] env_arg = os.environ - env_arg[rdioActive[0].get_label()] = self.pin + env_arg["PIN"] = self.pin #We alway use the eID-PIN #We have to provide the type of secret to use via a command line parameter - param = "--" + rdioActive[0].get_label().lower() + param = "--pin" try: p = subprocess.Popen(["pace-tool", param, "-v"], @@ -144,7 +152,8 @@ class PinpadGTK: else: lbl = self.builder.get_object("txtOutput") popup = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL | - gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, + gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, + gtk.BUTTONS_OK, "PIN wurde falsch eingegeben. Bitte erneut versuchen") res = popup.run() popup.destroy() @@ -180,6 +189,46 @@ class Popup(object): fraction = 0.0 self.progbar.set_fraction(fraction) +class cardChecker(Thread): + """ This class searches for a card with a given ATR and displays + wether or not it was found on the label of a widget """ + + def __init__(self, widget, atr, intervall=1): + Thread.__init__(self) + self._finished = Event() + self.widget = widget + self.targetATR = atr + self.intervall = intervall + + def __cardCheck(self): + """ + Actually this method should make use of pyscard, but I couldn't make + it run on the OpenMoko yet. Therefor we call opensc-tool instead, which + leads to higher delays """ + + try: + p = subprocess.Popen(["opensc-tool", "--atr"], stdout=subprocess.PIPE, + stderr=subprocess.PIPE, close_fds=True) + + line = p.stdout.readline().rstrip() + if line == self.targetATR: + gobject.idle_add(self.widget.set_label, STR_CARD_FOUND) + else: + gobject.idle_add(self.widget.set_label, STR_NO_CARD) + + except OSError, e: + pass #FIXME + + def run(self): + while (True): + if self._finished.isSet(): return + self.__cardCheck() + self._finished.wait(self.intervall) + + def stop(self): + self._finished.set() + if __name__ == "__main__": + gobject.threads_init() pinpad = PinpadGTK() gtk.main() diff --git a/pace-gui/src/pinpad_globals.py.in b/pace-gui/src/pinpad_globals.py.in index f08ec4d..2ab2999 100644 --- a/pace-gui/src/pinpad_globals.py.in +++ b/pace-gui/src/pinpad_globals.py.in @@ -2,3 +2,7 @@ name = "pinpad" version = "@VERSION@" image_dir = "@prefix@/share/pixmaps" glade_dir = "@prefix@/share/" + name + +STR_NO_CARD = "Keine Karte gefunden" +STR_CARD_FOUND = "Karte gefunden" +ePA_ATR = "3b:84:80:01:00:00:90:00:95"