Exemplo n.º 1
0
    def decrypt_masterkey_bytes(self, data, key=None):
        """
		Decrypts Masterkeyfile bytes
		data: bytearray of the masterkeyfile
		key: bytes describing the key used for decryption
		returns: touple of dictionaries. [0] - > masterkey[guid] = key, [1] - > backupkey[guid] = key
		"""
        mkf = MasterKeyFile.from_bytes(data)

        mks = {}
        bks = {}
        if mkf.masterkey is not None:
            for user_key in self.user_keys:
                dec_key = mkf.masterkey.decrypt(user_key)
                if dec_key:
                    self.masterkeys[mkf.guid] = dec_key
                    mks[mkf.guid] = dec_key

            for machine_key in self.machine_keys:
                dec_key = mkf.masterkey.decrypt(machine_key)
                if dec_key:
                    self.masterkeys[mkf.guid] = dec_key
                    mks[mkf.guid] = dec_key

            if key is not None:
                dec_key = mkf.masterkey.decrypt(key)
                if dec_key:
                    self.masterkeys[mkf.guid] = dec_key
                    mks[mkf.guid] = dec_key

        if mkf.backupkey is not None:
            for user_key in self.user_keys:
                dec_key = mkf.backupkey.decrypt(user_key)
                if dec_key:
                    self.backupkeys[mkf.guid] = dec_key
                    bks[mkf.guid] = dec_key

            for machine_key in self.machine_keys:
                dec_key = mkf.backupkey.decrypt(machine_key)
                if dec_key:
                    self.backupkeys[mkf.guid] = dec_key
                    bks[mkf.guid] = dec_key

            if key is not None:
                dec_key = mkf.backupkey.decrypt(key)
                if dec_key:
                    self.masterkeys[mkf.guid] = dec_key
                    bks[mkf.guid] = dec_key

        return mks, bks
Exemplo n.º 2
0
    def decrypt_masterkey_bytes(self, data, key=None):
        """
		Decrypts Masterkeyfile bytes
		data: bytearray of the masterkeyfile
		key: bytes describing the key used for decryption
		returns: touple of dictionaries. [0] - > masterkey[guid] = key, [1] - > backupkey[guid] = key
		"""
        mkf = MasterKeyFile.from_bytes(data)

        mks = {}
        bks = {}
        if mkf.masterkey is not None:
            if mkf.guid in self.masterkeys:
                mks[mkf.guid] = self.masterkeys[mkf.guid]

            else:
                for user_key in self.prekeys:
                    dec_key = mkf.masterkey.decrypt(user_key)
                    if dec_key:
                        logger.debug('user key win: %s' % user_key.hex())
                        self.masterkeys[mkf.guid] = dec_key
                        mks[mkf.guid] = dec_key
                        break

                if key is not None:
                    dec_key = mkf.masterkey.decrypt(key)
                    if dec_key:
                        self.masterkeys[mkf.guid] = dec_key
                        mks[mkf.guid] = dec_key

        if mkf.backupkey is not None:
            if mkf.guid in self.masterkeys:
                mks[mkf.guid] = self.masterkeys[mkf.guid]

            else:
                for user_key in self.prekeys:
                    dec_key = mkf.backupkey.decrypt(user_key)
                    if dec_key:
                        self.backupkeys[mkf.guid] = dec_key
                        bks[mkf.guid] = dec_key
                        break

                if key is not None:
                    dec_key = mkf.backupkey.decrypt(key)
                    if dec_key:
                        self.masterkeys[mkf.guid] = dec_key
                        bks[mkf.guid] = dec_key

        return mks, bks