From c4790e02b3482a9876cfcc25bfd3bd810ddc2da6 Mon Sep 17 00:00:00 2001 From: psytester Date: Fri, 23 Jan 2015 12:49:33 +0100 Subject: [PATCH] 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 ;-) --- .../Example_Dataset_Mueller_Gertrud.txt | 3 +-- .../src/vpicc/virtualsmartcard/CardGenerator.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/virtualsmartcard/npa-example-data/Example_Dataset_Mueller_Gertrud.txt b/virtualsmartcard/npa-example-data/Example_Dataset_Mueller_Gertrud.txt index 29485cf..cd2eda8 100644 --- a/virtualsmartcard/npa-example-data/Example_Dataset_Mueller_Gertrud.txt +++ b/virtualsmartcard/npa-example-data/Example_Dataset_Mueller_Gertrud.txt @@ -1,6 +1,5 @@ # This is an example dataset file for the virtual smartcard. # 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 # command line option -d, with or without path. # @@ -32,7 +31,7 @@ Country=D City=BREMEN ZIP=28195 Street=STADTMUSIKANTENWEG 12a -CommunityID='\x02\x76\x03\x02\x54\x00\x21' +CommunityID=02760302540021 # ResidencePermit1 and ResidencePermit2 are part of eAT only ResidencePermit1=Nebenbestimmungen I Text...(up to 750 characters) diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py b/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py index bd16bc3..be2482f 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py @@ -17,7 +17,7 @@ # virtualsmartcard. If not, see . # -import sys, getpass, anydbm, logging +import sys, getpass, anydbm, logging, binascii from pickle import loads, dumps from virtualsmartcard.TLVutils import pack, unpack from virtualsmartcard.utils import inttostring @@ -192,7 +192,10 @@ class CardGenerator(object): City = self.datagroups["City"] if "City" in self.datagroups else 'KOLN' ZIP = self.datagroups["ZIP"] if "ZIP" in self.datagroups else '51147' 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() != ""): + # 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 = 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' @@ -204,7 +207,7 @@ class CardGenerator(object): dg16_param = self.datagroups["dg16"] if "dg16" in self.datagroups else '' dg21_param = self.datagroups["dg21"] if "dg21" in self.datagroups else '' - # "Attribute not on Chip" makes sence only for ReligiousArtisticName, Nationality, BirthName, ResidencePermit1 and ResidencePermit2, refer to BSI TR-03127 + # "Attribute not on Chip" makes sence only for ReligiousArtisticName, Nationality, BirthName, ResidencePermit1 and ResidencePermit2, refer to BSI TR-03127 if (DocumentType.rstrip() != ""): dg1 = pack([(0x61, 0, [(0x13, 0, DocumentType)])], True) else: @@ -278,9 +281,8 @@ class CardGenerator(object): ])])], True) else: dg17 = None - #FIXME: Dataset file with CommunityID = still not works while assigning of non hex value due to eval() if (CommunityID.rstrip() != ""): - dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID)])], True) + dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID_Binary)])], True) else: dg18 = None if (ResidencePermit1.rstrip() != ""): @@ -296,7 +298,7 @@ class CardGenerator(object): else: dg21 = None - # If eid.append is not done for a DG, it results into required SwError() with FileNotFound "6A82" APDU return code + # If eid.append is not done for a DG, it results into required SwError() with FileNotFound "6A82" APDU return code if dg1: eid.append(TransparentStructureEF(parent=eid, fid=0x0101, shortfid=0x01, data=dg1)) if dg2: @@ -458,6 +460,7 @@ class CardGenerator(object): splitLine = line.split("=") # 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") + logging.info("Dataset value for "+splitLine[0].rstrip()+": '"+splitLine[1].rstrip("\n\r")+"'") if __name__ == "__main__": from optparse import OptionParser