Ejemplo n.º 1
0
 def Valid(self):
     """
     Validate signature to verify the ``encrypted_block``.
     """
     if not self.Ready():
         lg.warn("block is not ready yet " + str(self))
         return False
     hashsrc = self.GenerateHash()
     ConIdentity = contactsdb.get_contact_identity(my_id.getLocalID())
     if ConIdentity is None:
         lg.warn("could not get Identity so returning False")
         return False
     result = key.Verify(ConIdentity, hashsrc, self.Signature)    # At block level only work on own stuff
     return result
Ejemplo n.º 2
0
    def SignatureChecksOut(self, raise_signature_invalid=False):
        """
        This check correctness of signature, uses ``crypt.key.Verify``. To
        verify we need 3 things:

        - the packet ``Creator`` identity ( it keeps the public key ),
        - hash of that packet - just call ``GenerateHash()`` to make it,
        - the signature itself.
        """
        CreatorIdentity = contactsdb.get_contact_identity(self.CreatorID)
        if CreatorIdentity is None:
            # OwnerIdentity = contactsdb.get_contact_identity(self.OwnerID)
            # if OwnerIdentity is None:
            #     lg.err("could not get Identity for %s so returning False" % self.CreatorID.to_text())
            #     return False
            # CreatorIdentity = OwnerIdentity
            if raise_signature_invalid:
                raise Exception(
                    'can not verify signed packet, unknown identity %r' %
                    self.CreatorID)
            lg.err("could not get Identity for %r so returning False" %
                   self.CreatorID)
            return False


#         if _Debug:
#             if _LogSignVerify:
#                 try:
#                     from main import settings
#                     try:
#                         from Cryptodome.Util import number
#                     except:
#                         from Crypto.Util import number  # @UnresolvedImport @Reimport
#                     open(os.path.join(settings.LogsDir(), 'crypt.log'), 'wb').write(b'\SignatureChecksOut:\n' + strng.to_bin(number.long_to_bytes(self.Signature)) + b'\n\n')
#                 except:
#                     lg.exc()

        Result = key.Verify(CreatorIdentity, self.GenerateHash(),
                            self.Signature)

        #         if _Debug:
        #             if _LogSignVerify:
        #                 try:
        #                     from main import settings
        #                     open(os.path.join(settings.LogsDir(), 'crypt.log'), 'wb').write(b'\Result:' + strng.to_bin(str(Result)) + b'\n\n')
        #                 except:
        #                     lg.exc()

        return Result
Ejemplo n.º 3
0
    def SignatureChecksOut(self):
        """
        This check correctness of signature, uses ``crypt.key.Verify``. To
        verify we need 3 things:

        - the packet ``Creator`` identity ( it keeps the public key ),
        - hash of that packet - just call ``GenerateHash()`` to make it,
        - the signature itself.
        """
        CreatorIdentity = contactsdb.get_contact_identity(self.CreatorID)
        if CreatorIdentity is None:
            OwnerIdentity = contactsdb.get_contact_identity(self.OwnerID)
            if OwnerIdentity is None:
                lg.out(1, "signed.SignatureChecksOut ERROR could not get Identity for " + self.CreatorID + " so returning False")
                return False
            CreatorIdentity = OwnerIdentity
        Result = key.Verify(CreatorIdentity, self.GenerateHash(), self.Signature)
        return Result
Ejemplo n.º 4
0
 def Valid(self):
     """
     Validate signature to verify the ``encrypted_block``.
     Not used at the moment.
     """
     if not self.Ready():
         lg.warn("block is not ready yet " + str(self))
         return False
     # TODO: make possible to verify signature using `signing_key`
     hashsrc = self.GenerateHash()
     ConIdentity = my_id.getLocalIdentity()
     if ConIdentity is None:
         lg.warn("could not get Identity so returning False")
         return False
     result = key.Verify(
         ConIdentity, hashsrc,
         self.Signature)  # At block level only work on own stuff
     return result