- Remember the password when loading a card from disk and reuse it when saving the card.

- Added a bit of documentation


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@512 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-09-01 14:04:36 +00:00
parent 495022b38a
commit 373bf41ff3

View File

@@ -48,6 +48,7 @@ class CardGenerator(object):
self.type = card_type self.type = card_type
self.mf = mf self.mf = mf
self.sam = sam self.sam = sam
self.password = None
def __generate_iso_card(self): def __generate_iso_card(self):
default_pin = "1234" default_pin = "1234"
@@ -62,6 +63,10 @@ class CardGenerator(object):
self.sam.set_MF(self.mf) self.sam.set_MF(self.mf)
def __generate_ePass(self): def __generate_ePass(self):
"""Generate the MF and SAM of an ICAO passport. This method is
responsible for generating the filesystem and filling it with content.
Therefore it must interact with the user by prompting for the MRZ and
optionally for the path to a photo."""
from PIL import Image from PIL import Image
#TODO: Sanity checks #TODO: Sanity checks
@@ -168,28 +173,28 @@ class CardGenerator(object):
self.sam = sam self.sam = sam
def loadCard(self, filename, password=None): def loadCard(self, filename):
"""Load a card from disk""" """Load a card from disk"""
db = anydbm.open(filename, 'r') db = anydbm.open(filename, 'r')
if password is None: if self.password is None:
password = getpass.getpass("Please enter your password:") self.password = getpass.getpass("Please enter your password:")
serializedMF = read_protected_string(db["mf"], password) serializedMF = read_protected_string(db["mf"], self.password)
serializedSAM = read_protected_string(db["sam"], password) serializedSAM = read_protected_string(db["sam"], self.password)
self.sam = loads(serializedSAM) self.sam = loads(serializedSAM)
self.mf = loads(serializedMF) self.mf = loads(serializedMF)
self.type = db["type"] self.type = db["type"]
def saveCard(self, filename, password=None): def saveCard(self, filename):
"""Save the currently running card to disk""" """Save the currently running card to disk"""
if password is None: if self.password is None:
passwd1 = getpass.getpass("Please enter your password:") passwd1 = getpass.getpass("Please enter your password:")
passwd2 = getpass.getpass("Please retype your password:") passwd2 = getpass.getpass("Please retype your password:")
if (passwd1 != passwd2): if (passwd1 != passwd2):
raise ValueError, "Passwords did not match. Will now exit" raise ValueError, "Passwords did not match. Will now exit"
else: else:
password = passwd1 self.password = passwd1
if self.mf == None or self.sam == None: if self.mf == None or self.sam == None:
raise ValueError, "Card Generator wasn't set up properly" +\ raise ValueError, "Card Generator wasn't set up properly" +\
@@ -197,8 +202,8 @@ class CardGenerator(object):
mf_string = dumps(self.mf) mf_string = dumps(self.mf)
sam_string = dumps(self.sam) sam_string = dumps(self.sam)
protectedMF = protect_string(mf_string, password) protectedMF = protect_string(mf_string, self.password)
protectedSAM = protect_string(sam_string, password) protectedSAM = protect_string(sam_string, self.password)
db = anydbm.open(filename, 'c') db = anydbm.open(filename, 'c')
db["mf"] = protectedMF db["mf"] = protectedMF