示例#1
0
 def decrypt(self, container="", keyid=None, passphrase=None):
     """
     Decrypts the data stored inside self.{{container}} using the specified
     keyid and passphrase. Outputs the decrypted data as a json string.
     """
     if not keyid:
         keyid = self.keyfp
     if not passphrase:
         try:
             passphrase = self.pwd
         except AttributeError:
             if settings.VERBOSE:
                 print "trying to decrypt, but no passphrase -- exiting."
                 traceback.print_stack(file=sys.stdout)
             return ""
     data = getattr(self, container+"_data", "")
     if settings.VERBOSE:
         print "########"
         print "Decrypting data from %s's container %s with key %s " \
             "passphrase %s*" % (self.uid, container, keyid, passphrase[0:3])
         print "DATA:\n%s" % data
     decrypted_data = msg_decrypt (str(data), keyid, passphrase)
     if settings.VERBOSE:
         print "Decrypted data:\n %s\n\n\n\n" % decrypted_data.data
     return decrypted_data.data
示例#2
0
    def read_dropped_msg(self, friend, keyid=None, passphrase=None):
        """
        Return the content of dropped_signal of the given friendProfile.
        If the keyid can not decrypt the contents, return None.
        """
        if keyid is None:
            keyid = self.keyfp
        if passphrase is None:
            try:
                passphrase = self.pwd
            except AttributeError:
                if settings.VERBOSE:
                    print "trying to decrypt, but no passphrase given. exiting."
                traceback.print_stack(file=sys.stdout)
                return None

        data = getattr(friend, "dropped_signal", "")
        if settings.VERBOSE:
            print "########"
            print "Decrypting the dropped message from %s's profile with key " \
                "%s passphrase %s*" % (friend.id, keyid, passphrase[0:3])
            print "DATA:\n%s" % data
        decrypted_data = msg_decrypt (str(data), keyid, passphrase)
        if settings.VERBOSE:
            print "Decrypted data:\n %s\n\n\n\n" % decrypted_data.data
        return decrypted_data.data or None