gnupg.git
2 years agog13: First chunk of code to support dm-crypt. wk/g13work
Werner Koch [Wed, 21 Oct 2015 06:38:10 +0000 (08:38 +0200)]
g13: First chunk of code to support dm-crypt.

* g13/call-syshelp.c, g13/call-syshelp.h: New.
* g13/g13-syshelp.c, g13/g13-syshelp.h: New.
* g13/sh-cmd.c: New.
* g13/sh-blockdev.c: New.
* g13/sh-exectool.c: New.
* g13/sh-dmcrypt.c: New.
* g13/Makefile.am (sbin_PROGRAMS): Add g13-syshelp.c
(g13_syshelp_SOURCES): New.
(g13_syshelp_LDADD): New.

* g13/g13.c (opts): Add option --type.
(g13_deinit_default_ctrl): New.
(main): Implement that option.  Call g13_deinit_default_ctrl.
* g13/g13.h (struct call_syshelp_s): New declaration.
(server_control_s): Add field syshelp_local.
* g13/keyblob.h (KEYBLOB_TAG_CREATED): New.
(KEYBLOB_TAG_ALGOSTR): New.
(KEYBLOB_TAG_HDRCOPY): New.
* g13/backend.c (be_parse_conttype_name): New.
(be_get_detached_name): Add CONTTYPE_DM_CRYPT.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodoc: Typo fix.
Werner Koch [Mon, 30 Nov 2015 10:47:23 +0000 (11:47 +0100)]
doc: Typo fix.

--

2 years agodoc: Make make distcheck work again.
Werner Koch [Mon, 30 Nov 2015 10:45:28 +0000 (11:45 +0100)]
doc: Make make distcheck work again.

* doc/Makefile.am (DISTCLEANFILES): Add gpgkey2ssh.1

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoyat2m: Add keyword @url.
Werner Koch [Mon, 30 Nov 2015 10:32:00 +0000 (11:32 +0100)]
yat2m: Add keyword @url.

* doc/yat2m.c (proc_texi_cmd): Add keyword @url.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodoc: Build man pages with the same date as the info files.
Werner Koch [Mon, 30 Nov 2015 10:27:30 +0000 (11:27 +0100)]
doc: Build man pages with the same date as the info files.

* doc/Makefile.am (yat2m-stamp): Use option --date.
--

This changes allows reproducible builds.

Debian-bug-id: 806494

2 years agoyat2m: New option --date.
Werner Koch [Mon, 30 Nov 2015 10:25:37 +0000 (11:25 +0100)]
yat2m: New option --date.

* doc/yat2m.c (opt_date): new.
(isodatestring): Use it if set.
(main): New option --date.

2 years agogpg: Avoid extra translation strings.
Werner Koch [Fri, 27 Nov 2015 17:23:33 +0000 (18:23 +0100)]
gpg: Avoid extra translation strings.

* g10/keyedit.c (menu_expire): Use only one prompt.
--

The old code was anyway not fully i18n because it did not used
ngettext.  Further we ran into const char*/char* conflicts on Windows
where we use a different gettext implementation.

FWIW: A better pattern in the case of a static and a malloced string
w/o error return on malloc failure would be:

  const char *s;
  char *s_buf;
  s_buf = xtryasprintf ("%d foo", n);
  if (!s_buf)
    s = "several foo";
  else
    s = s_buf;
  bar (s);
  xfree (s_buf);

2 years agokbx: Include gpg-error prior to mischelp.h.
Werner Koch [Fri, 27 Nov 2015 17:10:31 +0000 (18:10 +0100)]
kbx: Include gpg-error prior to mischelp.h.

* kbx/keybox-init.c: Change order of includes.
--

This is to avoid redefintion warnings about GPGRT_ATTR_PRINTF.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg,w32: Fix a format string error.
Werner Koch [Fri, 27 Nov 2015 16:59:52 +0000 (17:59 +0100)]
gpg,w32: Fix a format string error.

* g10/keyring.c (keyring_search): Fix format string for off_t.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoSilence compiler warnings related to not using assuan_fd_t.
Werner Koch [Fri, 27 Nov 2015 16:58:51 +0000 (17:58 +0100)]
Silence compiler warnings related to not using assuan_fd_t.

* common/call-gpg.c (start_gpg): Use assuan_fd_t.  Note that the
declaration was already fixed by a previous change.
* dirmngr/server.c (cmd_getinfo): Use assuan_fd_t.
--

Note that this matters only for Windows and it does not harm as long
as we can only build for 32 bit Windows withsizeof(int)==sizeof(void*).

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoSilence unused variable or parameter warnings.
Werner Koch [Fri, 27 Nov 2015 16:53:52 +0000 (17:53 +0100)]
Silence unused variable or parameter warnings.

--

2 years agoAvoid incompatible pointer assignment warnings on Windows.
Werner Koch [Fri, 27 Nov 2015 17:30:14 +0000 (18:30 +0100)]
Avoid incompatible pointer assignment warnings on Windows.

* common/logging.c (fun_writer): Use gpgrt_ssize_t instead of ssize_t.
* dirmngr/server.c (data_line_cookie_write): Ditto.
* sm/certdump.c (format_name_writer): Ditto.
* sm/server.c (data_line_cookie_write): Ditto.
* dirmngr/http.c (cookie_read, cookie_write): Ditto.
--

See the release notes of libgpg-error 1.15 for background info on
gpgrt_ssize_t.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Avoid a declarations after statements.
Werner Koch [Fri, 27 Nov 2015 16:12:56 +0000 (17:12 +0100)]
dirmngr: Avoid a declarations after statements.

* tools/gpgtar.c (parse_arguments): Use a block for a local varibale
definition.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Avoid casting away a const from an char**.
Werner Koch [Fri, 27 Nov 2015 16:10:59 +0000 (17:10 +0100)]
dirmngr: Avoid casting away a const from an char**.

* dirmngr/ldap.c (start_cert_fetch_ldap): Do not use pointers from
global variables.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Allow testing for a running Tor via "getinfo tor".
Werner Koch [Fri, 27 Nov 2015 11:21:45 +0000 (12:21 +0100)]
dirmngr: Allow testing for a running Tor via "getinfo tor".

* dirmngr/server.c (cmd_getinfo): Print an S line if Tor is not
running.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agog13: Fix commit 1a045b13.
Werner Koch [Thu, 26 Nov 2015 17:10:05 +0000 (18:10 +0100)]
g13: Fix commit 1a045b13.

