Ejemplo n.º 1
0
 def _getDG(self, tag):
     """ 
     Read the dataGroup file specified by the parameter 'tag', then try to parse it.
     The dataGroup object is then stored in the object dictionnary.
     
     
     @param tag: The dataGroup identifier to read (see the dataGroups.converter for all valid representations)
     @type tag: A string
     
     @return: An dataGroup object if the file is read with success.
     @rtype: An DataGroupXX object
     
     @raise DataGroupException: If a wrong DataGroup is requested
     """
     try:
         self.log("Reading " + converter.toDG(tag))
         dgFile = self._dgReader.readDG(tag)
         self.log("File " + str(dgFile))
         dg = datagroup.DataGroupFactory().create(dgFile)
         self.log("DG " + str(dg))
         self.__setitem__(dg.tag, dg)
         return dg
     except IOError as msg:
         self.log("Reading error: " + str(msg))
         raise datagroup.DataGroupException(msg)
Ejemplo n.º 2
0
 def create(self, dgFile):
     dg = eval(converter.toClass(dgFile.tag))(dgFile)
     try:
         dg.parse()
     except Exception as msg:
         self.log("Parsing failed: " + str(msg), converter.toDG(dg.tag))
     return dg
Ejemplo n.º 3
0
 def readCom(self):
     """
     Read the common file of the passport.
     
     @return: A list with the data group tags present in the passport. 
     """
     list = []
     for tag in self["Common"]["5C"]:
         list.append(converter.toDG(tag))
     return list
    def _compareHashes(self, hashes):
        """
        Compare the calculated hashes with the corresponding hashes present in the SOD.

        @param hashes: A dictionary of hashes to compare with the security object hashes.
        @type hashes: A dictionary
        @return: A dictionary indexed with the DG name (DG1..DG15) and with the result of the hash comparison (True or False, None if the DG is not present in the SOD)
        """
        self.log("Compare the calculated hashes with the corresponding hash values in the SOD")

        res = {}

        for dg in hashes:
            try:
                res[converter.toDG(dg)] = (hashes[dg] == self._content["dataGroupHashValues"][converter.toOther(dg)])
            except KeyError:
                res[converter.toDG(dg)] = None

        return res
Ejemplo n.º 5
0
    def readCom(self):
        """
        Read the common file of the passport.

        @return: A list with the data group tags present in the passport.
        """
        list = []
        for tag in self["Common"]["5C"]:
            list.append(converter.toDG(tag))
        return list
Ejemplo n.º 6
0
    def _compareHashes(self, hashes):
        """
        Compare the calculated hashes with the corresponding hashes present in the SOD.

        @param hashes: A dictionary of hashes to compare with the security object hashes.
        @type hashes: A dictionary
        @return: A dictionary indexed with the DG name (DG1..DG15) and with the result of the hash comparison (True or False, None if the DG is not present in the SOD)
        """
        self.log(
            "Compare the calculated hashes with the corresponding hash values in the SOD"
        )

        res = {}

        for dg in hashes:
            try:
                res[converter.toDG(dg)] = (
                    hashes[dg] == self._content["dataGroupHashValues"][
                        converter.toOther(dg)])
            except KeyError:
                res[converter.toDG(dg)] = None

        return res
Ejemplo n.º 7
0
    def _calculateHashes(self, dgs):
        """
        Calculate the hashes of the relevant Data Groups, theses presents in the signature.

        @param dgs: A list of dataGroup objects to calculate the hash values.
        @type dgs: A list.
        @return: A dictionary indexed with DG1..DG15 with the calculated hashes of the DGs.
        """
        self.log("Calculate the hashes of the relevant Data Groups")
        hashes = {}
        #Find the hash function from the content dictionary
        hashAlgo = self._getHashAlgorithm()
        for dg in dgs:
            res = hashAlgo(dg.file)
            hashes[converter.toDG(dg.tag)] = res.digest()

        return hashes
    def _calculateHashes(self, dgs):
        """
        Calculate the hashes of the relevant Data Groups, theses presents in the signature.

        @param dgs: A list of dataGroup objects to calculate the hash values.
        @type dgs: A list.
        @return: A dictionary indexed with DG1..DG15 with the calculated hashes of the DGs.
        """
        self.log("Calculate the hashes of the relevant Data Groups")
        hashes = {}
        #Find the hash function from the content dictionary
        hashAlgo = self._getHashAlgorithm()
        for dg in dgs:
            res = hashAlgo(dg.file)
            hashes[converter.toDG(dg.tag)] = res.digest()

        return hashes
Ejemplo n.º 9
0
    def _getDG(self, tag):
        """
        Read the dataGroup file specified by the parameter 'tag', then try to parse it.
        The dataGroup object is then stored in the object dictionary.


        @param tag: The dataGroup identifier to read (see the dataGroups.converter for all valid representations)
        @type tag: A string

        @return: A dataGroup object if the file is read with success.
        @rtype: An DataGroupXX object

        @raise DataGroupException: If a wrong DataGroup is requested
        """
        try:
            self.log("Reading " + converter.toDG(tag))
            dgFile = self._dgReader.readDG(tag)
            dg = datagroup.DataGroupFactory().create(dgFile)
            self.__setitem__(dg.tag, dg)
            return dg
        except IOError, msg:
            self.log("Reading error: " + str(msg))
            raise datagroup.DataGroupException(msg)
Ejemplo n.º 10
0
 def create(self, dgFile):
     dg = eval(converter.toClass(dgFile.tag))(dgFile)
     try:
         dg.parse()
     except Exception, msg:
         self.log("Parsing failed: " + str(msg), converter.toDG(dg.tag))