gnupg.git
11 months agoRelease 2.1.18 gnupg-2.1.18
Werner Koch [Mon, 23 Jan 2017 18:26:37 +0000 (19:26 +0100)]
Release 2.1.18

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agobuild: Change make distcheck configure and temp. remove gpgconf.scm.
Werner Koch [Mon, 23 Jan 2017 20:14:32 +0000 (21:14 +0100)]
build: Change make distcheck configure and temp. remove gpgconf.scm.

* Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Also test gpgtar and
wks-tools.  Disable ntbtls.
* tests/openpgp/Makefile.am (XTESTS): Temporary remove gpgconf.scm.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agopo: Auto update
Werner Koch [Mon, 23 Jan 2017 18:26:12 +0000 (19:26 +0100)]
po: Auto update

--

11 months agopo: Translate two new strings to German
Werner Koch [Mon, 23 Jan 2017 18:24:48 +0000 (19:24 +0100)]
po: Translate two new strings to German

--

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agoUpdate copyright notices for 2017.
Werner Koch [Mon, 23 Jan 2017 18:16:55 +0000 (19:16 +0100)]
Update copyright notices for 2017.

--

Also some http:// -> https:// fixes.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agoFix format string errors and some missing error case initialization.
Werner Koch [Mon, 23 Jan 2017 15:32:44 +0000 (16:32 +0100)]
Fix format string errors and some missing error case initialization.

* common/logging.c (do_logv): Remove extra parentheses in comparison.

* dirmngr/dns-stuff.c (resolve_addr_libdns): Init RES so that
dns_res_close is given a defined value in the error case.

* dirmngr/http.c (cookie_read, cookie_write) [HTTP_USE_NTBTLS]: Fix
format string char.

* dirmngr/ks-engine-hkp.c (ks_hkp_help): Remove duplicate "const".
* dirmngr/ks-engine-http.c (ks_http_help): Ditto.
* dirmngr/ks-engine-kdns.c (ks_kdns_help): Ditto.
* dirmngr/ks-engine-ldap.c (ks_ldap_help): Ditto.

* scd/app-p15.c (send_keypairinfo, do_getattr): Fix format string
char.
* tools/gpgconf-comp.c (gpg_agent_runtime_change): Init PID for the
error case.
(scdaemon_runtime_change): Ditto.
(dirmngr_runtime_change): Ditto.

* tools/gpgconf.c (query_swdb): Init VALUE_SIZE_UL.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agodirmngr: On SIGHUP mark all keyservers alive.
Werner Koch [Mon, 23 Jan 2017 12:07:54 +0000 (13:07 +0100)]
dirmngr: On SIGHUP mark all keyservers alive.

* dirmngr/ks-engine-hkp.c (ks_hkp_reload): New.
* dirmngr/dirmngr.c (dirmngr_sighup_action): Call it.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agolibdns: Hack to skip negation term.
Gaetan Bisson [Mon, 23 Jan 2017 11:46:35 +0000 (12:46 +0100)]
libdns: Hack to skip negation term.

* dirmngr/dns.c (dns_nssconf_loadfile): Skip negation terms in
nsswitch.conf parser.
--

This small patch was submitted along with this comment:

  We've been having issues over at Arch Linux with the new libdns
  code.  Our /etc/nsswitch.conf contains the following line:

    hosts: files mymachines resolve [!UNAVAIL=return] dns myhostname

  And it turns out dirmngr fails to parse the negation statement (the
  bang in !UNAVAIL). This results in gnupg not being able to resolve
  any name.

  Looking at dirmngr/dns.c it was unclear to me how to properly handle
  such negations. The dns_anyconf_scan calls used in
  dns_nssconf_loadfile do not allow to store a negation bit easily...

  In the meantime, I wrote the attached patch which ignores those
  statements altogether. It makes libdns work as expected for us.

Commit log written by wk

11 months agodirmngr: Print debug message only with --debug.
Werner Koch [Mon, 23 Jan 2017 10:39:10 +0000 (11:39 +0100)]
dirmngr: Print debug message only with --debug.

* dirmngr/dns-stuff.c (libdns_init): Call log_debug only if opt_debug
is set.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agodirmngr: Handle missing nsswitch.conf.
Phil Pennock [Thu, 19 Jan 2017 06:21:42 +0000 (01:21 -0500)]
dirmngr: Handle missing nsswitch.conf.

* dirmngr/dns-stuff.c (libdns_init): Fallback to files,dns.

--

Signed-off-by: Phil Pennock <phil@pennock-tech.com>
ChangeLog entry by wk.

This fixed the problem:

  Short version: macOS doesn't include /etc/nsswitch.conf and GnuPG's
  dirmngr is hard-erroring when that file is missing, such that no DNS
  operations succeed and --recv-key returns ENOENT type errors to the
  caller.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agodco: Register Phil Pennock.
Werner Koch [Mon, 23 Jan 2017 09:54:39 +0000 (10:54 +0100)]
dco: Register Phil Pennock.

--

11 months agogpg: Fix misleading log message when checking regexp.
Damien Goutte-Gattat [Tue, 17 Jan 2017 19:42:09 +0000 (20:42 +0100)]
gpg: Fix misleading log message when checking regexp.

* src/trustdb.c (check_regexp): Correctly print whether the
regexp matched or not.
--

This patch fixes the log message displayed when gpg attempts to
match the regexp associated with a trust signature with an user ID.
The current message interprets the 'ret' variable backwards, and
displays 'YES' when the regexp actually fails to match.

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
11 months agopo: Fixes to the German translation
Werner Koch [Mon, 23 Jan 2017 09:33:11 +0000 (10:33 +0100)]
po: Fixes to the German translation

--

Justus reported that the German translation for the key listing in
--edit-key does "usage: E" -> "Aufruf: E" which is clearly wrong.  It
turnd out that this translation was once marked as fuzzy and
accidentally unfuzzied by me.

   "Aufruf" (bug) -> "Nutzung"
   "Leistungsfähigkeit" -> "Nutzung"
   "Signaturfähigkeit" -> "Signaturnutzbarkeit" etc.

The last two are in the key generation menu.  Also changed the key
code for "Umschalten der Signaturnutzbarkeit" from "U" to "S".

"Nutzung" is here better than "Fähigkeit" because the latter is more
connected to the property of the algorithm, where the former better
expresses an arbitrary choice.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agogpg: New export and import options "backup" and "restore".
Werner Koch [Mon, 23 Jan 2017 09:12:18 +0000 (10:12 +0100)]
gpg: New export and import options "backup" and "restore".

* g10/export.c (parse_export_options): Add "backup" and its alias
"export-backup".
(do_export_one_keyblock): Export ring trust packets in backup mode.
* g10/import.c (parse_import_options): Add "restore" and its alias
"import-restore".
(read_block): Import ring trust packets.
--

These options are intended to, well, backup and restore keys between
GnuPG implementations.  These options may eventually be enhanced to
backup and restore all public key related information.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agoscd: Fix INTERRUPT transfer.
NIIBE Yutaka [Mon, 23 Jan 2017 07:12:41 +0000 (16:12 +0900)]
scd: Fix INTERRUPT transfer.

* scd/ccid-driver.c (find_endpoint): Don't return Bulk endpoint as
Interrupt endpoint.
(ccid_poll): Call libusb_interrupt_transfer.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
11 months agobuild: Print a commit id in the generated ChangeLog
Werner Koch [Thu, 19 Jan 2017 14:01:44 +0000 (15:01 +0100)]
build: Print a commit id in the generated ChangeLog

* build-aux/gitlog-to-changelog: Print an extra line with the commit
id.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agocommon: Fix buffer copy code again.
Werner Koch [Thu, 19 Jan 2017 13:58:23 +0000 (14:58 +0100)]
common: Fix buffer copy code again.

* common/exectool.c (my_error_from_errno): Remove.
(copy_buffer_do_copy): Do without var RC.
(copy_buffer_flush): Ditto.  Use ERRNO instead of es_write return
code.
(gnupg_exec_tool): Correctly return errors from es_read.
--

Fixes-commit: 55c9212a2338bf0b07c8cf3a69bcedaa28d48d43
Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agogpg: Allow to freeze faked system time.
Damien Goutte-Gattat [Wed, 18 Jan 2017 17:52:12 +0000 (18:52 +0100)]
gpg: Allow to freeze faked system time.

* g10/gpg.c (main): If the parameter for --faked-system-time
ends with a '!', freeze time at the specified point.
* common/gettime.c (gnupg_set_time): Allow to freeze the time
at an arbitrary time instead of only the current time.
* doc/gpg.texi: Update documentation for --faked-system-time.
--

This patch allows the user to modify the behavior of the
--faked-system-time option: by appending a '!' to the parameter,
time in GnuPG will be frozen at the specified time, instead of
advancing normally from that time onward.

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
11 months agocommon: Clarify use of vars in buffer copy code.
Werner Koch [Thu, 19 Jan 2017 08:57:27 +0000 (09:57 +0100)]
common: Clarify use of vars in buffer copy code.

* common/exectool.c (my_error_from_errno): New.
(copy_buffer_do_copy): Use separate vars for errno values and
gpg-error values for clarity.  s/assert/log_assert/.
(copy_buffer_flush): Ditto.
(gnupg_exec_tool_stream): Use gpg_err_code when testing.
--

NB: It is surprising that es_write seems not to set ERRNO but only
returns the ERRNO value.  Need to check whether this is really the
case.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 months agodirmngr: Add setup of CA for NTBTLS.
NIIBE Yutaka [Thu, 19 Jan 2017 06:39:55 +0000 (15:39 +0900)]
dirmngr: Add setup of CA for NTBTLS.

* dirmngr/http.c [HTTP_USE_NTBTLS] (http_session_new): Add CA by
ntbtls_set_ca_chain.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
11 months agocommon: Fix flushing copy buffers.
Justus Winter [Wed, 18 Jan 2017 17:14:41 +0000 (18:14 +0100)]
common: Fix flushing copy buffers.

* common/exectool.c (copy_buffer_flush): Write and flush the data, but
do not hide EAGAIN from the caller.
(gnupg_exec_tool_stream): Retry on EAGAIN.

GnuPG-bug-id: 2425
Signed-off-by: Justus Winter <justus@g10code.com>
12 months agoagent: Reduce sleep time in the progress callback.
Werner Koch [Wed, 18 Jan 2017 09:13:04 +0000 (10:13 +0100)]
agent: Reduce sleep time in the progress callback.

* agent/gpg-agent.c (agent_libgcrypt_progress_cb): Reduce sleep time
from 100ms to 1ms or use gpgrt_yield when build against a recent
libgpg-error.
--

Debian-bug-id: 851298
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpgconf: Allow "all" for --launch, --kill, and --reload.
Werner Koch [Wed, 18 Jan 2017 09:01:55 +0000 (10:01 +0100)]
gpgconf: Allow "all" for --launch, --kill, and --reload.

* tools/gpgconf-comp.c (gc_component_launch): Allow -1 for COMPONENT.
(gc_component_kill): Ditto.
(gc_component_reload): For robustness change the condition to < 0.
* tools/gpgconf.c (main) <aLaunch, aKill, aReload>: Support argument
"all".

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpg: Remove unused definitions.
Werner Koch [Tue, 17 Jan 2017 11:43:13 +0000 (12:43 +0100)]
gpg: Remove unused definitions.

* g10/keydb.h (rt_UNKNOWN, rt_RING): Remove constants.
(keyblock_pos_struct, KBPOS): Remove struct and type.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agoscd: Cleanup SERIALNO protocol.
NIIBE Yutaka [Wed, 18 Jan 2017 06:48:50 +0000 (15:48 +0900)]
scd: Cleanup SERIALNO protocol.

* scd/app.c (app_get_serial_and_stamp): Remove.
(app_get_serialno): New.
(app_write_learn_status): Use send_status_direct.
(app_getattr): Use app_get_serialno for SERIALNO and
send with send_status_direct.
* scd/app-openpgp.c (do_getattr): Likewise.
* scd/command.c (cmd_serialno): Don't send TIMESTAMP of 0.
(cmd_learn): Likewise.  Don't inquire with TIMESTAMP of 0.

--

In the SERIALNO protocol, timestamp used to be considered, but had never
used at all.  In the new implementation, removed card/token is always
detected and connection becomes invalid, no timestamp is required any
more.  Examined scute and poldi as well for this protocol change.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Add "card_list" sub command for GETINFO.
NIIBE Yutaka [Wed, 18 Jan 2017 06:19:38 +0000 (15:19 +0900)]
scd: Add "card_list" sub command for GETINFO.

* scd/app.c (app_send_card_list): New.
* scd/command.c (cmd_getinfo): Fix "status" sub command.
Add "card_list" sub command.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agobuild: Handle packages with dashes in --find-version.
Werner Koch [Tue, 17 Jan 2017 11:14:53 +0000 (12:14 +0100)]
build: Handle packages with dashes in --find-version.

* autogen.sh (--find-version): Improve version extraction.
* (--help): Extend.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpg: Clean bogus subkey binding when cleaning a key.
Werner Koch [Tue, 17 Jan 2017 09:26:34 +0000 (10:26 +0100)]
gpg: Clean bogus subkey binding when cleaning a key.

* g10/trust.c (clean_key): Also clean bogus subkey bindings.
--

GnuPG-bug-id: 2922
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpg: Sync print of additional sig data in --edit-key.
Werner Koch [Tue, 17 Jan 2017 09:23:52 +0000 (10:23 +0100)]
gpg: Sync print of additional sig data in --edit-key.

* g10/keylist.c (show_policy_url): Implement MODE -1.
(show_keyserver_url): Ditto.
(show_notation): Ditto.
* g10/keyedit.c (print_one_sig): Print policy URL, keyserver URL and
notation data to the tty.
--

With this change the listing of signatures in the key edit menu does
now include policy URLs et al in order and not possible after leaving
the menu (it used to go to stdout and not the tty).

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agocommon: Remove unused function tty_print_string.
Werner Koch [Tue, 17 Jan 2017 09:19:06 +0000 (10:19 +0100)]
common: Remove unused function tty_print_string.

* common/ttyio.c (tty_print_string): Rename to ...
(do_print_string): this.  Make local.  Simplify FP case by using
print_utf8_buffer.  Change caller.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpg: Prepare some key cleaning function for use with secret key packets.
Werner Koch [Tue, 17 Jan 2017 08:14:44 +0000 (09:14 +0100)]
gpg: Prepare some key cleaning function for use with secret key packets.

* g10/trust.c (mark_usable_uid_certs): Allow use of secret key packets.
(clean_sigs_from_uid): Ditto.
(clean_uid_from_key): Ditto.
(clean_one_uid): Ditto.
(clean_key): Ditto.
--

Since 2.1 secret keys and public keys use identical data structure and
thus we should not restrict those key cleaning functions to work only
with public key packets.  This change has no immediate effect but may
come handy in the future.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Implement hkps lookups using literal addresses.
Werner Koch [Mon, 16 Jan 2017 18:04:58 +0000 (19:04 +0100)]
dirmngr: Implement hkps lookups using literal addresses.

* dirmngr/ks-engine-hkp.c (map_host): For literal addresses do a
reverse lookup.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Allow reverse DNS lookups in Tor-mode.
Werner Koch [Mon, 16 Jan 2017 18:03:39 +0000 (19:03 +0100)]
dirmngr: Allow reverse DNS lookups in Tor-mode.

* dirmngr/dns-stuff.c (resolve_dns_name): Move up in the file.
(resolve_addr_libdns): New.
(resolve_dns_addr): Divert to resolve_dns_addr.
--

In the old code reverse lookups where disabled in Tor mode.  By
implementing the reverse lookups via libdns it is now possible to do
them also in Tor mode.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Avoid network queries for literal IP addresses.
Werner Koch [Mon, 16 Jan 2017 08:10:46 +0000 (09:10 +0100)]
dirmngr: Avoid network queries for literal IP addresses.

* dirmngr/dns-stuff.c (resolve_name_libdns): USe flags AI_NUMERICHOST
for literal IP addresses.
(resolve_name_standard): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Fix URL creation for literal IPv6 addresses in HKP.
Werner Koch [Thu, 12 Jan 2017 20:09:42 +0000 (21:09 +0100)]
dirmngr: Fix URL creation for literal IPv6 addresses in HKP.

* dirmngr/dns-stuff.c (is_ip_address): Make the return value depend on
the address family.
* dirmngr/ks-engine-hkp.c (map_host): Rename arg R_POOLNAME to
R_HTTPHOST because that is its purpose.  Note that the former
behaviour of storing a NULL to indicate that it is not a pool has not
been used.
(make_host_part): Ditto.
(make_host_part): Make sure that literal v6 addresses are correclty
marked in the constructed URL.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agotests: Improve GPGHOME handling.
Justus Winter [Mon, 16 Jan 2017 12:59:56 +0000 (13:59 +0100)]
tests: Improve GPGHOME handling.

* tests/openpgp/defs.scm (GPGHOME): New variable.
* tests/openpgp/ssh-import.scm: Remove redundant code, use 'path-join'.
* tests/openpgp/tofu.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agoagent: Ask specific SERIALNO for pksign/pkdecrypt.
NIIBE Yutaka [Mon, 16 Jan 2017 01:33:08 +0000 (10:33 +0900)]
agent: Ask specific SERIALNO for pksign/pkdecrypt.

* agent/call-scd.c (agent_card_serialno): Add DEMAND argument.
* agent/command-ssh.c (card_key_available): Follow the change.
* agent/learncard.c (agent_handle_learn): Likewise.
* agent/divert-scd.c (ask_for_card): Use DEMAND argument.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Add --demand option for SERIALNO.
NIIBE Yutaka [Mon, 16 Jan 2017 01:26:16 +0000 (10:26 +0900)]
scd: Add --demand option for SERIALNO.

