def decrypt_text(project_id, text): private_key_file = key_path(project_id) if not os.path.exists(private_key_file): raise exception.ProjectNotFound(project_id=project_id) with open(private_key_file, 'rb') as f: data = f.read() try: priv_key = serialization.load_pem_private_key( data, None, backends.default_backend()) return priv_key.decrypt(text, padding.PKCS1v15()) except (ValueError, TypeError, exceptions.UnsupportedAlgorithm) as exc: raise exception.DecryptionFailure(reason=six.text_type(exc))
def decrypt_text(project_id, text): private_key = key_path(project_id) if not os.path.exists(private_key): raise exception.ProjectNotFound(project_id=project_id) try: dec, _err = utils.execute('openssl', 'rsautl', '-decrypt', '-inkey', '%s' % private_key, process_input=text) return dec except processutils.ProcessExecutionError as exc: raise exception.DecryptionFailure(reason=exc.stderr)
def _ssh_decrypt_text(self, ssh_private_key, text): with utils.tempdir() as tmpdir: sshkey = os.path.abspath(os.path.join(tmpdir, 'ssh.key')) with open(sshkey, 'w') as f: f.write(ssh_private_key) try: dec, _err = utils.execute('openssl', 'rsautl', '-decrypt', '-inkey', sshkey, process_input=text) return dec except processutils.ProcessExecutionError as exc: raise exception.DecryptionFailure(reason=exc.stderr)