Exemple #1
0
r = None

APPLET = False
READER_NUM = 2
APPLET_PATH = "D:\\download\\epassport_emulator_v1.02\\epassport.cap"
MRZ = "EG491433<0BEL8305099M1208157<<<<<<<<<<<<<<04"
DUMP_DIR = "../testData"

if not Sim:
    print("Put the original ePassport on the reader")
    r = reader.ReaderManager().waitForCard()
else:
    r = reader.ReaderManager().create("DumpReader")
    r.format = converter.types.GRT
    r.ext = ".bin"
    r.connect(DUMP_DIR)

ep = epassport.EPassport(r, MRZ)
ep.readPassport()

if APPLET:
    input("Applet upload: Put the JCOP on the reader, and press a key")
    jc = jcop.GPlatform(READER_NUM)
    jc.install(APPLET_PATH)

input("Dumps upload: Put the JCOP on the reader, and press a key")
r = reader.ReaderManager().waitForCard()
epc = epassportcreation.EPassportCreator(None, None, r)
epc.setEPassport(ep)
print(epc.toJCOP())
def generate(   firstname,
                surname,
                sex,
                dob,
                nationality,
                id_doc,
                doe,
                issuer,
                face_path,
                country,
                organisation,
                pob,
                middle_name,
                issuing_auth,
                doi,
                height,
                eyes,
                address,
                update = True,
                cap_path = None):


    if firstname == "": firstname = "John"
    if surname == "": surname = "Doe"
    if sex == "": sex = "M"
    if dob == "YYYY/MM/DD": dob = "1970/01/01"
    if nationality == "": nationality = "BEL"
    if id_doc == "": id_doc = "EH123456"
    if doe == "YYYY/MM/DD": doe = datetime.date.today().strftime("%Y/%m/%d")
    if issuer == "": issuer = "BEL"
    if face_path == "": face_path = "epassportviewer/ressources/face.jpg"
    if country == "": country = "BEL"
    if organisation == "": organisation = "UCL"
    if doi == "YYYY/MM/DD": doi = None


    date_cmp = doe.split("/")
    doe = datetime.date(int(date_cmp[0]), int(date_cmp[1]), int(date_cmp[2]))

    date_cmp = dob.split("/")
    dob = datetime.date(int(date_cmp[0]), int(date_cmp[1]), int(date_cmp[2]))


    ###################
    #       CA        #
    ###################

    # Create a fake Country Signer Certification Authority
    CSCA = pki.DistinguishedName(C=country[:2], O=organisation, CN="CSCA")

    # Create a fake Document Signer bond to CSCA
    DS = pki.DistinguishedName(C=country[:2], O=organisation, CN="Document-Signer")

    ca = pki.CA()
    (csca, cscaKey) = ca.createCSCA(1024, 720, CSCA)
    (ds, dsKey) = ca.createDS(1024, 365, DS)


    ###################
    #    DATAGROUP    #
    ###################



    # Create DataGroup 1 (MRZ) [mandatory]
    dg1 = datagroupcreation.DataGroup1Creation().create("P", issuer, surname, firstname, nationality, sex, id_doc, dob.strftime("%d%m%y"), doe.strftime("%d%m%y"))

    # Create DataGroup 2 (Face) [Mandatory]
    dg2 = datagroupcreation.DataGroup2Creation().create(face_path)

    dgs = [dg1, dg2]

    # Create DataGroup 11 (Additional document holder information) [Optional]
    if pob or middle_name:
        dgc = datagroupcreation.DataGroupFileCreation(converter.toTAG("DG11"))
        content = ""

        # Full name
        if middle_name:
            middle_name = middle_name.replace(' ', '<')
            full_name = surname.upper() + "<<" + firstname.upper() + middle_name.upper()
            dgc.addDataObject("5F02", full_name)

        # Place of birth
        if pob:
            pob = pob.replace(' ', '<')
            dgc.addDataObject("5F11", pob)
            content += "5F11"

        dgc.addDataObject("5C", hexfunctions.hexRepToBin("5F11"))

        dg11 = datagroup.DataGroupFactory().create(dgc)
        dgs.append(dg11)

    # Create DataGroup 12 (Additional document information) [Optional]
    if issuing_auth or doi:
        dgc = datagroupcreation.DataGroupFileCreation(converter.toTAG("DG12"))
        content = ""

        # Issuing authority
        if issuing_auth:
            dgc.addDataObject("5F19", issuing_auth)
            content += "5F19"
        # Date of issue
        if doi:
            date_cmp = doi.split("/")
            doi = datetime.date(int(date_cmp[0]), int(date_cmp[1]), int(date_cmp[2]))

            dgc.addDataObject("5F26", doi.strftime("%Y%m%d"))
            content += "5F26"

        dgc.addDataObject("5C", hexfunctions.hexRepToBin(content))

        dg12 = datagroup.DataGroupFactory().create(dgc)
        dgs.append(dg12)

    # Create DataGroup 13 (Reserved for national specific data) [Optional]
    if height or eyes or address:
        print "DG13"
        dgc = datagroupcreation.DataGroupFileCreation(converter.toTAG("DG13"))

        content = ""

        # Height
        if height:
            dgc.addDataObject("9F01", height)
            content += "9F01"
        # Eyes
        if eyes:
            dgc.addDataObject("9F02", eyes)
            content += "9F02"
        # Address
        if address:
            dgc.addDataObject("9F03", address)
            content += "9F03"

        dgc.addDataObject("5C", hexfunctions.hexRepToBin(content))

        dg13 = datagroup.DataGroupFactory().create(dgc)
        dgs.append(dg13)




    # Create presence map [mandatory]
    com = datagroupcreation.ComCreation().create(dgs)
    # Create a signer data strcture [mandatory]
    sod = datagroupcreation.SODCreation().create(ds, dsKey, dgs)

    dgs.append(com)
    dgs.append(sod)


    ###################
    #      JCOP       #
    ###################

    # Initializing the GPlatform object with the reader #1
    if not update:
        jc = jcop.GPlatform(reader_nb)
        jc.install(cap_path)

    r = readerAbstract.waitForCard()
    jcw = jcop.JavaCardWritter(r)


    # Write the forged ePassport in the JCOP
    for dg in dgs:
        jcw.writeDG(dg)
    jcw.setKseed(dg1)