* g13/g13.c (main): Use existsing function.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agocommon: Fix off-by-one access in the new format_text.
Werner Koch [Thu, 26 Nov 2015 17:04:54 +0000 (18:04 +0100)]
common: Fix off-by-one access in the new format_text.

* common/stringhelp.c (format_text): Use existsing fucntion to trim
trailing spaces.  Fix off-by-one access.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Improve output of "getinfo tor".
Werner Koch [Thu, 26 Nov 2015 16:35:56 +0000 (17:35 +0100)]
dirmngr: Improve output of "getinfo tor".

* dirmngr/server.c (cmd_getinfo): Print a message along with OK.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Let Libassuan employ nPth wrappers for connect.
Werner Koch [Thu, 26 Nov 2015 16:15:08 +0000 (17:15 +0100)]
dirmngr: Let Libassuan employ nPth wrappers for connect.

* dirmngr/http.c (my_unprotect, my_protect): Remove.
(connect_server): Do not use these wrappers.
--

Since Libassuan version 2.4.2 the macro ASSUAN_SYSTEM_NPTH_IMPL
protects the low-level connect calls with npth_unprotect and
npth_protect.  This is better than the high-level kludge we used here.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agotools/gpgtar: Add '--dry-run'.
Justus Winter [Thu, 26 Nov 2015 16:05:12 +0000 (17:05 +0100)]
tools/gpgtar: Add '--dry-run'.

* tools/gpgtar-extract.c (extract_{regular,directory}): Honor
'--dry-run'.
* tools/gpgtar.c (enum cmd_and_opt_values): New value.
(opts): Add '--dry-run'.
(parse_arguments): Handle '--dry-run'.
* tools/gpgtar.h (opt): Add field 'dry_run'.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Handle '--gpg-args'.
Justus Winter [Thu, 26 Nov 2015 14:36:52 +0000 (15:36 +0100)]
tools/gpgtar: Handle '--gpg-args'.

* tools/gpgtar-create.c (gpgtar_create): Use given arguments.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise.
* tools/gpgtar-list.c (gpgtar_list): Likewise.
* tools/gpgtar.c (enum cmd_and_opt_values): New value.
(opts): Add 'gpg-args'.
(parse_arguments): Handle arguments.
* tools/gpgtar.h (opt): Add field 'gpg_arguments'.
* tests/openpgp/gpgtar.test: Simplify accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agocommon: Make the GPG arguments configurable in call-gpg.
Justus Winter [Thu, 26 Nov 2015 14:01:40 +0000 (15:01 +0100)]
common: Make the GPG arguments configurable in call-gpg.

* common/call-gpg.c (start_gpg): Add parameter 'gpg_arguments'.
(_gpg_encrypt, gpg_encrypt_blob, gpg_encrypt_stream): Likewise.
(_gpg_decrypt, gpg_decrypt_blob, gpg_decrypt_stream): Likewise.
* common/call-gpg.h: Adapt prototypes.
* g13/create.c (encrypt_keyblob): Adapt callsite.
* g13/g13-common.h (opt): Add field 'gpg_arguments'.
* g13/g13.c (main): Construct default arguments.
* g13/mount.c (decrypt_keyblob): Adapt callsite.
* tools/gpgtar-create.c (gpgtar_create): Likewise.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise.
* tools/gpgtar-list.c (gpgtar_list): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Handle '--tar-args' for compatibility with gpg-zip.
Justus Winter [Thu, 26 Nov 2015 13:08:48 +0000 (14:08 +0100)]
tools/gpgtar: Handle '--tar-args' for compatibility with gpg-zip.

* tools/gpgtar.c (enum cmd_and_opt_values): New value.
(opts): Add new group for tar options, rearrange a little, add
'--tar-args'.
(tar_opts): New variable.
(shell_parse_stringlist): New function.
(shell_parse_argv): Likewise.
(parse_arguments): Add option argument, handle '--tar-args'.
(main): Fix invokation of 'parse_arguments'.
* tests/openpgp/gpgtar.test: Simplify decryption.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Rework argument parsing.
Justus Winter [Thu, 26 Nov 2015 10:46:35 +0000 (11:46 +0100)]
tools/gpgtar: Rework argument parsing.

* tools/gpgtar.c (main): Move argument parsing into its own function.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotests: Add tests for gpgtar and gpg-zip.
Justus Winter [Wed, 25 Nov 2015 17:32:09 +0000 (18:32 +0100)]
tests: Add tests for gpgtar and gpg-zip.

* tests/openpgp/Makefile.am (TESTS): Add new file.
* tests/openpgp/gpgtar.test: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Handle '--directory' argument.
Justus Winter [Wed, 25 Nov 2015 17:29:22 +0000 (18:29 +0100)]
tools/gpgtar: Handle '--directory' argument.

* tools/gpgtar-extract.c (gpgtar_extract): Only generate a directory
name if none is given via arguments.
* tools/gpgtar.c (enum cmd_and_opt_values): New constant.
(opts): Add argument.
(main): Parse argument.
* tools/gpgtar.h (opt): New field 'directory'.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Handle '--gpg' argument.
Justus Winter [Wed, 25 Nov 2015 13:57:14 +0000 (14:57 +0100)]
tools/gpgtar: Handle '--gpg' argument.

* tools/gpgtar-create.c (gpgtar_create): Use given gpg program.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise.
* tools/gpgtar-list.c (gpgtar_list): Likewise.
* tools/gpgtar.c (enum cmd_and_opt_values): New constant.
(opts): Add argument.
(main): Handle argument.
* tools/gpgtar.h (opt): Add field 'gpg_program'.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools/gpgtar: Improve error handling.
Justus Winter [Wed, 25 Nov 2015 12:39:50 +0000 (13:39 +0100)]
tools/gpgtar: Improve error handling.

* tools/gpgtar-create.c (gpgtar_create): Return an error code, fix
error handling.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise.
* tools/gpgtar-list.c (read_header): Return an error code.
(gpgtar_list): Return an error code, fix error handling.
(gpgtar_read_header): Return an error code.
* tools/gpgtar.c: Add missing include.
(main): Print an generic error message if a command failed and no
error has been printed yet.
* tools/gpgtar.h (gpgtar_{create,extract,list,read_header}): Fix the
prototypes accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agotools: Add encryption and decryption support to gpgtar.
Justus Winter [Tue, 24 Nov 2015 17:39:30 +0000 (18:39 +0100)]
tools: Add encryption and decryption support to gpgtar.

