Exemple #1
0
    def __init__(self, reader, epMrz=None):
        """ 
        This object provide most of the functionnalities described in the EPassport document.
            - The basic acces control + secure messaging
            - The active authentication
            - The passive authentication
            - Reading of the various dataGroups
        
        @param reader: It can be a reader or a path to dumps
        @type reader: A reader object, then it will use the specified rfid reader. 
                      A string, then the simulator will read the dumps from the specified url.  
        
        @param mrz: An object representing the passport MRZ.
        @type mrz: An MRZ object 
        """
        logger.Logger.__init__(self, "EPassport")

        if epMrz:
            self._mrz = mrz.MRZ(epMrz)
            if self._mrz.checkMRZ() == False:
                raise EPassportException("Invalid MRZ")
        else:
            self._mrz = None

        self._iso7816 = iso7816.Iso7816(reader)
        self._iso7816.register(self._logFct)

        self._dgReader = datagroup.DataGroupReaderFactory().create(
            self._iso7816)
        self._dgReader.register(self._logFct)

        self._bac = bac.BAC(self._iso7816)
        self._bac.register(self._logFct)

        self._openSSL = openssl.OpenSSL()
        self._openSSL.register(self._logFct)

        self._aa = activeauthentication.ActiveAuthentication(
            self._iso7816, self._openSSL)
        self._aa.register(self._logFct)

        self._pa = passiveauthentication.PassiveAuthentication(self._openSSL)
        self._pa.register(self._logFct)

        self._CSCADirectory = None
        self._selectPassportApp()
    def __init__(self, epassport, certdir=None, callback=None):
        self._doc = epassport
        self.curMRZ = None
        self._comm = self._doc.getCommunicationLayer()
        self._pa = passiveauthentication.PassiveAuthentication(epassport)
        self._certInfo = None
        self.callback = callback
        self.doPA = False

        if certdir:
            try:
                self.csca = camanager.CAManager(certdir)
                self.csca.toHashes()
                self.doPA = True
            except Exception:
                pass

        self._comm.rstConnection()
        if sod != None:
            with open('sod', 'wb') as fd:
                fd.write(sod.body)
            f = os.popen("openssl asn1parse -in sod -inform DER -i")
            res["SOD"] = f.read().strip()
            os.remove('sod')

            #Verify SOD body
            if self.callback:
                self.callback.put((None, 'slfp', "Verify SOD with CSCA"))
                self.callback.put((None, 'fp', 50))

            if self.doPA:
                try:
                    pa = passiveauthentication.PassiveAuthentication()
                    res["verifySOD"] = pa.verifySODandCDS(sod, self.csca)
                except Exception:
                    res["verifySOD"] = "No certificate imported verify the SOD"
                    pass

        #Read DGs and get the file content
        if self.callback:
            self.callback.put((None, 'slfp', "Read DGs"))
            self.callback.put((None, 'fp', 55))

        self._comm.rstConnection()
        data = {}
        start = time.time()
        res["EP"]["Common"] = self._doc["Common"]
        for dg in res["EP"]["Common"]["5C"]: