Commit Graph

6485 Commits

Author SHA1 Message Date
Justus Winter 445f0c13d7 Fix typos.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-27 14:59:56 +02:00
Justus Winter 66a0091d74 g10: Assert preconditions.
* g10/getkey.c (get_pubkey_byname): Assert preconditions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-27 14:43:29 +02:00
Werner Koch cf20b23c14
dirmngr: Do not implement --supervised in Windows.
* dirmngr/dirmngr.c (opts) [W32]: Remove --supervised.
(main) [W32]: Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-27 09:27:37 +02:00
Werner Koch a9c8b5fbe7
common: Remove debug output from gnupg_get_socket_name.
* common/sysutils.c (gnupg_get_socket_name): Remove debug message and
use my_error_from_syserror.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-27 09:27:37 +02:00
NIIBE Yutaka 45dfc02b47 dirmngr: ADNS error handling fix.
* dirmngr/dns-stuff.c (resolve_name_adns, get_dns_cert, get_dns_cname):
Use gpg_error and gpg_err_code_from_errno to compose the error value.

--
This fixes commits 6f1d8123d6.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 16:22:26 +09:00
Werner Koch a15ed5a1fd
gpg: Convey --quick option to dirmngr for --auto-key-retrieve.
* g10/call-dirmngr.c (gpg_dirmngr_ks_get): Add arg 'quick'.
(gpg_dirmngr_wkd_get): Ditto.
* g10/keyserver.c (keyserver_get): Add arg 'quick'.
(keyserver_get_chunk): Add arg 'quick'.
(keyserver_import_fprint): Ditto.  Change callers to pass 0 for it.
(keyserver_import_keyid): Ditto.
(keyserver_import_wkd): Ditto.
* g10/mainproc.c (check_sig_and_print): Call the 3 fucntions with
QUICK set.
--

Note that this option has not yet been implemented by dirmngr.
Dirmngr will simply ignore it for now.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-27 09:06:10 +02:00
NIIBE Yutaka 8b3d0d1a36 common: Fix gnupg_inotify_has_name, differently.
* common/sysutils.c (gnupg_inotify_has_name): Use void * to stop the
warning.

--
According to the man page of inotify(7), it is aligned by null bytes.
So, bc28f320fa is reverted.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 15:43:18 +09:00
NIIBE Yutaka 6f1d8123d6 dirmngr: More ADNS error fix.
* dirmngr/dns-stuff.c (get_dns_cert, getsrv, get_dns_cname): Fix return
value.

--
GnuPG-bug-id: 2745
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 15:04:34 +09:00
NIIBE Yutaka 8a9341b42c dirmngr: Fix error return for ADNS.
* dirmngr/dns-stuff.c (resolve_name_adns): Use RET for return value.

--
There are cases where libadns returns an error without setting the
variable ERRNO.

GnuPG-bug-id: 2745
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 14:49:17 +09:00
NIIBE Yutaka ca0ee4e381 g10: Fix ECDH, clarifying the format.
* g10/ecdh.c (pk_ecdh_encrypt_with_shared_point): Returns error when
it's short.  Clarify the format.  Handle other prefixes correctly.

--
With the scdaemon's change, there is no case NBYTES < SECRET_X_SIZE.
This fixes the break of ECDH with X25519.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 13:04:45 +09:00
NIIBE Yutaka 6bbd97d6c7 scd: Add 0x41 prefix for x-coordinate only result.
* scd/app-openpgp.c (do_decipher): When it's x-coordinate only, add the
prefix 0x41.

--
Card should return fixed size bytes, either in format of
(04 || X || Y) or (X, x-coordinate only).

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 13:04:29 +09:00
Arnaud Fontaine b648f28f9f g10: ECDH shared point format.
* g10/ecdh.c (pk_ecdh_encrypt_with_shared_point): Improve handling of
ECDH shared point format.

--
This handles the case where the result comes from scdaemon.

Signed-off-by: Arnaud Fontaine <arnaud.fontaine at ssi.gouv.fr>
2016-10-27 12:16:30 +09:00
Daniel Kahn Gillmor 75f8aaf5bc dirmngr: Implement --supervised command (for systemd, etc).
* dirmngr/dirmngr.c (main): Add new --supervised command, which is a
mode designed for running under a process supervision system like
systemd or runit.
* doc/dirmngr.texi: document --supervised option.

--

"dirmngr --supervised" is a way to invoke dirmngr such that a system
supervisor like systemd can provide socket-activated startup, log
management, and scheduled shutdown.

When running in this mode, dirmngr:

 * Does not open its own listening socket; rather, it expects to be
   given a listening socket on file descriptor 3.

 * Does not detach from the invoking process, staying in the
   foreground instead.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-27 10:46:53 +09:00
Daniel Kahn Gillmor 6316b28e89 agent,common: move get_socket_name() into common.
* agent/gpg-agent.c (get_socket_name): move to ...
* common/sysutils.c (gnupg_get_socket_name): ... here.

--
This allows us to use the same functionality in dirmngr as well.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-27 10:37:17 +09:00
Daniel Kahn Gillmor 6bb6ac56cc dirmngr: report actual socket name.
* dirmngr/dirmngr.[ch] (dirmngr_get_current_socket_name): new function
to report known socket name.
* dirmngr/server.c (cmd_getinfo): use dirmngr_get_current_socket_name
to report correct socket name.

--

This fixes the output of 'getinfo socket_name' when dirmngr is invoked
with --socket-name.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-27 10:30:55 +09:00
NIIBE Yutaka bc28f320fa common: Fix gnupg_inotify_has_name.
* common/sysutils.c (gnupg_inotify_has_name): Take care of the
alignment.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 10:16:48 +09:00
NIIBE Yutaka 96414baf36 dirmngr: Fix help string and argument.
* dirmngr/server.c (hlp_versioncheck): Add a newline.
(cmd_versioncheck): Fix argument.

--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-27 09:18:29 +09:00
Werner Koch d1ccab5176
dirmngr: Fix hang due to deferred thread initialization.
* dirmngr/dirmngr.c (main): Call ldap_wrapper_launch_thread after
thread_init.
--

Fixes-commit: eda17649f8
Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-26 10:25:14 +02:00
Werner Koch b77f95a4a6
agent: Avoid double error message.
* agent/gpg-agent.c (map_supervised_sockets): Shorten error message.
Remove unneeded diagnostic.
--

get_socket_name already prints error messages and thus there is not
need to print another one.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-26 09:10:52 +02:00
Werner Koch ece13f177d
common: Use GPG_ERR_INV_VALUE instead of GPG_ERR_EINVAL.
* common/sysutils.c (gnupg_inotify_watch_socket): Return
GPG_ERR_INV_VALUE for a missing socket name and set proper error
source.
--

By using a different value we can easier see whether the error is due
to a system call or from GnuPG code.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-26 09:02:10 +02:00
Werner Koch 21b318452a
tests: Improve portability of fake-pinentry.
* tests/openpgp/fake-pinentry.c: Make all functions static.
(get_passphrase): s/unlink/remove/ because that is standard C.
(spacep): Rename to whitespace and change all callers.
(main): Move macro out of if-then chain.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-26 08:34:18 +02:00
Daniel Kahn Gillmor 900c18f0b5 doc: Fix spelling of "internal".
--
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-26 14:37:14 +09:00
Daniel Kahn Gillmor 27f6d5b9f4 agent: --supervised mode improvements.
* agent/gpg-agent.c (map_supervised_socket): if the agent is running
  in --supervised mode and is not actually given LISTEN_FDNAMES
  directives, require at least fd 3 to be open for listening.
--
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-26 14:18:29 +09:00
Daniel Kahn Gillmor 3b5f5e0eb0 common: avoid segfault
* common/sysutils.c (gnupg_inotify_watch_socket): return EINVAL if
  socket_name is NULL, rather than segfaulting
--
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-26 14:16:06 +09:00
Justus Winter 852b8f0b89 agent,tests,w32: Fix relaying pinentry user data, fix fake-pinentry.
* agent/call-pinentry.c (start_pinentry): Also send the user data
using an Assuan 'OPTION' command.
* tests/openpgp/fake-pinentry.c (get_passphrase): Fix updating
passphrase file.
(spacep): Include newline characters.
(rstrip): New function.
(main): Handle Windows line endings.  Handle the userdata option, and
restart with the new options.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-25 17:07:08 +02:00
Justus Winter f88f11a256 tests: Do not autostart gpg-agents on teardown.
* tests/openpgp/defs.c (stop-agent): Use '--no-autostart' when calling
gpg-connect-agent.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-25 17:06:05 +02:00
Werner Koch b120f358c2
dirmngr: Allow command VERSIONCHECK to handle 3 part version numbers.
* dirmngr/server.c (parse_version_string): Add arg MICRO and set it.
(cmp_version): Extend to handle the MICRO part.
(confucius_mktmpdir): Rename to my_mktmpdir.
(my_mktmpdir): xstrconcat does not fail; use strconcat.
(fetch_into_tmpdir): Improve error checking.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-25 09:38:01 +02:00
Werner Koch 7983f87587
common: Use strconcat in gnupg_setenv.
* common/sysutils.c (gnupg_setenv): Replace malloc+stpcpy by
strconcat.  Indent cpp conditionals.
(gnupg_unsetenv): Indent cpp conditionals.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-25 08:59:44 +02:00
Werner Koch 9d6146d6f9
gpg: Replace two sprintf calls.
* g10/keygen.c (print_status_key_created): Use snprintf for now.
(ask_expire_interval): Replace xmalloc and sprintf by xasprintf.
--

Future updates: Replace code like

   r = xcalloc (1, sizeof *r + 20 );
   r->key = pKEYLENGTH;
   sprintf( r->u.value, "%u", info.key_attr[0].nbits);

by something like

   r = new_r_with_value ("%u", info.key_attr[0].nbits);
   r->key = pKEYLENGTH;

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-24 13:12:05 +02:00
Werner Koch 8c40b3b98d
agent: Minor cleanup for recent change in findkey.c
* agent/findkey.c (agent_write_private_key): Avoid label name error.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-24 13:01:06 +02:00
Werner Koch fdb653a33e
agent: Slightly change structure of cmd_readkey.
* agent/command.c (cmd_readkey): Avoid a leave label in the middle of
the code.  Remove the special return.
--

This helps to get better debug output.

The set_error macro which is used by parse_keygrip merely sets the
error code into the Assuan context.  It is thus no problem anymore to
call leave_cmd after having used set_error.  This might havve been
diffferent in the past.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-24 12:59:57 +02:00
Kai Michaelis 5e7dfd979d dirmngr: Fix segfault in VERSIONCHECK.
* dirmngr/server.c (cmd_versioncheck): The VERSIONCHECK command crashes
when called without program version.
2016-10-24 12:33:22 +02:00
NIIBE Yutaka b1828c17fc scd: Use canonical curve name of libgcrypt.
* scd/app-openpgp.c (send_key_attr): Use curve instead of OID.
(ecdh_params): New.
(ecc_read_pubkey): Use ecdh_params.  Use curve name.
(ecc_writekey): Likewise.
(ecc_curve): Rename from ecc_oid.
(parse_algorithm_attribute): Use ecc_curve.
* g10/call-agent.c (learn_status_cb): Use openpgp_is_curve_supported to
intern the curve name string.
* g10/card-util.c (card_status): Conver curve name to alias for print.
--
Now, sdcaemon answer for KEY-ATTR is in the canonical curve name
instead of the alias.  Since it is used of key generation for
card encryption key with backup, it should be canonical name.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-24 11:22:44 +09:00
NIIBE Yutaka 945e7ab0dd common: Fix openpgp_is_curve_supported.
* common/openpgp-oid.c (openpgp_is_curve_supported): Support both of
canonical name of the curve and alias.

--
Only alias (the name for print) was allowed before this change.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-24 11:20:14 +09:00
NIIBE Yutaka acef095164 g10: Fix card keygen for decryption.
* g10/keygen.c (do_generate_keypair): Fix arguments.

--

Reported-by: Grumpy
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-24 07:52:40 +09:00
NIIBE Yutaka 987bbb2276 g10: More card key generation change.
* g10/keygen.c (gen_card_key): Add back ALGO as the second argument.
Don't get ALGO by KEY-ATTR by this function.  It's caller to provide
ALGO.  Don't do that by both of caller and callee.
(generate_keypair): Only put paramerters needed.  Use parameters
for ALGO to call gen_card_key.
(generate_card_subkeypair): Get ALGO and call gen_card_key with it.