* tools/Makefile.am: Amend CFLAGS and LDADD.
* tools/gpgtar-create.c (gpgtar_create): Add encrypt flag and encrypt
stream if requested.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise for decryption.
* tools/gpgtar-list.c (gpgtar_list): Likewise.
* tools/gpgtar.c (main): Initialize npth and assuan.  Parse recipient
and local user, and note which flags are currently ignored.  Adapt
calls to gpgtar_list and friends.
(tar_and_encrypt): Drop stub function and prototype.
(decrypt_and_untar): Likewise.
(decrypt_and_list): Likewise.
* tools/gpgtar.h (gpgtar_{create,extract,list}): Add encryption or
decryption argument.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agocommon: Add stream interface to call-pgp.
Justus Winter [Tue, 24 Nov 2015 17:31:14 +0000 (18:31 +0100)]
common: Add stream interface to call-pgp.

* common/call-gpg.c (struct writer_thread_parms): Add field 'stream'.
(writer_thread_main): Support reading from a stream.
(start_writer): Add stream argument.
(struct reader_thread_parms): Add field 'stream'.
(reader_thread_main): Support writing to a stream.
(start_reader): Add stream argument.
(_gpg_encrypt): Add stream api.
(gpg_encrypt_blob): Adapt accordingly.
(gpg_encrypt_stream): New function.
(_gpg_decrypt): Add stream api.
(gpg_decrypt_blob): Adapt accordingly.
(gpg_decrypt_stream): New function.
* common/call-gpg.h (gpg_encrypt_stream): New prototype.
(gpg_decrypt_stream): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agocommon: Refactor the call-gpg code.
Justus Winter [Tue, 24 Nov 2015 13:58:31 +0000 (14:58 +0100)]
common: Refactor the call-gpg code.

* common/call-gpg.c (gpg_{en,de}crypt_blob): Move most of the code
into two new functions, _gpg_encrypt and _gpg_decrypt.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agog13: Move 'call-gpg.c' to common.
Justus Winter [Tue, 24 Nov 2015 12:40:56 +0000 (13:40 +0100)]
g13: Move 'call-gpg.c' to common.

* common/Makefile.am (common_sources): Add files.
* g13/call-gpg.c: Move to 'common' and adapt slightly.  Add a
parameter to let callees override the gpg program to execute.
* g13/call-gpg.h: Likewise.
* g13/Makefile.am (g13_SOURCES): Drop files.
* g13/create.c (encrypt_keyblob): Hand in the gpg program to execute.
* g13/mount.c (decrypt_keyblob): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agogpg: When comparing keyids, use the keyid, not the fingerprint's suffix.
Neal H. Walfield [Tue, 24 Nov 2015 12:03:24 +0000 (13:03 +0100)]
gpg: When comparing keyids, use the keyid, not the fingerprint's suffix.

* g10/keyedit.c (menu_select_key): Use spacep and hexdigitp instead of
inline tests.  Don't compare P to the suffix of the fingerprint.  If P
appears to be a keyid, do an exact compare against the keyid.  If it
appears to be a fingerprint, do an exact compare against the
fingerprint.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Reflow long texts.
Neal H. Walfield [Mon, 23 Nov 2015 21:20:28 +0000 (22:20 +0100)]
gpg: Reflow long texts.

* common/stringhelp.c (format_text): New function.
* common/t-stringhelp.c (stresc): New function.
(test_format_text): New function.  Test format_text.
* g10/tofu.c (get_trust): Use format_text to reflow long texts.
(show_statistics): Likewise.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agocommon: Extend utf8_charcount to include the string's length.
Neal H. Walfield [Mon, 23 Nov 2015 21:13:56 +0000 (22:13 +0100)]
common: Extend utf8_charcount to include the string's length.

* common/stringhelp.c (utf8_charcount): Take additional parameter,
len.  Process at most LEN bytes.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agodirmngr: Fix http lookups when libadns is used.
Justus Winter [Mon, 23 Nov 2015 14:41:36 +0000 (15:41 +0100)]
dirmngr: Fix http lookups when libadns is used.

* dirmngr/dns-stuff.c (resolve_name_adns): Fill in the port.
--
Previously, sin_port was set to zero, making connect fail.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Fix SRV record lookups when using the system resolver.
Justus Winter [Mon, 23 Nov 2015 14:46:33 +0000 (15:46 +0100)]
dirmngr: Fix SRV record lookups when using the system resolver.

* dirmngr/dns-stuff.c (getsrv): Fix error handling.
--
This fixes hkp server pools not using SRV records.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Honor ports specified in SRV records.
Justus Winter [Thu, 19 Nov 2015 14:03:30 +0000 (15:03 +0100)]
dirmngr: Honor ports specified in SRV records.

* dirmngr/ks-engine-hkp.c (struct hostinfo_s): New field 'port'.
(create_new_hostinfo): Initialize 'port'.
(add_host): Add host parameter and update the hosttable entry.
(map_host): Return port if known, adjust calls to 'add_host'.
(make_host_part): Let 'map_host' specify the port if known.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Support hkp server pools using SRV records.
Justus Winter [Thu, 19 Nov 2015 13:29:36 +0000 (14:29 +0100)]
dirmngr: Support hkp server pools using SRV records.

* dirmngr/ks-engine-hkp.c (map_host): Handle SRV records.
--
Signed-off-by: Justus Winter <justus@g10code.com>
GnuPG-bug-id: 1788

2 years agodirmngr: Refactor 'map_host'.
Justus Winter [Thu, 19 Nov 2015 12:00:59 +0000 (13:00 +0100)]
dirmngr: Refactor 'map_host'.

* dirmngr/ks-engine-hkp.c (add_host): New function.
(map_host): Use the new function.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Fix pool detection.
Justus Winter [Mon, 23 Nov 2015 12:59:01 +0000 (13:59 +0100)]
dirmngr: Fix pool detection.

* dirmngr/ks-engine-hkp (arecords_is_pool): Fix counting IP addresses.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Refactor 'map_host'.
Justus Winter [Thu, 19 Nov 2015 11:43:23 +0000 (12:43 +0100)]
dirmngr: Refactor 'map_host'.

* dirmngr/ks-engine-hkp.c (arecords_is_pool): New function.
(map_host): Use the new function.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Start dirmngr on demand.
Justus Winter [Mon, 23 Nov 2015 10:44:50 +0000 (11:44 +0100)]
dirmngr: Start dirmngr on demand.

