Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide value for CommunityID as readable digit-string now #37

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# virtualsmartcard. If not, see <https://www.gnu.org/licenses/>.
#

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
Expand Down Expand Up @@ -192,7 +192,10 @@ def __generate_nPA(self):
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() != "<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 = 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'
Expand All @@ -204,7 +207,7 @@ def __generate_nPA(self):
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() != "<NotOnChip>"):
dg1 = pack([(0x61, 0, [(0x13, 0, DocumentType)])], True)
else:
Expand Down Expand Up @@ -278,9 +281,8 @@ def __generate_nPA(self):
])])], True)
else:
dg17 = None
#FIXME: Dataset file with CommunityID =<NotOnChip> still not works while assigning of non hex value due to eval()
if (CommunityID.rstrip() != "<NotOnChip>"):
dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID)])], True)
dg18 = pack([(0x72, 0, [(0x04, 0, CommunityID_Binary)])], True)
else:
dg18 = None
if (ResidencePermit1.rstrip() != "<NotOnChip>"):
Expand All @@ -296,7 +298,7 @@ def __generate_nPA(self):
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:
Expand Down Expand Up @@ -458,6 +460,7 @@ def readDatagroups(self, datasetfile):
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
Expand Down