--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-22 08:45:35 +09:00
Andre Heinecke f7e50634be g10: Write first keybox record in binary mode
* g10/keydb.c (maybe_create_keyring_or_box): Open in binary mode.

--
This fixes keybox corruption on windows.

Signed-off-by: Andre Heinecke <aheinecke@intevation.de>
2016-10-21 15:02:19 +02:00
NIIBE Yutaka d2653b1a6d g10,scd: Fix ECC keygen.
* g10/keygen.c (generate_keypair): For card key generation, fill
parameters by KEY-ATTR.

* scd/app-openpgp.c (ecc_read_pubkey): OID should be freed at last,
after its reference by OIDBUF is finished.
(ecc_writekey): Likewise.
--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 21:37:04 +09:00
NIIBE Yutaka 693e657ff0 scd: Fix segfault changing key attr.
* asc/app-openpgp.c (change_keyattr_from_string): Release after
allocated.
--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 16:27:46 +09:00
NIIBE Yutaka dafce6f698 g10: Don't ask keysize for for non-RSA card.
* g10/card-util.c (card_status): Bug fix for keyno.
(ask_card_rsa_keysize, do_change_rsa_keysize): Rename.
(generate_card_keys): Only ask keysize when RSA.
(card_generate_subkey): Likewise.

--

Co-authored-by: Arnaud Fontaine <arnaud.fontaine@ssi.gouv.fr>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 14:15:05 +09:00
NIIBE Yutaka 161cb22f13 g10: Support ECC for gen_card_key.
* g10/keygen.c (gen_card_key): Remove the first argument of ALGO.
(do_generate_keypair, generate_card_subkeypair): Follow the change.

--
ALGO is determined by the key attribute of the card.

Co-authored-by: Arnaud Fontaine <arnaud.fontaine@ssi.gouv.fr>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 13:59:09 +09:00
NIIBE Yutaka 6e85ac77af Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.

--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 12:04:46 +09:00
NIIBE Yutaka 1ffd475f99 agent: Fix saving with FORCE=1.
* agent/findkey.c (agent_write_private_key): Recover from an error of
GPG_ERR_ENOENT when FORCE=1 and it is opened with "rb+".

--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 10:57:29 +09:00
Justus Winter 71158d8d5f tests: Simplify test.
* tests/openpgp/quick-key-manipulation.scm: Avoid creating a temporary
home directory, just make the uids unique.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:24 +02:00
Justus Winter ca9597f080 tests: Flush stdout in the fake pinentry.
* tests/openpgp/fake-pinentry.c (reply): Flush stdout.

Fixes-commit: 94504b3d5a
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:24 +02:00
Justus Winter 8c7c4faf3d common,w32: Fix setting environment variables on Windows.
* common/sysutils.c (gnupg_setenv): Also update the environment block
maintained by the C runtime.
(gnupg_unsetenv): Likewise.
* tests/gpgscm/ffi.c (do_setenv): Fix error handling.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:24 +02:00
Justus Winter bf37916a23 tests,w32: Cope with Windows line endings.
* tests/openpgp/issue2015.scm: Rstrip line before comparison.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:23 +02:00
Justus Winter 2d794779e0 tests: Create and remove socket directories.
* tests/openpgp/defs.scm (start-agent): Move function here and create
the socket directory prior to starting the agent.
(stop-agent): Move function here and remove the socket directory.
* tests/openpgp/finish.scm: Adapt.
* tests/openpgp/setup.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:23 +02:00
NIIBE Yutaka 9a34e2142b agent, g10: Fix keygen.
* agent/command.c (cmd_readkey): Get length after card_readkey.
* g10/keygen.c (gen_card_key): Fix off-by-one error.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-20 20:01:46 +09:00
NIIBE Yutaka b680f79cc1 scd: GENKEY updates the public key in APP.
* scd/app-openpgp.c (rsa_read_pubkey, ecc_read_pubkey): New.
(read_public_key): New.
(get_public_key, do_genkey): Use read_public_key.

--

With this change, since GENKEY updates the public key (pk[keyno].key) in
APP, READKEY will be possible after the command even for the old
card (version <= 0x0100).

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-20 16:25:47 +09:00