* common/asshelp.h: Include 'util.h'.
* dirmngr/dirmngr-client.c (main): Use 'start_new_dirmngr' to connect
to the dirmngr.
(start_dirmngr): Drop now unused declaration and function.
--
Signed-off-by: Justus Winter <justus@g10code.com>
GnuPG-bug-id: 1843

2 years agogpg: If sqlite is not available, don't build things depending on it.
Neal H. Walfield [Mon, 23 Nov 2015 11:39:22 +0000 (12:39 +0100)]
gpg: If sqlite is not available, don't build things depending on it.

* configure.ac: Define the automake conditional SQLITE3.
* tests/openpgp/Makefile.am (TESTS): Move the sqlite3 dependent tests
to...
(sqlite3_dependent_tests): ... this new variable.  If SQLITE3 is not
defined, then clear this variable.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Allow updating the expiration time of multiple subkeys at once.
Neal H. Walfield [Mon, 23 Nov 2015 11:16:33 +0000 (12:16 +0100)]
gpg: Allow updating the expiration time of multiple subkeys at once.

* g10/keyedit.c (menu_expire): Allow updating the expiration time of
multiple subkeys at once.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1944

2 years agogpg: Don't crash if key is not passed an argument.
Neal H. Walfield [Mon, 23 Nov 2015 10:21:24 +0000 (11:21 +0100)]
gpg: Don't crash if key is not passed an argument.

* g10/keyedit.c (menu_select_key): Don't crash if P is NULL.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Fail if the search description passed to --gen-revoke is ambiguous.
Neal H. Walfield [Fri, 20 Nov 2015 12:00:19 +0000 (13:00 +0100)]
gpg: Fail if the search description passed to --gen-revoke is ambiguous.

* g10/revoke.c (gen_revoke): Error out if the search description is
ambiguous.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Refactor print_seckey_info.
Neal H. Walfield [Fri, 20 Nov 2015 11:52:04 +0000 (12:52 +0100)]
gpg: Refactor print_seckey_info.

* g10/keylist.c (print_seckey_info): Break formatting functionality
into...
(format_seckey_info): ... this new function.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Improve an error message.
Neal H. Walfield [Fri, 20 Nov 2015 11:17:13 +0000 (12:17 +0100)]
gpg: Improve an error message.

* g10/revoke.c (gen_revoke): Provide a more descriptive error message
if searching for a key fails.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1987

2 years agodirmngr: Improve error handling.
Justus Winter [Thu, 19 Nov 2015 16:37:32 +0000 (17:37 +0100)]
dirmngr: Improve error handling.

* dirmngr/crlcache.c (crl_cache_cert_isvalid): Add missing break.
--
Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Fix memory leak.
Justus Winter [Thu, 19 Nov 2015 15:45:09 +0000 (16:45 +0100)]
dirmngr: Fix memory leak.

* dirmngr/ldap.c (start_cert_fetch_ldap): Avoid leaking all malloc'ed
arguments.
--
Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agoagent: Improve error handling.
Justus Winter [Thu, 19 Nov 2015 15:18:20 +0000 (16:18 +0100)]
agent: Improve error handling.

* agent/trustlist.c (istrusted_internal): Initialize 'err'.
--
There is a plausible path of execution so that a branch condition uses
the uninitialized value.

Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agocommon: Avoid undefined behavior.
Justus Winter [Thu, 19 Nov 2015 15:13:55 +0000 (16:13 +0100)]
common: Avoid undefined behavior.

* common/iobuf.c (iobuf_esopen): Initialize 'len' as 'file_es_filter'
will make use of it.
--
Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agog10: Avoid undefined behavior.
Justus Winter [Thu, 19 Nov 2015 14:48:01 +0000 (15:48 +0100)]
g10: Avoid undefined behavior.

* g10/trust.c (clean_one_uid): Avoid a computation involving an
uninitialized value.
--
Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agoscd: Improve error handling.
Justus Winter [Tue, 17 Nov 2015 17:05:51 +0000 (18:05 +0100)]
scd: Improve error handling.

* scd/app-openpgp.c (get_public_key): Improve error handling.
--
Found using the Clang Static Analyzer.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Fix typo.
Justus Winter [Thu, 19 Nov 2015 13:38:30 +0000 (14:38 +0100)]
dirmngr: Fix typo.

--
Signed-off-by: Justus Winter <justus@g10code.com>
2 years agodirmngr: Gracefully handle premature termination of TLS streams. fix-1950
Justus Winter [Wed, 18 Nov 2015 14:06:48 +0000 (15:06 +0100)]
dirmngr: Gracefully handle premature termination of TLS streams.

* dirmngr/http.c (close_tls_session): New function.
(session_unref): Use the new function to close the TLS stream.
(cookie_read): If the stream terminated prematurely, close it and
return a short read.
--
With this patch, I was able to update all the keys in the Debian
keyring over hkps.

Signed-off-by: Justus Winter <justus@g10code.com>
GnuPG-bug-id: 1950

2 years agotools: Fix option parsing for gpg-zip.
Neal H. Walfield [Tue, 17 Nov 2015 21:15:33 +0000 (22:15 +0100)]
tools: Fix option parsing for gpg-zip.

* tools/gpg-zip.in: Correctly set GPG when --gpg is specified.
Correctly set TAR when --tar is specified.  Pass TAR_ARGS to tar.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Co-authored-by: Michael Mönch <michael.moench@marktjagd.de>
GnuPG-bug-id 1351
GnuPG-bug-id 1442

2 years agogpg: Allow selecting subkeys using a keyid.
Neal H. Walfield [Tue, 17 Nov 2015 20:21:03 +0000 (21:21 +0100)]
gpg: Allow selecting subkeys using a keyid.

* g10/keyedit.c (menu_select_key): Take an additional argument, p.
Update callers.  If P is a hex string, then assume that P is a key id
or fingerprint and select subkeys with matching key ids or
fingerprints.
* doc/gpg.texi: Update documentation for the key subcommand.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1423
Debian-bug-id: 610336

2 years agodirmngr: Fix specifying keyservers by IP address.
Justus Winter [Mon, 16 Nov 2015 17:18:25 +0000 (18:18 +0100)]
dirmngr: Fix specifying keyservers by IP address.