* scd/app.c (select_application): Add SERIALNO_BIN and SERIALNO_BIN_LEN
arguments.  Return matched APP with a serial number when specified.
* scd/command.c (open_card): Modify for the implicit open only.
(open_card_with_request): New for explicit open and support match with a
serial number.
(cmd_serialno): Support --demand option.
(cmd_learn, cmd_readcert, cmd_readkey, cmd_pksign, cmd_pkauth)
(cmd_pkdecrypt, cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_apdu): Follow
the change of open_card.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agobuild: Make autogen.sh more POSIX friendly (next try)
Werner Koch [Thu, 12 Jan 2017 10:22:37 +0000 (11:22 +0100)]
build: Make autogen.sh more POSIX friendly (next try)

* autogen.sh: Fix dd count to 5.
--

Fixes-commit: 3c00b52f7cb0fbd756c0bbe5134b8f2d69c60dd1
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpg: Rename a var to avoid a shadowing warning.
Werner Koch [Thu, 12 Jan 2017 09:40:26 +0000 (10:40 +0100)]
gpg: Rename a var to avoid a shadowing warning.

* g10/keygen.c (keygen_set_std_prefs): Rename variable.
--

I consider it better not to use the name of a commonly used function.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agotests: Fix t-gettime for a time_t of 64 and a long of 32 bit.
Werner Koch [Thu, 12 Jan 2017 09:39:19 +0000 (10:39 +0100)]
tests: Fix t-gettime for a time_t of 64 and a long of 32 bit.

* configure.ac (AC_CHECK_HEADERS): Add stdint.h.
* common/t-gettime.c: Include stdint.h.
(UINTMAX_C): Define replacement.
(test_isotime2epoch): Use UINTMAX_C for the >32 bit constants.
--

This is for example the case on 32 bit OpenBSD.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agobuild: Make autogen.sh more POSIX friendly.
Werner Koch [Thu, 12 Jan 2017 08:58:57 +0000 (09:58 +0100)]
build: Make autogen.sh more POSIX friendly.

* autogen.sh: Replace non POSIX "cp -a" and "head -c".
--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agolibdns: Silence -Wstrict-prototypes on some function ptrs.
Werner Koch [Thu, 12 Jan 2017 08:22:14 +0000 (09:22 +0100)]
libdns: Silence -Wstrict-prototypes on some function ptrs.

* dirmngr/dns.c (dns_rrtype): Ignore -Wstrict-prototypes warning.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agolibdns: Provide replacement for EPROTO.
Werner Koch [Thu, 12 Jan 2017 08:20:49 +0000 (09:20 +0100)]
libdns: Provide replacement for EPROTO.

* dirmngr/dns.c (EPROTO) ![EPROTO]: Define to EPROTONOSUPPORT.
--

This is the same replacement we use in Libassuan
(commit 8ab3b9273524bd344bdb90dd5d3bc8e5f53ead6e) to make it work on
OpenBSD and may other BSD based OSes.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: After a connection failure log a hint if Tor is not running.
Werner Koch [Wed, 11 Jan 2017 16:09:16 +0000 (17:09 +0100)]
dirmngr: After a connection failure log a hint if Tor is not running.

* dirmngr/ks-engine-hkp.c (handle_send_request_error): Check whether
Tor is running.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Mark hosts dead on ENETDOWN.
Werner Koch [Wed, 11 Jan 2017 15:43:30 +0000 (16:43 +0100)]
dirmngr: Mark hosts dead on ENETDOWN.

* dirmngr/ks-engine-hkp.c (handle_send_request_error): Take care of
ENETDOWN.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Fix Tor access for v6 addresses.
Werner Koch [Wed, 11 Jan 2017 15:41:15 +0000 (16:41 +0100)]
dirmngr: Fix Tor access for v6 addresses.

* dirmngr/http.c (use_socks): New.
(my_sock_new_for_addr): New.
(connect_server): Replace assuan_sock_new by my_sock_new_for_addr.
--

Libassuan always uses 127.0.0.1 to connect to the local Tor proxy.
https.c used to create a socket for the actual address family and thus
the connect call in Libassuan fails when it tries to connect to a v6
address using a v4 socket.

It would be cleaner to have the my_sock_new_for_addr function as a
public interface in Libassuan; for now we need to duplicate some code.
from Libassuan.

GnuPG-bug-id: 2902
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Remove warnings about unused global variables.
Werner Koch [Wed, 11 Jan 2017 09:48:20 +0000 (10:48 +0100)]
dirmngr: Remove warnings about unused global variables.

* dirmngr/crlcache.c (oidstr_issuingDistributionPoint): Comment.
* dirmngr/ocsp.c (oidstr_certHash): Comment.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Implement debug option "network" for http.
Werner Koch [Wed, 11 Jan 2017 09:35:46 +0000 (10:35 +0100)]
dirmngr: Implement debug option "network" for http.

* dirmngr/dirmngr.c (parse_rereadable_options): Set http debugging.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Add debug code to http.c.
Werner Koch [Wed, 11 Jan 2017 09:34:49 +0000 (10:34 +0100)]
dirmngr: Add debug code to http.c.

* dirmngr/http.c (opt_verbose, opt_debug): New vars.
(http_set_verbose): New function.
(_my_socket_new): Add debug output.
(_my_socket_ref, _my_socket_unref, session_unref): Call log_debug if
OPT_DEBUG has ben set to 2 in a debugger.
(http_session_new, http_session_ref): Ditto.
(send_request, http_start_data): Print debug output for the request.
(parse_response): Change to use log_debug_string for the response.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agocommon: New function log_debug_with_string.
Werner Koch [Wed, 11 Jan 2017 09:21:32 +0000 (10:21 +0100)]
common: New function log_debug_with_string.

* common/logging.c (do_logv): Factor some code out to ...
(print_prefix): new.
(log_logv): Add arg EXTRASTRING and print it.  Change all callers to
pass NULL for it.
(log_debug_with_string): New.  Uses EXTRASTRING.
--

This function can be used to print a human readable buffer in addition
to a log message to the log stream.  This function will keep all lines
together and prefix them with ">> ".

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agocommon: Avoid unnecessary ambiguity in argparse.
Daniel Kahn Gillmor [Tue, 10 Jan 2017 20:59:36 +0000 (15:59 -0500)]
common: Avoid unnecessary ambiguity in argparse.

