Skip to content

Commit

Permalink
Don't filter GPG debug outputs, but send everything to PassFF
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Vogt committed Dec 1, 2023
1 parent 8daa5e4 commit e45d99d
Showing 1 changed file with 1 addition and 37 deletions.
38 changes: 1 addition & 37 deletions src/passff.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,6 @@ def setPassGpgOpts(env, opts_dict):
env['PASSWORD_STORE_GPG_OPTS'] = opts.strip()


def getGpgCodesFromStderr(stderr):
messages = []
for line in stderr.split("\n"):
# append gpg indented line continuation to previous message
if len(messages) > 0 and line.startswith(' '):
messages[-1] += f"\n{line}"
else:
messages.append(line)

# extract GPG error codes from status and debug messages
# https://github.com/gpg/libgpg-error/blob/master/src/err-codes.h.in
gpg_error_code = 0
for msg in messages:
if msg.startswith('gpg: DBG:'):
m = re.search(r'chan_\d+ (?:<-|->) ERR (\d+)', msg)
if m is not None:
gpg_error_code = int(m.group(1)) & 0xFFFF
elif msg.startswith("[GNUPG:]"):
m = re.search(r'ERROR pkdecrypt_failed (\d+)', msg)
if m is not None:
gpg_error_code = int(m.group(1)) & 0xFFFF
elif 'NO_SECKEY' in line:
gpg_error_code = 17

# filter out debug and status outputs
stderr_filtered = '\n'.join(
msg for msg in messages
if not msg.startswith(("gpg: DBG:", "[GNUPG:]"))
)

return stderr_filtered, gpg_error_code


if __name__ == "__main__":
# Read message from standard input
receivedMessage = getMessage()
Expand Down Expand Up @@ -161,13 +128,10 @@ def getGpgCodesFromStderr(stderr):
proc = subprocess.run(cmd, **proc_params)

# Send response
decoded_stderr = proc.stderr.decode(CHARSET)
stderr, gpg_error_code = getGpgCodesFromStderr(decoded_stderr)
sendMessage(
encodeMessage({
"exitCode": proc.returncode,
"stdout": proc.stdout.decode(CHARSET),
"stderr": stderr,
"gpgErrorCode": gpg_error_code,
"stderr": proc.stderr.decode(CHARSET),
"version": VERSION
}))

0 comments on commit e45d99d

Please sign in to comment.