* dirmngr/ks-engine-hkp.c (map_host): Update the original 'hosttable'
entry instead of creating another one.
--
Previously, if a keyserver was given using its IP address
(e.g. 'hkp://127.0.0.1'), 'map_host' would create two entries in the
'hosttable', one with the name '127.0.0.1', and the second one with
the name 'localhost' and 'v4addr' being set to '127.0.0.1'.  But the
first entry is the one being used for lookups, and since the 'v4' flag
is not set, the 'HTTP_FLAG_IGNORE_IPv4' is used when doing the http
request, making it fail.

Signed-off-by: Justus Winter <justus@g10code.com>
GnuPG-bug-id: 2012

2 years agogpg: Change keydb_search to not return legacy keys.
Neal H. Walfield [Tue, 17 Nov 2015 13:38:03 +0000 (14:38 +0100)]
gpg: Change keydb_search to not return legacy keys.

* g10/keyring.c (keyring_search): Take new argument, ignore_legacy.
If set, skip any legacy keys.  Update callers.
* g10/keydb.c (keydb_search): Skip any legacy keys.
(keydb_search_first): Don't skip legacy keys.  Treat them
as an error.
(keydb_search_next): Likewise.
(keydb_search_fpr): Likewise.
* g10/export.c (do_export_stream): Likewise.
* g10/getkey.c (lookup): Likewise.
(have_secret_key_with_kid): Likewise.
* g10/keylist.c (list_all): Likewise.
(keyring_rebuild_cache): Likewise.
* g10/keyserver.c (keyidlist): Likewise.
* g10/trustdb.c (validate_key_list): Likewise.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Correctly handle an error.
Neal H. Walfield [Tue, 17 Nov 2015 11:56:55 +0000 (12:56 +0100)]
gpg: Correctly handle an error.

* g10/keyring.c (keyring_search): If a compare function returns an
error, treat it as an error.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Correctly handle keyblocks followed by legacy keys.
Neal H. Walfield [Tue, 17 Nov 2015 11:55:42 +0000 (12:55 +0100)]
gpg: Correctly handle keyblocks followed by legacy keys.

* g10/keyring.c (keyring_get_keyblock): If we encounter a legacy
packet after already having some non-legacy packets, then treat the
legacy packet as a keyblock boundary, not as part of the keyblock.
* g10/t-keydb-get-keyblock.c: New file.
* g10/t-keydb-get-keyblock.gpg: New file.
* g10/Makefile.am (EXTRA_DIST): Add t-keydb-get-keyblock.gpg.
(module_tests): Add t-keydb-get-keyblock.
(t_keydb_get_keyblock_SOURCES): New variable.
(t_keydb_get_keyblock_LDADD): Likewise.

--
Signed-off-by: Neal H. Walfield
GnuPG-bug-id: 2151

2 years agogpg: Add some debugging output.
Neal H. Walfield [Mon, 16 Nov 2015 19:55:34 +0000 (20:55 +0100)]
gpg: Add some debugging output.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Make debugging search descriptors easier.
Neal H. Walfield [Tue, 17 Nov 2015 10:36:38 +0000 (11:36 +0100)]
gpg: Make debugging search descriptors easier.

* g10/keydb.c (dump_search_desc): Rename from this...
(keydb_search_desc_dump): ... to this.  Only process a single search
descriptor.  Improve output.  Don't mark as static.  Update callers.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Add function format_keyid.
Neal H. Walfield [Tue, 17 Nov 2015 10:47:43 +0000 (11:47 +0100)]
gpg: Add function format_keyid.

* g10/options.h (opt.keyid_format): Add new value KF_DEFAULT.
* g10/keyid.c (format_keyid): New function.
(keystr): Use it.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Use a more appropriate error code.
Neal H. Walfield [Tue, 17 Nov 2015 12:42:43 +0000 (13:42 +0100)]
gpg: Use a more appropriate error code.

* g10/gpg.c (check_user_ids): Return a more appropriate error code if
a user id is ambiguous.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agoFix typos found using codespell.
Justus Winter [Mon, 16 Nov 2015 11:41:46 +0000 (12:41 +0100)]
Fix typos found using codespell.

* agent/cache.c: Fix typos.
* agent/call-pinentry.c: Likewise.
* agent/call-scd.c: Likewise.
* agent/command-ssh.c: Likewise.
* agent/command.c: Likewise.
* agent/divert-scd.c: Likewise.
* agent/findkey.c: Likewise.
* agent/gpg-agent.c: Likewise.
* agent/w32main.c: Likewise.
* common/argparse.c: Likewise.
* common/audit.c: Likewise.
* common/audit.h: Likewise.
* common/convert.c: Likewise.
* common/dotlock.c: Likewise.
* common/exechelp-posix.c: Likewise.
* common/exechelp-w32.c: Likewise.
* common/exechelp-w32ce.c: Likewise.
* common/exechelp.h: Likewise.
* common/helpfile.c: Likewise.
* common/i18n.h: Likewise.
* common/iobuf.c: Likewise.
* common/iobuf.h: Likewise.
* common/localename.c: Likewise.
* common/logging.c: Likewise.
* common/openpgp-oid.c: Likewise.
* common/session-env.c: Likewise.
* common/sexputil.c: Likewise.
* common/sysutils.c: Likewise.
* common/t-sexputil.c: Likewise.
* common/ttyio.c: Likewise.
* common/util.h: Likewise.
* dirmngr/cdblib.c: Likewise.
* dirmngr/certcache.c: Likewise.
* dirmngr/crlcache.c: Likewise.
* dirmngr/dirmngr-client.c: Likewise.
* dirmngr/dirmngr.c: Likewise.
* dirmngr/dirmngr_ldap.c: Likewise.
* dirmngr/dns-stuff.c: Likewise.
* dirmngr/http.c: Likewise.
* dirmngr/ks-engine-hkp.c: Likewise.
* dirmngr/ks-engine-ldap.c: Likewise.
* dirmngr/ldap-wrapper.c: Likewise.
* dirmngr/ldap.c: Likewise.
* dirmngr/misc.c: Likewise.
* dirmngr/ocsp.c: Likewise.
* dirmngr/validate.c: Likewise.
* g10/encrypt.c: Likewise.
* g10/getkey.c: Likewise.
* g10/gpg.c: Likewise.
* g10/gpgv.c: Likewise.
* g10/import.c: Likewise.
* g10/keydb.c: Likewise.
* g10/keydb.h: Likewise.
* g10/keygen.c: Likewise.
* g10/keyid.c: Likewise.
* g10/keylist.c: Likewise.
* g10/keyring.c: Likewise.
* g10/mainproc.c: Likewise.
* g10/misc.c: Likewise.
* g10/options.h: Likewise.
* g10/packet.h: Likewise.
* g10/parse-packet.c: Likewise.
* g10/pkclist.c: Likewise.
* g10/pkglue.c: Likewise.
* g10/plaintext.c: Likewise.
* g10/server.c: Likewise.
* g10/sig-check.c: Likewise.
* g10/sqlite.c: Likewise.
* g10/tdbio.c: Likewise.
* g10/test-stubs.c: Likewise.
* g10/tofu.c: Likewise.
* g10/trust.c: Likewise.
* g10/trustdb.c: Likewise.
* g13/create.c: Likewise.
* g13/mountinfo.c: Likewise.
* kbx/keybox-blob.c: Likewise.
* kbx/keybox-file.c: Likewise.
* kbx/keybox-init.c: Likewise.
* kbx/keybox-search-desc.h: Likewise.
* kbx/keybox-search.c: Likewise.
* kbx/keybox-update.c: Likewise.
* scd/apdu.c: Likewise.
* scd/app-openpgp.c: Likewise.
* scd/app-p15.c: Likewise.
* scd/app.c: Likewise.
* scd/ccid-driver.c: Likewise.
* scd/command.c: Likewise.
* scd/iso7816.c: Likewise.
* sm/base64.c: Likewise.
* sm/call-agent.c: Likewise.
* sm/call-dirmngr.c: Likewise.
* sm/certchain.c: Likewise.
* sm/gpgsm.c: Likewise.
* sm/import.c: Likewise.
* sm/keydb.c: Likewise.
* sm/minip12.c: Likewise.
* sm/qualified.c: Likewise.
* sm/server.c: Likewise.
* tools/gpg-check-pattern.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgkey2ssh.c: Likewise.
* tools/gpgparsemail.c: Likewise.
* tools/gpgtar.c: Likewise.
* tools/rfc822parse.c: Likewise.
* tools/symcryptrun.c: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2 years agogpg: Fix error checking and improve error reporting.
Neal H. Walfield [Mon, 16 Nov 2015 09:34:01 +0000 (10:34 +0100)]
gpg: Fix error checking and improve error reporting.

