Code style improvements

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@467 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-07-29 20:40:38 +00:00
parent be448f9001
commit 28972ee5be

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, readline, os, dircache import sys, getpass, anydbm, readline, dircache
from pickle import loads, dumps from pickle import loads, dumps
from TLVutils import pack from TLVutils import pack
from virtualsmartcard.utils import inttostring from virtualsmartcard.utils import inttostring
@@ -36,10 +36,10 @@ from virtualsmartcard.SmartcardFilesystem import *
class CardGenerator(object): class CardGenerator(object):
def __init__(self, type=None, sam=None, mf=None): def __init__(self, card_type=None, sam=None, mf=None):
self.type = type self.type = card_type
self.mf = None self.mf = mf
self.sam = None self.sam = sam
def __generate_iso_card(self): def __generate_iso_card(self):
from virtualsmartcard.SmartcardSAM import SAM from virtualsmartcard.SmartcardSAM import SAM
@@ -47,7 +47,7 @@ class CardGenerator(object):
print "Using default SAM. Insecure!!!" print "Using default SAM. Insecure!!!"
self.sam = SAM("1234", "1234567890") #FIXME: Use user provided data self.sam = SAM("1234", "1234567890") #FIXME: Use user provided data
self.mf = MF(filedescriptor=FDB["DF"], lifecycle=LCB["ACTIVATED"], dfname=None) self.mf = MF(filedescriptor=FDB["DF"])
self.sam.set_MF(self.mf) self.sam.set_MF(self.mf)
def __generate_ePass(self): def __generate_ePass(self):
@@ -81,34 +81,43 @@ class CardGenerator(object):
mf = MF() mf = MF()
#We need a MF with Application DF \xa0\x00\x00\x02G\x10\x01 #We need a MF with Application DF \xa0\x00\x00\x02G\x10\x01
df = DF(parent=mf, fid=4, dfname='\xa0\x00\x00\x02G\x10\x01', bertlv_data=[]) df = DF(parent=mf, fid=4, dfname='\xa0\x00\x00\x02G\x10\x01',
bertlv_data=[])
#EF.COM #EF.COM
COM = pack([(0x5F01,4,"0107"),(0x5F36,6,"040000"),(0x5C,2,"6175")]) COM = pack([(0x5F01, 4, "0107"), (0x5F36, 6, "040000"),
COM = pack(((0x60,len(COM),COM),)) (0x5C, 2, "6175")])
df.append(TransparentStructureEF(parent=df, fid=0x011E, filedescriptor=0, data=COM)) COM = pack(((0x60, len(COM), COM),))
df.append(TransparentStructureEF(parent=df, fid=0x011E,
filedescriptor=0, data=COM))
#EF.DG1 #EF.DG1
DG1 = pack([(0x5F1F,len(MRZ),MRZ)]) DG1 = pack([(0x5F1F, len(MRZ), MRZ)])
DG1 = pack([(0x61,len(DG1),DG1)]) DG1 = pack([(0x61, len(DG1), DG1)])
df.append(TransparentStructureEF(parent=df, fid=0x0101, filedescriptor=0, data=DG1)) df.append(TransparentStructureEF(parent=df, fid=0x0101,
filedescriptor=0, data=DG1))
#EF.DG2 #EF.DG2
if picture != None: if picture != None:
IIB = "\x00\x01" + inttostring(pic_width,2) + inttostring(pic_height,2) + 6 * "\x00" IIB = "\x00\x01" + inttostring(pic_width, 2) +\
inttostring(pic_height, 2) + 6 * "\x00"
length = 32 + len(picture) #32 is the length of IIB + FIB length = 32 + len(picture) #32 is the length of IIB + FIB
FIB = inttostring(length,4) + 16 * "\x00" FIB = inttostring(length, 4) + 16 * "\x00"
FRH = "FAC" + "\x00" + "010" + "\x00" + inttostring(14+length,4) + inttostring(1,2) FRH = "FAC" + "\x00" + "010" + "\x00" +\
inttostring(14 + length, 4) + inttostring(1, 2)
picture = FRH + FIB + IIB + picture picture = FRH + FIB + IIB + picture
DG2 = pack([(0xA1,8,"\x87\x02\x01\x01\x88\x02\x05\x01"),(0x5F2E,len(picture),picture)]) DG2 = pack([(0xA1, 8, "\x87\x02\x01\x01\x88\x02\x05\x01"),
DG2 = pack([(0x02,1,"\x01"),(0x7F60,len(DG2),DG2)]) (0x5F2E, len(picture), picture)])
DG2 = pack([(0x7F61,len(DG2),DG2)]) DG2 = pack([(0x02, 1, "\x01"), (0x7F60, len(DG2), DG2)])
DG2 = pack([(0x7F61, len(DG2), DG2)])
else: else:
DG2="" DG2 = ""
df.append(TransparentStructureEF(parent=df, fid=0x0102, filedescriptor=0, data=DG2)) df.append(TransparentStructureEF(parent=df, fid=0x0102,
filedescriptor=0, data=DG2))
#EF.SOD #EF.SOD
df.append(TransparentStructureEF(parent=df, fid=0x010D, filedescriptor=0, data="")) df.append(TransparentStructureEF(parent=df, fid=0x010D,
filedescriptor=0, data=""))
mf.append(df) mf.append(df)
@@ -119,7 +128,8 @@ class CardGenerator(object):
from virtualsmartcard.SmartcardSAM import CryptoflexSAM from virtualsmartcard.SmartcardSAM import CryptoflexSAM
self.mf = CryptoflexMF() self.mf = CryptoflexMF()
self.mf.append(TransparentStructureEF(parent=self.mf, fid=0x0002, filedescriptor=0x01, self.mf.append(TransparentStructureEF(parent=self.mf, fid=0x0002,
filedescriptor=0x01,
data="\x00\x00\x00\x01\x00\x01\x00\x00")) #EF.ICCSN data="\x00\x00\x00\x01\x00\x01\x00\x00")) #EF.ICCSN
self.sam = CryptoflexSAM(self.mf) self.sam = CryptoflexSAM(self.mf)