* common/argparse.c (find_long_option): Avoid unnecessary ambiguity.
--

If two struct ARGPARSE_OPTS share a prefix in their long_opt name, but
have the exact same short_opt and flags, they are aliases and not
distinct options.  Avoid reporting this as an ambiguity, so that (for
example) both --clearsign and --clear-sign can be invoked as --clear.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Debian-Bug-Id: 850475

12 months agosystemd-user: Enable "systemctl --user reload {dirmngr,gpg-agent}"
Daniel Kahn Gillmor [Tue, 10 Jan 2017 22:12:09 +0000 (17:12 -0500)]
systemd-user: Enable "systemctl --user reload {dirmngr,gpg-agent}"

* doc/examples/systemd-user/*.service: Add ExecReload directives to
  indicate the canonical way to reload the services.

GnuPG recommends reloading the agent and dirmngr with "gpgconf
--reload".  if anyone is running them as systemd user services, they
might ask them to reload in the systemd way, so teach systemd the
right thing to do.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
12 months agodoc: Mention dirmngr.conf
Werner Koch [Tue, 10 Jan 2017 15:24:31 +0000 (16:24 +0100)]
doc: Mention dirmngr.conf

--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agotests: Improve gpgconf test.
Justus Winter [Tue, 10 Jan 2017 14:50:57 +0000 (15:50 +0100)]
tests: Improve gpgconf test.

* tests/openpgp/defs.scm (valgrind): New variable.
(gpg-config): Fix clearing an option.
* tests/openpgp/gpgconf.scm: Also toggle 'quiet'.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agotools: Fix memory leaks and improve error handling.
Justus Winter [Tue, 10 Jan 2017 14:42:27 +0000 (15:42 +0100)]
tools: Fix memory leaks and improve error handling.

* tools/gpgconf-comp.c (gc_option_free): New function.
(gc_components_free): Likewise.
(gc_components_init): Likewise.
(retrieve_options_from_program): Use 'xfree', fix memory leak.
(change_options_program): Improve error handling.
(gc_component_change_options): Fix memory leaks.
* tools/gpgconf.c (main): Initialize components.
* tools/gpgconf.h (gc_components_init): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agotests: Add test for gpgconf.
Justus Winter [Tue, 10 Jan 2017 11:38:07 +0000 (12:38 +0100)]
tests: Add test for gpgconf.

* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/defs.scm (percent-encode): New function.
(gpg-conf): Generalize so that we can feed stdin.
(gpg-config): New function.
* tests/openpgp/gpgconf.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agocommon: Fix fallback code.
Justus Winter [Tue, 10 Jan 2017 11:31:46 +0000 (12:31 +0100)]
common: Fix fallback code.

* common/logging.c (_log_assert): Fix the variant for compilers that
do not support __FUNCTION__.
* common/logging.h (_log_assert): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agodirmngr: Use "pgpkey-hkps" and "pgpkey-hkp" for SRV record lookups.
Werner Koch [Mon, 9 Jan 2017 09:42:30 +0000 (10:42 +0100)]
dirmngr: Use "pgpkey-hkps" and "pgpkey-hkp" for SRV record lookups.

* dirmngr/ks-engine-hkp.c (map_host): Chnage arg NO_SRV to SRVTAG.
(make_host_part): Rewrite.
--

This fixes a regression from 2.0 and 1.4 where these tags have been in
used since 2009.  For whatever reason this was not ported to 2.1 and
"hkp" was always used.

GnuPG-bug-id: 2451
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Do not use a SRV record for HKP if a port was specified.
Werner Koch [Mon, 9 Jan 2017 09:11:20 +0000 (10:11 +0100)]
dirmngr: Do not use a SRV record for HKP if a port was specified.

* dirmngr/http.h (parsed_uri_s): Add field EXPLICIT_PORT.
* dirmngr/http.c (do_parse_uri): That it.
* dirmngr/ks-engine-hkp.c (map_host): Add arg NO_SRV.
(make_host_part): Ditto.
(ks_hkp_resolve): Set NO_SRV from EXPLICIT_PORT.
(ks_hkp_search): Ditto.
(ks_hkp_get): Ditto.
(ks_hkp_put): Ditto.
--

This implements the behaviour of the keyserver helpers from 1.4 and
2.0.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodoc: Update man page for watchgnupg
Werner Koch [Mon, 9 Jan 2017 07:54:45 +0000 (08:54 +0100)]
doc: Update man page for watchgnupg

--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Implement experimental SRV record lookup for WKD.
Werner Koch [Sun, 8 Jan 2017 17:42:50 +0000 (18:42 +0100)]
dirmngr: Implement experimental SRV record lookup for WKD.

* dirmngr/server.c (cmd_wkd_get): Support SRV records.
--

This patch changes the way a WKD query is done.  Now we first look for
a SRV record for service "openpgpkey" and port "tcp" under the
to-be-queried domain.  If such a record was found and the target host
matches the to-be-queried domain or is a suffix to that domain, that
target host is used instead of the domain name.  The SRV record also
allows to change the port and obviously can be used for
load-balancing.

For example a query for the submission address of example.org with the
SRV record specification

_openpgpkey._tcp        IN     SRV   0 0  0    wkd.foo.org.
                        IN     SRV   0 0  0    wkd.example.net.
                        IN     SRV   0 0  4711 wkd.example.org.

(queried using the name "_openpgpkey._tcp.example.org") would fetch
from this URL:

 https://wkd.example.org:4711/.well-known/openpgpkey/submission-address

Note that the first two SRV records won't be used because foo.org and
example.net do not match example.org.  We require that the target host
is identical to the domain or be a subdomain of it.  This is so that
an attacker modifying the SRV records needs to setup a server in a
sub-domain of the actual domain and can't use an arbitrary domain.
Whether this is a sufficient requirement is not clear and needs
further discussion.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Improve debug output for TLS.
Werner Koch [Sun, 8 Jan 2017 17:07:18 +0000 (18:07 +0100)]
dirmngr: Improve debug output for TLS.

* dirmngr/misc.c (dump_cert): Also print SubjectAltNames.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Change internal SRV lookup API.
Werner Koch [Sun, 8 Jan 2017 17:04:59 +0000 (18:04 +0100)]
dirmngr: Change internal SRV lookup API.

* dirmngr/dns-stuff.c (get_dns_srv): Add args SERVICE and PROTO.
* dirmngr/http.c (connect_server): Simplify SRV lookup.
* dirmngr/ks-engine-hkp.c (map_host): Ditto.
* dirmngr/t-dns-stuff.c (main): Adjust for changed get_dns_srv.
--

This new API is more convenient because it includes commonly used
code.  Note that right now http.c's SRV record code is not used.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Strip root zone suffix from libdns SRV results.
Werner Koch [Sun, 8 Jan 2017 17:00:38 +0000 (18:00 +0100)]
dirmngr: Strip root zone suffix from libdns SRV results.

* dirmngr/dns-stuff.c (getsrv_libdns): Strip trailing dot from the
target.
--

See-also: b200e636ab20d2aa93d9f71f3789db5a04af0a56
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agoagent,w32: Fix annoying output to DebugView.
Werner Koch [Fri, 6 Jan 2017 17:45:14 +0000 (18:45 +0100)]
agent,w32: Fix annoying output to DebugView.

* agent/gpg-agent.c (startup_fd_list): Do not define for W32.
(main) [W32]: Do not call get_all_open_fds.
--

GnuPG-bug-id: 2267
Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodoc: Document summary values of TOFU_STATS
Andre Heinecke [Fri, 6 Jan 2017 11:26:01 +0000 (12:26 +0100)]
doc: Document summary values of TOFU_STATS

--

Signed-off-by: Andre Heinecke <aheinecke@intevation.de>
12 months agoscd: Fix for --disable-ccid for scdaemon.
NIIBE Yutaka [Fri, 6 Jan 2017 01:35:46 +0000 (10:35 +0900)]
scd: Fix for --disable-ccid for scdaemon.

* scd/apdu.c (apdu_dev_list_finish): Don't call ccid_dev_scan_finish
with no table.
(apdu_open_reader): Only increment when it's zero.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Fix for --disable-ccid-driver.
NIIBE Yutaka [Fri, 6 Jan 2017 01:07:40 +0000 (10:07 +0900)]
scd: Fix for --disable-ccid-driver.

* scd/apdu.c [HAVE_LIBUSB] (apdu_dev_list_start): Conditionalize.
[HAVE_LIBUSB] (apdu_dev_list_finish, apdu_open_reader): Likewise.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Support multiple readers by CCID driver.
NIIBE Yutaka [Fri, 6 Jan 2017 00:14:13 +0000 (09:14 +0900)]
scd: Support multiple readers by CCID driver.

* scd/apdu.c (new_reader_slot): Lock is now in apdu_dev_list_start.
(close_pcsc_reader_direct, close_ccid_reader): RDRNAME is handled...
(apdu_close_reader): ... by this function now.
(apdu_prepare_exit): Likewise.
(open_ccid_reader): Open with dev_list.
(apdu_dev_list_start, apdu_dev_list_finish): New.
(apdu_open_one_reader): New.
(apdu_open_reader): Support multiple readers.
* scd/app.c (select_application): With SCAN, opening all readers
available, and register as new APP.
(app_write_learn_status): app->ref_count == 0 is valid for APP which is
not yet used.
(app_list_start, app_list_finish): New.
* scd/ccid-driver.c (struct ccid_driver_s): Remove RID and BCD_DEVICE.
Add BAI.
(parse_ccid_descriptor): BCD_DEVICE is now on the arguments.
(ccid_dev_scan, ccid_dev_scan_finish): New.
(ccid_get_BAI, ccid_compare_BAI, ccid_open_usb_reader): New.
(ccid_open_reader): Support multiple readers.
(ccid_set_progress_cb, ccid_close_reader): No RID any more.
--

With this change, multiple readers/tokens are supported by the internal
CCID driver of GnuPG.  Until the changes of upper layers (scdaemon,
gpg-agent, and gpg front end), only a single reader is used, though.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoSilence two -Wlogical-op warnings.
Werner Koch [Thu, 5 Jan 2017 19:42:55 +0000 (20:42 +0100)]
Silence two -Wlogical-op warnings.

* common/tlv.c (parse_ber_header): Avoid compiler warning about a
duplicate condition.
* tools/gpgtar-create.c (pattern_valid_p): Likewise.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodoc: Mention gpgv in the description of gpg --verify.
Werner Koch [Thu, 5 Jan 2017 19:25:16 +0000 (20:25 +0100)]
doc: Mention gpgv in the description of gpg --verify.

--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agotests: New test for --{show,override}-session-key.
Justus Winter [Thu, 5 Jan 2017 16:05:59 +0000 (17:05 +0100)]
tests: New test for --{show,override}-session-key.

* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/decrypt-session-key.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agotests: Fix macro.
Justus Winter [Thu, 5 Jan 2017 16:00:36 +0000 (17:00 +0100)]
tests: Fix macro.

* tests/openpgp/defs.scm (with-ephemeral-home-directory): Make
hygienic, use define-macro, do not change to the ephemeral home
directory.
* tests/gpgsm/setup.scm: Change to the ephemeral home directory.
* tests/openpgp/setup.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agog10: avoid warning when --disable-tofu
Daniel Kahn Gillmor [Wed, 4 Jan 2017 13:31:06 +0000 (08:31 -0500)]
g10: avoid warning when --disable-tofu

If configured with --disable-tofu, we see compiler warnings about an
unused variable.  This should remove those warnings.

12 months agodoc: Add release announcement pointers to NEWS entries.
Werner Koch [Wed, 4 Jan 2017 17:37:36 +0000 (18:37 +0100)]
doc: Add release announcement pointers to NEWS entries.

--

These are used by the website buider to link to the announcement
mails.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agotests,w32: Fix locating the components.
Justus Winter [Wed, 4 Jan 2017 15:54:41 +0000 (16:54 +0100)]
tests,w32: Fix locating the components.

* tests/openpgp/defs.scm (percent-decode): New function.
(bin-prefix): New variable.
(installed?): Likewise.
(tool-hardcoded): Use the new variables.
(gpg-conf): Use the new function to decode the values.
(gpg-components): Do not use '--build-prefix' when 'installed?'.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agodoc: Extend dirmngr's --allow-version-check description
Werner Koch [Tue, 3 Jan 2017 12:12:25 +0000 (13:12 +0100)]
doc: Extend dirmngr's --allow-version-check description

--

12 months agodirmngr: Make sure Tor mode is also set for DNS on SIGHUP.
Werner Koch [Tue, 3 Jan 2017 11:03:28 +0000 (12:03 +0100)]
dirmngr: Make sure Tor mode is also set for DNS on SIGHUP.

* dirmngr/dns-stuff.c (enable_dns_tormode): Always succeed.
(reload_dns_stuff): Reset tor port.
* dirmngr/dirmngr.c (set_tor_mode): Also enable Tor mode for DNS.
(main): Remove warning that Tor mode may not fully work.
* dirmngr/server.c (cmd_dns_cert): Remove explicit Tor for DNS
initialization.
* dirmngr/t-dns-stuff.c (main): Remove option --new-circuit and error
checking for enable_dns_tormode.
--

This patch also resets the port on SIGHUP so that after starting Tor
SIGHUP is sufficient to use Tor.  Without the SIGHUP and when not
using the Tor browser Dirmngr would keep on trying the Tor browser
port.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: New debug message on correctly initialized libdns.
Werner Koch [Mon, 2 Jan 2017 14:47:24 +0000 (15:47 +0100)]
dirmngr: New debug message on correctly initialized libdns.

* dirmngr/dns-stuff.c (libdns_init): Add debug level diagnostic on
success.
--

This output may help to avoid questions when evaluating an Assuan log.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agocommon: Turn assertions into expressions.
Justus Winter [Mon, 2 Jan 2017 15:30:45 +0000 (16:30 +0100)]
common: Turn assertions into expressions.

* common/logging.h (log_assert): Turn this into an expression so it
can be used in expressions.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agotests: Fix faked time in the TOFU test.
Justus Winter [Mon, 2 Jan 2017 15:37:02 +0000 (16:37 +0100)]
tests: Fix faked time in the TOFU test.

* tests/openpgp/tofu.scm (GPG): Fix time delta.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agog13: Improve printing of debug infos.
Werner Koch [Mon, 2 Jan 2017 12:30:37 +0000 (13:30 +0100)]
g13: Improve printing of debug infos.

* g13/g13tuple.c (all_printable): Make it work.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agoReplace use of variable-length-arrays.
Werner Koch [Mon, 2 Jan 2017 12:29:18 +0000 (13:29 +0100)]
Replace use of variable-length-arrays.

* common/t-iobuf.c (main): Replace variable-length-array.
* g10/gpgcompose.c (mksubpkt_callback): Ditto.
(encrypted): Ditto.
* g10/t-stutter.c (log_hexdump): Ditto.
(oracle_test): Ditto.
* g10/tofu.c (get_policy): Ditto.  Use "%zu" for size_t.
* scd/app-openpgp.c (ecc_writekey): Replace variable-length-array.
Check for zero length OID_LEN.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agobuild: Enable gcc warnings to detect non-portable code.
Werner Koch [Mon, 2 Jan 2017 11:59:10 +0000 (12:59 +0100)]
build: Enable gcc warnings to detect non-portable code.

--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agogpgscm: Fail if too many arguments are given.
Justus Winter [Thu, 22 Dec 2016 14:48:07 +0000 (15:48 +0100)]
gpgscm: Fail if too many arguments are given.

* tests/gpgscm/scheme.c (opexe_0): Enable check.
* tests/gpgscm/tests.scm (test::report): Remove superfluous argument.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agogpgscm: Add 'finally', rework all macros.
Justus Winter [Thu, 22 Dec 2016 13:42:50 +0000 (14:42 +0100)]
gpgscm: Add 'finally', rework all macros.

* tests/gpgscm/init.scm (finally): New macro.
* tests/gpgscm/tests.scm (letfd): Rewrite.
(with-working-directory): Likewise.
(with-temporary-working-directory): Likewise.
(lettmp): Likewise.
--

Rewrite all our macros using 'define-macro'. Use the new control flow
mechanism 'finally', or 'dynamic-wind' where appropriate.  Make sure
the macros are hygienic.  Reduce code duplication.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agogpgscm: Use boxed values for source locations.
Justus Winter [Thu, 22 Dec 2016 09:36:56 +0000 (10:36 +0100)]
gpgscm: Use boxed values for source locations.

* tests/gpgscm/scheme-private.h (struct port): Use boxed values for
filename and current line.  This allows us to use the same Scheme
object for labeling all expressions in a file.
* tests/gpgscm/scheme.c (file_push): Use boxed type for filename.
(mark): Mark location objects of port objects.
(gc): Mark location objects in the load stack.
(port_clear_location): New function.
(port_reset_current_line): Likewise.
(port_increment_current_line): Likewise.
(file_pop): Adapt accordingly.
(port_rep_from_filename): Likewise.
(port_rep_from_file): Likewise.
(port_close): Likewise.
(skipspace): Likewise.
(token): Likewise.
(_Error_1): Likewise.
(opexe_0): Likewise.
(opexe_5): Likewise.
(scheme_deinit): Likewise.
(scheme_load_file): Likewise.
(scheme_load_named_file): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
12 months agodoc: Remove warning that DNS is not routed via Tor
Werner Koch [Mon, 2 Jan 2017 09:39:59 +0000 (10:39 +0100)]
doc: Remove warning that DNS is not routed via Tor

--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agodirmngr: Strip root zone suffix from libdns cname results.
Werner Koch [Mon, 2 Jan 2017 09:00:33 +0000 (10:00 +0100)]
dirmngr: Strip root zone suffix from libdns cname results.

* dirmngr/dns-stuff.c (resolve_name_libdns): Strip trailing dot.
(get_dns_cname_libdns): Ditto.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
12 months agoscd: Fix select_application.
NIIBE Yutaka [Fri, 30 Dec 2016 06:17:50 +0000 (15:17 +0900)]
scd: Fix select_application.

* scd/app.c (select_application): Fix the condition for open.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Fix card removal monitor.
NIIBE Yutaka [Fri, 30 Dec 2016 04:17:49 +0000 (13:17 +0900)]
scd: Fix card removal monitor.

* scd/app.c (app_reset): Call send_client_notification with REMOVAL.
(scd_update_reader_status_file): Likewise.
* scd/command.c (send_client_notifications): Distinguish removal.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Improve internal CCID driver.
NIIBE Yutaka [Thu, 29 Dec 2016 02:31:25 +0000 (11:31 +0900)]
scd: Improve internal CCID driver.

* scd/ccid-driver.c (scan_or_find_usb_device): Don't scan for
configuration but use active configuration.  Support alt_setting.
(scan_or_find_devices): Support alt_setting.
(ccid_open_reader): Support alt_setting.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Fix a race condition for new_reader_slot.
NIIBE Yutaka [Thu, 29 Dec 2016 01:07:43 +0000 (10:07 +0900)]
scd: Fix a race condition for new_reader_slot.

* scd/apdu.c (reader_table_lock, apdu_init): New.
(new_reader_slot): Serialize by reader_table_lock.
* scd/app.c (lock_app, unlock_app, app_new_register): Fix error code
usage.
(initialize_module_command): Call apdu_init.
* scd/scdaemon.c (main): Handle error for initialize_module_command.

--

This is a long standing bug.  There are two different things; The
serialization of allocating a new SLOT, and the serialization of using
the SLOT.  The latter was implemented in new_reader_slot by lock_slot.
However, the former was not done.  Thus, there was a possible race where
a same SLOT is allocated to multiple threads.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: APP centric approach for device management.
NIIBE Yutaka [Wed, 28 Dec 2016 03:29:17 +0000 (12:29 +0900)]
scd: APP centric approach for device management.

* scd/app.c (lock_app): Rename from lock_reader and use internal field
of APP.
(unlock_app): Likewise.
(app_dump_state): Use APP.
(application_notify_card_reset): Remove.
(check_conflict): Change API for APP, instead of SLOT.
(check_application_conflict): Likewise.
(release_application_internal): New.
(app_reset): New.
(app_new_register): New.
(select_application): Change API for APP, instead of SLOT.
(deallocate_app, release_application): Modify for manage link.
(report_change): New.
(scd_update_reader_status_file): Moved from command.c and
use APP list, instead of VREADER.
(initialize_module_command): Moved from command.c.

* scd/command.c (TEST_CARD_REMOVAL): Remove.
(IS_LOCKED): Simplify.
(vreader_table): Remove.
(vreader_slot, update_card_removed): Remove.
(do_reset): Call app_reset.
(get_current_reader): Remove.
(open_card): Add SCAN arg.
(cmd_serialno): No retry, since retry is done in lower layer in apdu.c.
No do_reset, since it is done in lower layer.
Add clearing card_removed flag.
(cmd_disconnect): Call apdu_disconnect.
(send_client_notifications): Modify for APP.
(update_reader_status_file): Remove.

--

APP is the abstraction of the card application.  For management of
cards, it is better to focus on the APP instead of the physical reader.
This change makes support of multiple card/token easier.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Simplify monitoring card removal.
NIIBE Yutaka [Wed, 28 Dec 2016 02:14:29 +0000 (11:14 +0900)]
scd: Simplify monitoring card removal.

* scd/apdu.c (struct reader_table_s): Remove any_status, last_status,
status, and change_counter field.
(new_reader_slot, dump_reader_status, ct_activate_card, open_ct_reader)
(connect_pcsc_card, open_pcsc_reader_direct, open_pcsc_reader_wrapped)
(open_ccid_reader, apdu_reset): Follow the change.
(ct_dump_reader_status): Remove.
(apdu_get_status_internal, apdu_get_status): Remove CHANGED arg.
(apdu_connect): Follow the change.
* scd/command.c (struct vreader_s): Remove reset_failed, any, and
changed field.
(cmd_getinfo, update_reader_status_file): Follow the change.

--

In the past, scdaemon monitors card insertion (as well as removal), so
the code has been complicated, and there has been duplication in two
layers.  Now, it only monitors card removal, it's now simplified.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agoscd: Improve internal CCID driver.
NIIBE Yutaka [Tue, 27 Dec 2016 02:58:54 +0000 (11:58 +0900)]
scd: Improve internal CCID driver.

* scd/ccid-driver.c (scan_or_find_usb_device): Fix return value.
Support device with multiple CCID interfaces.  Fix the case with
READERNO.  Support partial string match of "reader-port" like PC/SC
driver.

--

I don't know any device with multiple CCID interfaces, though.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
12 months agodirmngr: Fix for --disable-libdns usage.
NIIBE Yutaka [Fri, 23 Dec 2016 07:05:01 +0000 (16:05 +0900)]
dirmngr: Fix for --disable-libdns usage.

* dirmngr/dns-stuff.c (enable_recursive_resolver, set_dns_nameserver)
(reload_dns_stuff): Conditionalize with USE_LIBDNS.
(get_h_errno_as_gpg_error): Map HOST_NOT_FOUND to GPG_ERR_NO_NAME.

--

get_dns_srv assumes error code of GPG_ERR_NO_NAME when no SRV record
available.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
GnuPG-bug-id: 2889

12 months agotools: Show a clearer error message if a server doesn't support WKS
Neal H. Walfield [Thu, 22 Dec 2016 15:06:13 +0000 (16:06 +0100)]
tools: Show a clearer error message if a server doesn't support WKS

* tools/gpg-wks-client.c (command_send): If we fail to lookup the
submission address, print a better error message.  If it is because
the corresponding file doesn't exist, provide the hint that the server
probably doesn't support WKS.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
12 months agowks: Let the client ignore missing policy flags.
Werner Koch [Thu, 22 Dec 2016 13:39:11 +0000 (14:39 +0100)]
wks: Let the client ignore missing policy flags.

* tools/gpg-wks-client.c (command_send): Ignore missing policy flags.

Signed-off-by: Werner Koch <wk@gnupg.org>