* g10/gpg.c (check_user_ids): Differentiate between a second result
and an error.  If the key specification is ambiguous or an error
occurs, set RC appropriately.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Reported-by: Werner Koch <wk@gnupg.org>
Suggested-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agogpg: Use only one fingerprint formatting function.
Werner Koch [Sat, 14 Nov 2015 08:13:02 +0000 (09:13 +0100)]
gpg: Use only one fingerprint formatting function.

* g10/gpg.h (MAX_FORMATTED_FINGERPRINT_LEN): New.
* g10/keyid.c (hexfingerprint): Add optional args BUFFER and BUFLEN.
Change all callers.
(format_hexfingerprint): New.
* g10/keylist.c (print_fingerprint): Change to use hexfingerprint.
* g10/tofu.c (fingerprint_format): Remove.  Replace calls by
format_hexfingerprint.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Simplify the tofu interface by using the public key packet.
Werner Koch [Fri, 13 Nov 2015 15:42:59 +0000 (16:42 +0100)]
gpg: Simplify the tofu interface by using the public key packet.

* g10/tofu.c (fingerprint_str): Remove.
(tofu_register): Take a public key instead of a fingerprint as arg.
Use hexfingerprint() to get a fpr from the PK.
(tofu_get_validity): Ditto.
(tofu_set_policy, tofu_get_policy): Simplify by using hexfingerprint.
* g10/trustdb.c (tdb_get_validity_core): Pass the primary key PK to
instead of the fingerprint to the tofu functions.
--

This change has the advantage that we are not bound to a specific
fingerprint length and will thus helps us to implement rfc4880bis.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Make trusted-key override for Tofu robust against swapped tofu.db.
Werner Koch [Fri, 13 Nov 2015 15:09:01 +0000 (16:09 +0100)]
gpg: Make trusted-key override for Tofu robust against swapped tofu.db.

* g10/tofu.c (get_trust): For the UTK check lookup the key by
fingerprint.
--

Extracting the keyid form the fingerprint is not a good idea because
that only works for v4 keys.  It is also better to first read the key
and then extract the keyid from the actual available key.

The entire trusted-key stuff should be reworked to make use of
fingerprints.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Fix regression in --locate-keys (in 2.1.9).
Werner Koch [Fri, 13 Nov 2015 11:56:13 +0000 (12:56 +0100)]
gpg: Fix regression in --locate-keys (in 2.1.9).

* g10/getkey.c (getkey_ctx_s): Add field "extra_list".
(get_pubkey_byname): Store strings in the context.
(getkey_end): Free EXTRA_LIST.
--

This fixes a use-after-free bug.  It showed up with:

  gpg --auto-key-locate local --locate-key wk@gnupg.org

The key was shown but also all other following keys in the keyring.
Bisecting showed d47e84946ee010917cfc3501062721b74afbb771 as culprit
but the actual cause was a part of:

Regression-due-to: b06f96ba4f57f55194efcd37a0e3a2aa5450b974
Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Print a new EXPORTED status line.
Werner Koch [Thu, 12 Nov 2015 16:02:18 +0000 (17:02 +0100)]
gpg: Print a new EXPORTED status line.

* common/status.h (STATUS_EXPORTED): New.
* g10/export.c (print_status_exported): New.
(do_export_stream): Call that function.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Print export statistics to the status-fd.
Werner Koch [Thu, 12 Nov 2015 15:02:35 +0000 (16:02 +0100)]
gpg: Print export statistics to the status-fd.

* common/status.h (STATUS_EXPORT_RES): New.
* g10/main.h (export_stats_t): New.
* g10/export.c (export_stats_s): New.
(export_new_stats, export_release_stats): New.
(export_print_stats): New.
(export_pubkeys, export_seckeys, export_secsubkeys)
(export_pubkey_buffer, do_export): Add arg "stats".
(do_export_stream): Add arg stats and update it.
* g10/gpg.c (main) <aExport, aExportSecret, aExportSecretSub>: Create,
pass, and print a stats object to the export function calls.

* g10/export.c (export_pubkeys_stream): Remove unused function.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Do not block during ADNS calls.
Werner Koch [Thu, 12 Nov 2015 12:31:59 +0000 (13:31 +0100)]
dirmngr: Do not block during ADNS calls.

