def _decrypt_password_data(self, parsed, **kwargs):
"""
This handler gets called after the GetPasswordData command has been
executed. It is called with the and the ``parsed`` data. It checks to
see if a private launch key was specified on the command. If it was,
it tries to use that private key to decrypt the password data and
replace it in the returned data dictionary.
"""
if self._key_path is not None:
logger.debug("Decrypting password data using: %s", self._key_path)
value = parsed.get('PasswordData')
if not value:
return
try:
with open(self._key_path) as pk_file:
pk_contents = pk_file.read()
private_key = rsa.PrivateKey.load_pkcs1(six.b(pk_contents))
value = base64.b64decode(value)
value = rsa.decrypt(value, private_key)
logger.debug(parsed)
parsed['PasswordData'] = value.decode('utf-8')
logger.debug(parsed)
except Exception:
logger.debug('Unable to decrypt PasswordData', exc_info=True)
msg = ('Unable to decrypt password data using '
'provided private key file.')
raise ValueError(msg)
评论列表
文章目录