gnupg/sm
Daniel Kahn Gillmor fdd1567743 gpg,gpgsm: Handle pkdecrypt responses with or without NUL terminators
* g10/call-agent.c (agent_pkdecrypt): accept but do not require
NUL-terminated data from the agent.
* sm/call-agent.c (gpgsm_agent_pkdecrypt): accept but do not require
NUL-terminated data from the agent.

--

The current code for both gpg and gpgsm assumes that gpg-agent will
return string terminated with a single NUL, even though the string
that it receives is also already length-delimited.  Since these tools
might be talking to an older version of gpg-agent, we want to continue
to make sense of such a response, but we really shouldn't depend on
it.  Rather, we can just strip off all trailing NULs and then treat
the remaining string as a proper S-expression.

We can't assume tha the S-expression itself is a NUL-terminated
string, because any of the canonically-represented objects could
contain a NUL byte internally.  But if it's a proper S-expression,
then it must actually terminate in a non-NUL ')' octet.

I note that gpgsm_agent_pkdecrypt() appears to try to work with older
versions of gpg-agent which might not return a full S-expression.
This makes it harder to reason about, since a maliciously-formed
return value could contain a string that could cause invalid memory
access when invoking strtoul (e.g. all numbers up to the end of the
buffer).  So we still have to manually NUL-terminate it before
continuing in that codepath.  This cleanup would be easier if we could
just assume that the agent will always return an S-expression.
Perhaps that could be a subsequent cleanup for gpgsm?  Do we expect
all versions of gpgsm to interoperate with all past versions of
gpg-agent?

gpg's agent_pkdecrypt() has no such qualms -- if the returned object
is not a full S-expression, then it rejects the response.  This makes
it much easier to reason about the pkdecrypt response without
modification, and allows us to strip any trailing NUL bytes knowing
that the response string will be properly terminated with a close
parenthesis.

GnuPG-bug-id: 4652
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-07-24 19:30:25 -04:00
..
ChangeLog-2011 Generate the ChangeLog from commit logs. 2011-12-01 11:09:02 +01:00
Makefile.am Remove -I option to common. 2017-03-07 20:25:54 +09:00
call-agent.c gpg,gpgsm: Handle pkdecrypt responses with or without NUL terminators 2019-07-24 19:30:25 -04:00
call-dirmngr.c all: fix spelling and typos 2018-10-24 15:56:18 -04:00
certchain.c all: fix more spelling errors 2018-10-25 16:53:05 -04:00
certcheck.c Use the gpgrt log functions if possible. 2017-11-27 15:00:25 +01:00
certdump.c Use the gpgrt log functions if possible. 2017-11-27 15:00:25 +01:00
certlist.c sm: Print a better diagnostic for encryption certificate selection. 2019-06-04 09:24:03 +02:00
certreqgen-ui.c common: Extend function pubkey_algo_string. 2019-04-02 18:50:55 +02:00
certreqgen.c sm: Fix certificate creation with key on card. 2019-02-21 17:32:39 +01:00
decrypt.c sm: Return the last error for pubkey decryption. 2019-07-05 15:46:19 +09:00
delete.c sm: Change keydb code to use the keybox locking. 2019-05-14 13:36:08 +02:00
encrypt.c gpg,sm: String changes for compliance diagnostics. 2017-07-28 17:46:43 +02:00
export.c kbx: Unify the fingerprint search modes. 2019-03-14 14:55:06 +01:00
fingerprint.c Use the gpgrt log functions if possible. 2017-11-27 15:00:25 +01:00
gpgsm-w32info.rc w32: Add icons and version information. 2013-05-07 21:35:48 +02:00
gpgsm.c sm: Add a couple of debug calls to the keydb module. 2019-05-15 08:52:21 +02:00
gpgsm.h sm: Avoid confusing diagnostic for the default key. 2019-05-27 15:44:16 +02:00
import.c Use the gpgrt log functions if possible. 2017-11-27 15:00:25 +01:00
keydb.c sm: Add a couple of debug calls to the keydb module. 2019-05-15 08:52:21 +02:00
keydb.h sm: Add a couple of debug calls to the keydb module. 2019-05-15 08:52:21 +02:00
keylist.c sm: Add a couple of debug calls to the keydb module. 2019-05-15 08:52:21 +02:00
minip12.c all: fix spelling and typos 2018-10-24 15:56:18 -04:00
minip12.h Change all http://www.gnu.org in license notices to https:// 2016-11-05 12:02:19 +01:00
misc.c sm: Prepare algo mapping to handle values > 255. 2019-02-21 08:51:50 +01:00
passphrase.c Change all http://www.gnu.org in license notices to https:// 2016-11-05 12:02:19 +01:00
passphrase.h Change all http://www.gnu.org in license notices to https:// 2016-11-05 12:02:19 +01:00
qualified.c all: fix spelling and typos 2018-10-24 15:56:18 -04:00
server.c Return better error code for some getinfo IPC commands. 2019-06-03 16:33:10 +02:00
sign.c sm: Avoid confusing diagnostic for the default key. 2019-05-27 15:44:16 +02:00
verify.c Use the gpgrt log functions if possible. 2017-11-27 15:00:25 +01:00