* dirmngr/dns-stuff.c: Include npth.h
(my_unprotect, my_protect): New wrapper.
(resolve_name_adns): Put unprotect/protect around adns calls.
(get_dns_cert): Ditto.
(getsrv): Ditto.
(get_dns_cname): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: New option --nameserver.
Werner Koch [Thu, 12 Nov 2015 12:20:18 +0000 (13:20 +0100)]
dirmngr: New option --nameserver.

* dirmngr/dirmngr.c (oNameServer): New.
(opts): Add --nameserver.
(parse_rereadable_options): Act upon oNameServer.
* dirmngr/dns-stuff.c (DEFAULT_NAMESERVER): New.
(tor_nameserver): New.
(set_dns_nameserver): New.
(my_adns_init): Make name server configurable.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Fix cache consistency problem.
Neal H. Walfield [Wed, 11 Nov 2015 17:26:53 +0000 (18:26 +0100)]
gpg: Fix cache consistency problem.

g10/keyring.c (keyring_search): Only mark the cache as completely
filled if we start the scan from the beginning of the keyring.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Reported-by: NIIBE Yutaka <gniibe@fsij.org>
A new feature (e8c53fc) turned up a bug whereby checking if a search
term matches multiple keys in the keyring causes the cache to be
inconsistent.

When we look for a key on the keyring, we iterate over each of the
keyblocks starting with the keyblock following the last result.  For
each keyblock, we iterate over the public key and any subkeys.  As we
iterate over each key, we first insert it into the cache and then
check if the key matches.  If so, we are done.

In pseudo code:

  for (i = last_result + 1; i < num_records; i ++)
    keyblock = get_keyblock (i)
    for (j = 1; j < len(keyblock); j ++)
      key = keyblock[j]
      update_cache (key)
      if (compare (key, search_terms))
        return ok
  cache_filled = true
  return ENOFOUND

When we look for the next match, we start with the following keyblock.
The result is that any subkeys following the key that matched are not
added to the cache (in other words, when a keyblock matches, the inner
loop did not necessarily complete and the subsequent search doesn't
resume it).

This patch includes a straightforward fix: only indicate the cache as
complete if we started the scan from the beginning of the keyring and
really didn't find anything.

2 years agogpg: Default to the the PGP trust model.
Neal H. Walfield [Tue, 10 Nov 2015 07:05:17 +0000 (08:05 +0100)]
gpg: Default to the the PGP trust model.

* g10/trustdb.c (init_trustdb): If we can't read the trust model from
the trust DB, default to TM_PGP, not TM_TOFU_PGP.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Default to the flat TOFU DB format.
Neal H. Walfield [Tue, 10 Nov 2015 07:03:57 +0000 (08:03 +0100)]
gpg: Default to the flat TOFU DB format.

* g10/tofu.c (opendbs): If the TOFU DB format is set to auto and there
is no TOFU DB, default to the flat format.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agodirmngr: Change to new ADNS Tor mode init scheme.
Werner Koch [Mon, 9 Nov 2015 19:44:13 +0000 (20:44 +0100)]
dirmngr: Change to new ADNS Tor mode init scheme.

* dirmngr/dns-stuff.c (tor_credentials): New.
(enable_dns_tormode): Add arg new_circuit and update tor_credentials.
(my_adns_init): Rework to set Tor mode using a config file options and
always use credentials.
* dirmngr/server.c (cmd_dns_cert): Improve error message.
* dirmngr/t-dns-stuff.c (main): Add option --new-circuit.
--

Note that the option --new-circuit in t-dns-stuff is not really useful
because a new circuit is also used for the first call to the function.

Todo: We need to find a policy when to requrest a new curcuit and we
      also need to add credentials to the assuan_sock_connect calls.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodirmngr: Improve detection of ADNS.
Werner Koch [Mon, 9 Nov 2015 19:34:42 +0000 (20:34 +0100)]
dirmngr: Improve detection of ADNS.

* configure.ac (HAVE_ADNS_FREE): New ac_define.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoscd: Add reder information to --card-status.
NIIBE Yutaka [Mon, 9 Nov 2015 07:15:44 +0000 (16:15 +0900)]
scd: Add reder information to --card-status.

* g10/call-agent.h, g10/call-agent.c (agent_release_card_info)
g10/card-util.c (card_status): Add READER.
* scd/apdu.c (close_ccid_reader, open_ccid_reader): Handle RDRNAME.
(apdu_get_reader_name): New.
* scd/ccid-driver.c (ccid_open_reader): Add argument to RDRNAME_P.
* scd/command.c (cmd_learn): Return READER information.

2 years agogpg: Avoid new strings.
Werner Koch [Fri, 6 Nov 2015 12:29:01 +0000 (13:29 +0100)]
gpg: Avoid new strings.

* g10/decrypt-data.c (decrypt_data): Use already translated strings.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agocommon: Fix commit f99830b.
Werner Koch [Fri, 6 Nov 2015 12:20:01 +0000 (13:20 +0100)]
common: Fix commit f99830b.

* common/userids.c (classify_user_id): Avoid underflow.  Use spacep to
also trim tabs.
--

This is actually not fully consistent because the now used
trim_trailing_spaces uses the locale dependent isspace and not spacep.
Given that the use of isspace is anyway problematic we should check
whether we can chnage trim_trailing_spaces.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agogpg: Fix formatting string.
Neal H. Walfield [Fri, 6 Nov 2015 12:15:34 +0000 (13:15 +0100)]
gpg: Fix formatting string.

* g10/decrypt-data.c (decrypt_data): Fix formatting string.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Add new option --only-sign-text-ids.
Neal H. Walfield [Fri, 6 Nov 2015 12:14:57 +0000 (13:14 +0100)]
gpg: Add new option --only-sign-text-ids.

* g10/options.h (opt): Add field only_sign_text_ids.
* g10/gpg.c (enum cmd_and_opt_values): Add value oOnlySignTextIDs.
(opts): Handle oOnlySignTextIDs.
(main): Likewise.
* g10/keyedit.c (sign_uids): If OPT.ONLY_SIGN_TEXT_IDS is set, don't
select non-text based IDs automatically.
(keyedit_menu): Adapt the prompt asking to sign all user ids according
to OPT.ONLY_SIGN_TEXT_IDS.
* doc/gpg.texi: Document the new option --only-sign-text-ids.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1241
Debian-bug-id: 569702

2 years agocommon: When classifying keyids and fingerprints, reject trailing junk.
Neal H. Walfield [Fri, 6 Nov 2015 11:31:16 +0000 (12:31 +0100)]
common: When classifying keyids and fingerprints, reject trailing junk.

