provide CommunityID as hex string

CommunityID is taken now from default value or dataset file in readable digit-string Format.
Benefits:
- internal "NotOnChip" function is now working for DG18
- The value is readable ;-)
This commit is contained in:
psytester
2015-01-23 12:49:33 +01:00
committed by Frank Morgner
parent 38d356d55b
commit c4790e02b3
2 changed files with 10 additions and 8 deletions

View File

@@ -1,6 +1,5 @@
# This is an example dataset file for the virtual smartcard. # This is an example dataset file for the virtual smartcard.
# Datagroups are just given in plain ascii, separated by =. # Datagroups are just given in plain ascii, separated by =.
# CommunityID has to be given as hex values enclosed with ' '.
# The File is passed to the virtual smartcard emulator via # The File is passed to the virtual smartcard emulator via
# command line option -d, with or without path. # command line option -d, with or without path.
# #
@@ -32,7 +31,7 @@ Country=D
City=BREMEN City=BREMEN
ZIP=28195 ZIP=28195
Street=STADTMUSIKANTENWEG 12a Street=STADTMUSIKANTENWEG 12a
CommunityID='\x02\x76\x03\x02\x54\x00\x21' CommunityID=02760302540021
# ResidencePermit1 and ResidencePermit2 are part of eAT only # ResidencePermit1 and ResidencePermit2 are part of eAT only
ResidencePermit1=Nebenbestimmungen I Text...(up to 750 characters) ResidencePermit1=Nebenbestimmungen I Text...(up to 750 characters)

View File

@@ -17,7 +17,7 @@
# virtualsmartcard. If not, see <http://www.gnu.org/licenses/>. # virtualsmartcard. If not, see <http://www.gnu.org/licenses/>.
# #
import sys, getpass, anydbm, logging import sys, getpass, anydbm, logging, binascii
from pickle import loads, dumps from pickle import loads, dumps
from virtualsmartcard.TLVutils import pack, unpack from virtualsmartcard.TLVutils import pack, unpack
from virtualsmartcard.utils import inttostring from virtualsmartcard.utils import inttostring
@@ -192,7 +192,10 @@ class CardGenerator(object):
City = self.datagroups["City"] if "City" in self.datagroups else 'KOLN' City = self.datagroups["City"] if "City" in self.datagroups else 'KOLN'
ZIP = self.datagroups["ZIP"] if "ZIP" in self.datagroups else '51147' ZIP = self.datagroups["ZIP"] if "ZIP" in self.datagroups else '51147'
Street = self.datagroups["Street"] if "Street" in self.datagroups else 'HEIDESTRASSE 17' Street = self.datagroups["Street"] if "Street" in self.datagroups else 'HEIDESTRASSE 17'
CommunityID = eval(self.datagroups["CommunityID"]) if "CommunityID" in self.datagroups else '\x02\x76\x03\x78\x90\x02\x76' CommunityID = self.datagroups["CommunityID"] if "CommunityID" in self.datagroups else '02760378900276'
if (CommunityID.rstrip() != "<NotOnChip>"):
# the plain CommunityID integer value has to be translated into its binary representation. '0276...' will be '\x02\x76\...'
CommunityID_Binary = binascii.unhexlify(CommunityID)
# ResidencePermit1 and ResidencePermit2 are part of eAT only # ResidencePermit1 and ResidencePermit2 are part of eAT only
ResidencePermit1 = self.datagroups["ResidencePermit1"] if "ResidencePermit1" in self.datagroups else 'ResidencePermit1 field up to 750 characters' ResidencePermit1 = self.datagroups["ResidencePermit1"] if "ResidencePermit1" in self.datagroups else 'ResidencePermit1 field up to 750 characters'
ResidencePermit2 = self.datagroups["ResidencePermit2"] if "ResidencePermit2" in self.datagroups else 'ResidencePermit1 field up to 250 characters' ResidencePermit2 = self.datagroups["ResidencePermit2"] if "ResidencePermit2" in self.datagroups else 'ResidencePermit1 field up to 250 characters'
@@ -278,9 +281,8 @@ class CardGenerator(object):
])])], True) ])])], True)
else: else:
dg17 = None dg17 = None
#FIXME: Dataset file with CommunityID =<NotOnChip> still not works while assigning of non hex value due to eval()
if (CommunityID.rstrip() != "<NotOnChip>"): if (CommunityID.rstrip() != "<NotOnChip>"):
dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID)])], True) dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID_Binary)])], True)
else: else:
dg18 = None dg18 = None
if (ResidencePermit1.rstrip() != "<NotOnChip>"): if (ResidencePermit1.rstrip() != "<NotOnChip>"):
@@ -458,6 +460,7 @@ class CardGenerator(object):
splitLine = line.split("=") splitLine = line.split("=")
# we don't want to have the newline char from dataset file as part of the value!! # we don't want to have the newline char from dataset file as part of the value!!
self.datagroups[splitLine[0]] = splitLine[1].rstrip("\n\r") self.datagroups[splitLine[0]] = splitLine[1].rstrip("\n\r")
logging.info("Dataset value for "+splitLine[0].rstrip()+": '"+splitLine[1].rstrip("\n\r")+"'")
if __name__ == "__main__": if __name__ == "__main__":
from optparse import OptionParser from optparse import OptionParser