Hi again,

after some fiddling with Python threads, I've written a short script
which does exactly what the bash script does, without the nasty trick of
parsing pcsc_scan output (see attachment). What's still missing here is
reader addition/removal monitoring, I'm not quite sure if this is
needed?

Florian

On Fr, 2011-09-02 at 17:49 +0200, Ludovic Rousseau wrote:
> 2011/9/2 Florian Echtler <[email protected]>:
> > a while ago, there was a discussion in xdg [1] about DBus support for
> > smartcard activity. I've hacked together a bash script for that purpose:
[...]
> > However, I think it would be a bit smoother to directly integrate this
> > into pcsc-lite. The best to add support would be in eventhandler.c,
> > correct?
> 
> I don't think it is a good idea to add that inside pcsc-lite.
> You should be able to to the same as in your bash script using Python
> to link pyscard [2] on one side and dbus-python on the other side.
> If you provide such a script I may include it in the pcsc-lite project
> in contrib [3].
> 
> You can get information like card insertion or removal, reader
> insertion or removal.
> But you will not get events like "an APDU exchange is ongoing". This
> could be a security issue if anyone could spy at this level. But that
> would be great to implement a software blinking LED for readers
> without this feature.
-- 
SENT FROM MY PDP-11
#!/usr/bin/env python

"""
pcsc-watcher.py
(c) 2011 by Florian "floe" Echtler <[email protected]>
"""

import gobject

import dbus
import dbus.service 

from dbus.mainloop.glib import DBusGMainLoop

from smartcard.CardMonitoring import *
from smartcard.util import *


# dbus stuff

service = None

interface = "org.debian.alioth.pcsclite" # also used as bus name
path = "/org/debian/alioth/pcsclite/reader0/slot0"

# very simple DBus service class with one signal
class PCSC_DBus_Service(dbus.service.Object):
	def __init__(self,object_path):
		bus_name = dbus.service.BusName(interface, bus=dbus.SessionBus())
		dbus.service.Object.__init__(self, bus_name, object_path)

	@dbus.service.signal(interface)
	def CardPresenceChanged(self, atr, added):
		pass


# smartcard stuff

# simple card observer class which calls the DBus service
class PCSC_Card_Observer(CardObserver):
	def update(self, observable, (addedcards, removedcards)):
		for card in addedcards:
			service.CardPresenceChanged(toHexString(card.atr),True)
		for card in removedcards:
			service.CardPresenceChanged(toHexString(card.atr),False)


# main

DBusGMainLoop(set_as_default=True)
gobject.threads_init() # very important to avoid starving the PCSC thread

service = PCSC_DBus_Service(path)

cardmonitor = CardMonitor()
cardobserver = PCSC_Card_Observer()
cardmonitor.addObserver(cardobserver)

gobject.MainLoop().run()

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle

Reply via email to