* common/userids.c (classify_user_id): Trim any trailing whitespace.
Before assuming that a hexstring corresponds to a key id or
fingerprint, make sure that it is NUL terminated.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1206
Debian-bug-id: 575084

2 years agogpg: Check for ambiguous or non-matching key specs.
Neal H. Walfield [Thu, 5 Nov 2015 16:29:53 +0000 (17:29 +0100)]
gpg: Check for ambiguous or non-matching key specs.

* g10/gpg.c (check_user_ids): New function.
(main): Check that any user id specifications passed to --local-user
and --remote-user correspond to exactly 1 user.  Check that any user
id specifications passed to --default-key correspond to at most 1
user.  Warn if any user id specifications passed to --local-user or
--default-user are possible ambiguous (are not specified by long keyid
or fingerprint).
* g10/getkey.c (parse_def_secret_key): Don't warn about possible
ambiguous key descriptions here.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1128
Debian-debug-id: 544490

2 years agocommon: Add new function strlist_rev.
Neal H. Walfield [Fri, 6 Nov 2015 09:51:35 +0000 (10:51 +0100)]
common: Add new function strlist_rev.

* common/strlist.c (strlist_rev): New function.
* common/t-strlist.c: New file.
* common/Makefile.am (common_sources): Add strlist.c and strlist.h.
(module_tests): Add t-strlist.
(t_strlist_LDADD): New variable.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agocommon: Include required, but not included headers in t-support.h.
Neal H. Walfield [Fri, 6 Nov 2015 09:49:09 +0000 (10:49 +0100)]
common: Include required, but not included headers in t-support.h.

* common/t-support.h: Include <stdlib.h> and <stdio.h>.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agogpg: Indicate which characters are invalid.
Neal H. Walfield [Thu, 5 Nov 2015 13:31:58 +0000 (14:31 +0100)]
gpg: Indicate which characters are invalid.

* g10/keygen.c (ask_user_id): Indicate which characters are invalid.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1143

2 years agogpg: Add support for unwrapping the outer level of encryption.
Neal H. Walfield [Thu, 5 Nov 2015 11:20:42 +0000 (12:20 +0100)]
gpg: Add support for unwrapping the outer level of encryption.

* g10/decrypt-data.c (decrypt_data): If OPT.UNWRAP_ENCRYPTION is set,
copy the data to the output file instead of continuing to process it.
* g10/gpg.c (enum cmd_and_opt_values): Add new value oUnwrap.
(opts): Handle oUnwrap.
(main): Likewise.
* g10/options.h (opt): Add field unwrap_encryption.
* g10/plaintext.c (handle_plaintext): Break the output file selection
functionality into ...
(get_output_file): ... this new function.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1060
Debian-bug-id: 282061

2 years agocommon: Add a function for copying data from one iobuf to another.
Neal H. Walfield [Thu, 5 Nov 2015 11:19:45 +0000 (12:19 +0100)]
common: Add a function for copying data from one iobuf to another.

* common/iobuf.c (iobuf_copy): New function.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agodoc: Note that gpgkey2ssh is deprecated.
Neal H. Walfield [Thu, 5 Nov 2015 13:08:49 +0000 (14:08 +0100)]
doc: Note that gpgkey2ssh is deprecated.

* doc/tools.texi (gpgkey2ssh): Note that gpgkey2ssh is deprecated.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2 years agotools: Fix gpgkey2ssh's most gratuitous errors. Use gpg2, not gpg.
Neal H. Walfield [Thu, 5 Nov 2015 12:59:33 +0000 (13:59 +0100)]
tools: Fix gpgkey2ssh's most gratuitous errors.  Use gpg2, not gpg.

* tools/gpgkey2ssh.c (main): Add support for --help.  Replace the most
gratuitous asserts with error messages.  Invoke gpg2, not gpg.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Debian-bug-id: 380241

2 years agodoc: Add documentation for gpgkey2ssh.
Neal H. Walfield [Thu, 5 Nov 2015 12:57:32 +0000 (13:57 +0100)]
doc: Add documentation for gpgkey2ssh.

* doc/tools.texi: Add documentation for gpgkey2ssh.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Co-authored-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
GnuPG-bug-id: 1067
Debian-bug-id 380241

2 years agogpg: Print a better error message for --multifile --sign --encrypt.
Neal H. Walfield [Wed, 4 Nov 2015 12:27:49 +0000 (13:27 +0100)]
gpg: Print a better error message for --multifile --sign --encrypt.

* g10/gpg.c (main): Print a better error message for --multifile
--sign --encrypt.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 1009

2 years agogpg: Add --encrypt-to-default-key.
Neal H. Walfield [Tue, 3 Nov 2015 22:39:46 +0000 (23:39 +0100)]
gpg: Add --encrypt-to-default-key.

* g10/getkey.c (parse_def_secret_key): Drop the static qualifier and
export the function.
* g10/gpg.c (enum cmd_and_opt_values): Add value oEncryptToDefaultKey.
(opts): Handle oEncryptToDefaultKey.
(main): Likewise.
* g10/options.h (opt): Add field encrypt_to_default_key.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 807

2 years agogpg: Allow multiple --default-key options. Take the last available key.
Neal H. Walfield [Tue, 3 Nov 2015 22:15:27 +0000 (23:15 +0100)]
gpg: Allow multiple --default-key options.  Take the last available key.

* g10/getkey.c (parse_def_secret_key): New function.
(get_seckey_default): Add parameter ctrl.  Update callers.  Use
parse_def_secret_key to get the default secret key, if any.
(getkey_byname): Likewise.
(enum_secret_keys): Likewise.
* g10/options.h (opt): Change def_secret_key's type from a char * to a
strlist_t.
* g10/gpg.c (main): When processing --default-key, add the key to
OPT.DEF_SECRET_KEY.
* g10/gpgv.c (get_session_key): Add parameter ctrl.  Update callers.
* g10/mainproc.c (proc_pubkey_enc): Likewise.
(do_proc_packets): Likewise.
* g10/pkclist.c (default_recipient): Likewise.
* g10/pubkey-enc.c (get_session_key): Likewise.
* g10/sign.c (clearsign_file): Likewise.
(sign_symencrypt_file): Likewise.
* g10/skclist.c (build_sk_list): Likewise.
* g10/test-stubs.c (get_session_key): Likewise.

--
Signed-off-by: Neal H. Walield <neal@g10code.com>
GnuPG-bug-id: 806