gnupg.git
21 hours agoagent: Terminate pinentry process gracefully, by watching socket. master
NIIBE Yutaka [Tue, 19 Feb 2019 05:36:50 +0000 (14:36 +0900)]
agent: Terminate pinentry process gracefully, by watching socket.

* agent/call-pinentry.c (watch_sock): New.
(do_getpin): Spawn the watching thread.

--

While we don't have npth_cancel (and it's difficult to implement it
correctly), this is a kind of best compromise allowing a thread's
polling when pinentry is active.

GnuPG-bug-id: 2011
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
21 hours agoagent: Minor change for pinentry status handling.
NIIBE Yutaka [Tue, 19 Feb 2019 04:12:07 +0000 (13:12 +0900)]
agent: Minor change for pinentry status handling.

* agent/call-pinentry.c (struct entry_parm_s): Add status.
(do_getpin): Use param->status.
(agent_askpin): Copy param->status. to pininfo.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
24 hours agoagent: Factor out the getpin interaction.
NIIBE Yutaka [Tue, 19 Feb 2019 02:55:55 +0000 (11:55 +0900)]
agent: Factor out the getpin interaction.

* agent/call-pinentry.c (do_getpin): New.
(agent_askpin, agent_get_passphrase): Use do_getpin.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 days agosm: Support generation of card-based ed25519 CSR.
Damien Goutte-Gattat via Gnupg-devel [Sun, 17 Feb 2019 17:40:51 +0000 (17:40 +0000)]
sm: Support generation of card-based ed25519 CSR.

* sm/call-agent.c (gpgsm_scd_pksign): Allow SHA512. Create proper
S-expression for EdDSA signature.
* sm/certreqgen.c (create_request): Force use of SHA512 when
using a ed25519 key.
* sm/misc.c (transform_sigval): Insert OID for ed25519.

--

GnuPG-bug-id: 4013
Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
5 days agosm: Support generation of card-based ECDSA CSR.
Damien Goutte-Gattat via Gnupg-devel [Fri, 16 Nov 2018 01:27:37 +0000 (01:27 +0000)]
sm: Support generation of card-based ECDSA CSR.

* sm/call-agent.c (gpgsm_scd_pksign): Identify type of signing key
and format resulting S-expression accordingly.
* sm/misc.c (transform_sigval): Support ECDSA signatures.
--

Current GpgSM implementation assumes card-based keys are RSA keys.
This patch introduces support for ECDSA keys.

By itself this patch is not sufficient, we also need support
from libksba.

GnuPG-bug-id: 4092
Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
5 days agopo: Correct a simple typo in the Norwegian translation
Ingvar Hagelund [Thu, 14 Feb 2019 14:44:38 +0000 (09:44 -0500)]
po: Correct a simple typo in the Norwegian translation

Signed-off-by: Ingvar Hagelund <ingvar@redpill-linpro.com>
6 days agocard: New command "yubikey".
Werner Koch [Wed, 13 Feb 2019 08:46:36 +0000 (09:46 +0100)]
card: New command "yubikey".

* tools/card-tool-yubikey.c: New.
* tools/Makefile.am (gpg_card_tool_SOURCES): Add it.
* tools/card-call-scd.c (scd_apdu): Allow returning data.
* tools/card-tool-misc.c (send_apdu): New.  Move from gpg-card-tool.c
and let it return data.  Change all callers.

* tools/gpg-card-tool.c (cmd_writecert): Prepend the certref with the
current application type.
(cmd_yubikey): New.
--

This command allows listing of active applications and to enable or
disable selected applications.  This is in particular useful to
disable the OpenPGP application so that the PIV support can easily be
tested.

Signed-off-by: Werner Koch <wk@gnupg.org>
8 days agoscd: Implement decryption for PIV cards.
Werner Koch [Mon, 11 Feb 2019 14:32:54 +0000 (15:32 +0100)]
scd: Implement decryption for PIV cards.

* scd/app-piv.c (do_decipher): New.
--

Note that ECDH decryption has not been tested due to the lack of ECC
support in gpgsm.

Signed-off-by: Werner Koch <wk@gnupg.org>
8 days agoscd: For PIV cards used NO_AUTH instead of BAD_PIN.
Werner Koch [Mon, 11 Feb 2019 08:07:54 +0000 (09:07 +0100)]
scd: For PIV cards used NO_AUTH instead of BAD_PIN.

* common/util.h (GPG_ERR_NO_AUTH, GPG_ERR_BAD_AUTH): Add replacement
codes for gpgrt < 1.36.
* scd/app-piv.c (auth_adm_key):
(do_genkey, do_writecert): Use better error codes.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agoscd: Implement RSA signing for PIV cards.
Werner Koch [Fri, 8 Feb 2019 15:46:52 +0000 (16:46 +0100)]
scd: Implement RSA signing for PIV cards.

* scd/app-piv.c (concat_tlv_list): New.
(get_key_algorithm_by_dobj): Rename args for clarity.
(do_auth): factor all code out to ...
(do_sign): new.  Implement RSA signing.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agosm: In --gen-key with "key from card" show also the algorithm.
Werner Koch [Fri, 8 Feb 2019 11:35:26 +0000 (12:35 +0100)]
sm: In --gen-key with "key from card" show also the algorithm.

* sm/certreqgen-ui.c (gpgsm_gencertreq_tty): Get and show algo.
--

This extends the prompt to show something like

  Serial number of the card: FF020001008A77F6
  Available keys:
     (1) 4130F84FA3704F4645924AEC3FFA48AD26D33656 PIV.9A nistp384
     (2) AB2988FB8C227BCD5175BF92F66AA3A95AE83214 PIV.9E rsa2048
     (3) DB7DDAEAA88534BA45CCD7A9B761425103EA2090 PIV.9C rsa2048
     (4) BABB48C3D80ACCF9839F101DF2910966C8B988DF PIV.9D nistp256
  Your selection? 1

Having the algorithm here is helpful in particular because right now
we support only RSA with X.509.  Take care: PIV card based certificate
creation does not yet work.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agocommon: Provide function to get public key algo names in our format.
Werner Koch [Fri, 8 Feb 2019 11:10:45 +0000 (12:10 +0100)]
common: Provide function to get public key algo names in our format.

* tools/card-tool-misc.c (pubkey_algo_string): Move to  ...
* common/sexputil.c (pubkey_algo_string): here.
--

The new gpg format for public key algorithms is useful at other places
as well.  Thus we make this new function available.  Note that the
code we use in gpg is not based on s-expressions and thus a new
function was required.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agocard: Make "generate" work for PIV cards.
Werner Koch [Fri, 8 Feb 2019 10:58:27 +0000 (11:58 +0100)]
card: Make "generate" work for PIV cards.

* tools/card-call-scd.c (scd_genkey_cb): Make createtime optional.
(scd_genkey_cb):  Ditto.  Add arg algo.
* tools/gpg-card-tool.c (cmd_generate): Add options and factor card
specific code out to ...
(generate_openpgp, generate_generic): new functions.
--

This patch keeps the interactive OpenPGP mode but adds a pure command
line mode for other cards; in particular PIV cards.  What we still
need to do is:
 a) Add an interactive mode for PIV cards
 b) Add a command line mode for OpenPGP cards.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agoscd: Allow generating ECC curves on PIV cards.
Werner Koch [Fri, 8 Feb 2019 10:53:34 +0000 (11:53 +0100)]
scd: Allow generating ECC curves on PIV cards.

* scd/app-piv.c (genkey_parse_ecc): New.
(get_keygrip_by_tag): Call that one.
(do_readkey): Call that one.
* scd/command.c (cmd_genkey): Add option --algo.

Signed-off-by: Werner Koch <wk@gnupg.org>
11 days agocommon: New functions get_option_value and ascii_strupr.
Werner Koch [Fri, 8 Feb 2019 08:32:55 +0000 (09:32 +0100)]
common: New functions get_option_value and ascii_strupr.

* common/server-help.c (get_option_value): New.
* common/stringhelp.c (ascii_strupr): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 days agocard: Print the used algorithm of all keys.
Werner Koch [Thu, 7 Feb 2019 19:28:43 +0000 (20:28 +0100)]
card: Print the used algorithm of all keys.

* tools/card-call-scd.c (scd_readkey): New.
* tools/card-tool-misc.c (pubkey_algo_string): New.
* tools/gpg-card-tool.c (list_one_kinfo): Print the algo.
--

It is convenient to see the actual algorithm of keys even if no
certificate has yet been created.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 days agocard: Fix a NULL-ptr deref in key listings.
Werner Koch [Thu, 7 Feb 2019 15:28:03 +0000 (16:28 +0100)]
card: Fix a NULL-ptr deref in key listings.

* tools/card-tool-keys.c (get_matching_keys): Fix segv.
* tools/gpg-card-tool.c (main): Init info.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 days agoscd: Store a new PIV public key in the certificate DO.
Werner Koch [Thu, 7 Feb 2019 15:13:21 +0000 (16:13 +0100)]
scd: Store a new PIV public key in the certificate DO.

* scd/app-piv.c (struct genkey_result_s): Remove type and all users.
(send_keypair_and_cert_info): Print certinfo only if we got a cert..
(readcert_by_tag): Add arg r_mechanism and implement reading of public
keys.
(get_keygrip_by_tag): Use a public key to compute the keygrip.
(do_readcert): Make sure to only return a certificate.
(do_readkey): Read public key from the DO if a certificate is missing.
(get_key_algorithm_by_dobj): Get the algorithm also from a public key.
(does_key_exist): String changes.
(do_genkey): Remove result caching and store public key in the DO.
--

This removes the result cache and instead stores the public key in the
certificate object.  This allows to properly list public keys at any
time after generating a key and before a new certificate is stored
there.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 days agocard: Support reading and writing PIV certificates
Werner Koch [Thu, 7 Feb 2019 10:05:22 +0000 (11:05 +0100)]
card: Support reading and writing PIV certificates

* scd/app-piv.c (add_tlv): New.
(put_data): New.
(do_writecert): New.
(do_setattr): Remove usused special mode 0.
* tools/gpg-card-tool.c (cmd_writecert): Allow other cards than
OPENPGP.
(cmd_readcert): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
12 days agocard: Add readline completion for help arguments
Werner Koch [Thu, 7 Feb 2019 07:16:02 +0000 (08:16 +0100)]
card: Add readline completion for help arguments

--

13 days agoscd: Add genkey command to app-piv (rsa-only)
Werner Koch [Wed, 6 Feb 2019 19:47:07 +0000 (20:47 +0100)]
scd: Add genkey command to app-piv (rsa-only)

* scd/app-piv.c (struct genkey_result_s): new.
(struct app_local_s): add member genkey_results.
(do_deinit): Free that one.
(flush_cached_data): Extend to delete all items.
(keyref_from_dobj): New.
(do_readkey): New.
(do_auth): Use keyref_from_dobj.
(does_key_exist): New.
(genkey_parse_rsa): New.
(do_genkey): New.
--

We need to extend the GENKEY in command.c to support other algos.

Signed-off-by: Werner Koch <wk@gnupg.org>
13 days agoscd: Make app_genkey and supporting ISO function more flexible.
Werner Koch [Wed, 6 Feb 2019 13:07:42 +0000 (14:07 +0100)]
scd: Make app_genkey and supporting ISO function more flexible.

* scd/app.c (app_genkey): Add arg keytype.
* scd/app-common.h (struct app_ctx_s): Fitto for the genkey member.
* scd/command.c (cmd_genkey): Adjust for change.
* scd/iso7816.c (do_generate_keypair): Replace arg read_only by new
args p1 and p2.
(iso7816_read_public_key): Adjust for this.
(iso7816_generate_keypair): Add new args p1 and p2.
* scd/app-openpgp.c (do_genkey): Adjust for changes.
--

The OpenPGP card creates keys according to parameters read from a data
object.  Other cards we are about to implement require a direct
specification of the requested keytype.  This patch implements the
required changes.

Signed-off-by: Werner Koch <wk@gnupg.org>
13 days agoscd: Fix parameter name of app_change_key.
Werner Koch [Wed, 6 Feb 2019 11:24:30 +0000 (12:24 +0100)]
scd: Fix parameter name of app_change_key.

* scd/app-common.h (APP_GENKEY_FLAG_FORCE): New.
* scd/app.c (app_change_pin): Rename arg reset_mode to flags and
change from int to unsigned int.
--

This is basically a documentation fix.

Signed-off-by: Werner Koch <wk@gnupg.org>
13 days agodoc: Add basic man page for the gpg-card-tool.
Werner Koch [Wed, 6 Feb 2019 09:37:03 +0000 (10:37 +0100)]
doc: Add basic man page for the gpg-card-tool.

--

13 days agoscd: Implement PIN changing and unblocking for PIV cards.
Werner Koch [Wed, 6 Feb 2019 08:45:54 +0000 (09:45 +0100)]
scd: Implement PIN changing and unblocking for PIV cards.

* scd/app-piv.c: Some refactoring
(do_change_chv): Implement.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agoscd: Allow standard keyref scheme for app-openpgp.
Werner Koch [Tue, 5 Feb 2019 13:48:49 +0000 (14:48 +0100)]
scd: Allow standard keyref scheme for app-openpgp.

* scd/app-openpgp.c (do_change_pin): Allow prefixing the CHVNO with
"OPENPGP."
* tools/card-call-scd.c (scd_change_pin): Change API to use strings.
* tools/gpg-card-tool.c (cmd_passwd): Adjust for change.
(cmd_unblock): Ditto.
--

The generic keyref allows for better error detection in case a keyref
is send to a wrong card.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocard: Implement non-interactive mode.
Werner Koch [Thu, 31 Jan 2019 17:57:16 +0000 (18:57 +0100)]
card: Implement non-interactive mode.

* tools/card-tool.h (opt): Add field 'initialized'.
* tools/card-call-scd.c (scd_learn): Set it.
* tools/gpg-card-tool.c (main): Reworked.
(dispatch_command): New.
--

This work is not yet finished because most commands need some tweaks
for non-interactive work.  What you already can do are things like:

 $ gpg-card-tool list -- 'auth <oldkey' \
   -- auth --setkey --raw 123456781234567812345678 -- help auth

Which will list the current card, authenticate using a hex encoded key
from the file "oldkey", set the new admin key to "123...78", and print
help for the auth command.  Note that the -- acts as a delimiter
between commands.  To use a double dash as argument to a command the
entire command must be quoted.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocard: New command 'authenticate'.
Werner Koch [Thu, 31 Jan 2019 15:06:47 +0000 (16:06 +0100)]
card: New command 'authenticate'.

* tools/card-tool-misc.c (hex_to_buffer): New.
* tools/gpg-card-tool.c (get_data_from_file): Change to allow returning
a string.
(cmd_authenticate): New.
(cmds): Add command "authenticate".

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agoscd: Add DES authentication for PIV card.
Werner Koch [Thu, 31 Jan 2019 13:26:17 +0000 (14:26 +0100)]
scd: Add DES authentication for PIV card.

* scd/app-piv.c (flush_cached_data): New.
(auth_adm_key): New.
(set_adm_key): New.
(do_setattr): New.
* scd/command.c (MAXLEN_SETATTRDATA): New.
(cmd_setattr): Add an inquire option.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocard: Cache the results from gpg and gpgsm.
Werner Koch [Wed, 30 Jan 2019 16:48:41 +0000 (17:48 +0100)]
card: Cache the results from gpg and gpgsm.

* tools/card-tool-keys.c (keyblock_cache): New var.
(release_keyblock): Factor code out to a new do_release_keyblock.  Add
a cache.
(flush_keyblock_cache): New.
(get_matching_keys): Use the cache.
* tools/gpg-card-tool.c (cmds): Add command "reset".
(interactive_loop): Implement reset.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocard: Print matching OpenPGP and X.509 data.
Werner Koch [Wed, 30 Jan 2019 14:01:34 +0000 (15:01 +0100)]
card: Print matching OpenPGP and X.509 data.

* tools/card-tool-keys.c: New.
* tools/Makefile.am (gpg_card_tool_SOURCES): Add file.
* tools/card-tool.h (struct pubkey_s, pubkey_t): New.
(struct userid_s, userid_t): New.
(struct keyblock_s, keyblock_t): New.
* common/util.h (GNUPG_PROTOCOL_): New const
* tools/gpg-card-tool.c (aTest): Add temporary command.
(list_one_kinfo): Print info from gpg and gpgsm.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agogpg: Emit an ERROR status if no key was found with --list-keys.
Werner Koch [Wed, 30 Jan 2019 13:40:26 +0000 (14:40 +0100)]
gpg: Emit an ERROR status if no key was found with --list-keys.

* g10/keylist.c (list_one): Emit status line.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocommon: Add kludge to allow silencing gnupg_exec_tool_stream.
Werner Koch [Wed, 30 Jan 2019 13:38:37 +0000 (14:38 +0100)]
common: Add kludge to allow silencing gnupg_exec_tool_stream.

* common/exectool.c (read_and_log_buffer_t): Take care of a --quiet
argument.
(gnupg_exec_tool_stream): Ditto.
--

If we pass --quiet to a program it should really shutup and the parent
should be quite as well.

2 weeks agogpg: Allow generating Ed25519 key from an existing key.
Werner Koch [Wed, 30 Jan 2019 10:28:14 +0000 (11:28 +0100)]
gpg: Allow generating Ed25519 key from an existing key.

* g10/misc.c (map_pk_gcry_to_openpgp): Add EdDSA mapping.
--

Due to this missing mapping a "gpg --export --full-gen-key" with
selection "13 - Existing key" did not worked for an ed25519 key.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 weeks agocommon: New function decode_c_string.
Werner Koch [Wed, 30 Jan 2019 07:28:56 +0000 (08:28 +0100)]
common: New function decode_c_string.

* common/miscellaneous.c (decode_c_string): New.
--

This is basically a copy from the code we use in gpgme and gpa.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agodoc: Fix typo
Werner Koch [Tue, 29 Jan 2019 21:15:49 +0000 (22:15 +0100)]
doc: Fix typo

--

3 weeks agogpg: Implement searching keys via keygrip.
Werner Koch [Tue, 29 Jan 2019 18:52:08 +0000 (19:52 +0100)]
gpg: Implement searching keys via keygrip.

* kbx/keybox-defs.h (struct _keybox_openpgp_key_info): Add field grip.
* kbx/keybox-openpgp.c (struct keyparm_s): New.
(keygrip_from_keyparm): New.
(parse_key): Compute keygrip.
* kbx/keybox-search.c (blob_openpgp_has_grip): New.
(has_keygrip): Call it.
--

This has been marked for too long as not yet working.  However, it is
a pretty useful feature and will come pretty handy when looking for
all keys matching one keygrip.

Can be optimized a lot by storing the keygrip in the meta data.  This
will be done along with the upgrade of KBX for v5 fingerprints.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agocommon: Provide some convenient OpenPGP related constants.
Werner Koch [Tue, 29 Jan 2019 17:20:34 +0000 (18:20 +0100)]
common: Provide some convenient OpenPGP related constants.

* common/openpgpdefs.h (OPENPGP_MAX_NPKEY): New.
(OPENPGP_MAX_NSKEY): New.
(OPENPGP_MAX_NSIG): New.
(OPENPGP_MAX_NENC): New.
* g10/packet.h: Define PUBKEY_MAX using the new consts.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agocommon: New helper functions for OpenPGP curve OIDs.
Werner Koch [Tue, 29 Jan 2019 17:19:05 +0000 (18:19 +0100)]
common: New helper functions for OpenPGP curve OIDs.

* common/openpgp-oid.c (openpgp_oidbuf_to_str): Factor most code out
to ...
(openpgp_oidbuf_to_str): new.
(openpgp_oidbuf_is_ed25519): New.
(openpgp_oidbuf_is_cv25519): New.
--

At some places it is more convenient (and faster) to directly work on
buffers and avoid the way via opaque MPIs.  These 3 new functions
allow for that.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agocard: Support factory reset for Yubikey PIV application.
Werner Koch [Tue, 29 Jan 2019 12:28:10 +0000 (13:28 +0100)]
card: Support factory reset for Yubikey PIV application.

* scd/app-common.h (struct app_ctx_s): Add field cardtype.
* scd/app.c (app_new_register): Set cardtype for yubikey.
(app_getattr): Add CARDTYPE.
(app_write_learn_status): Emit new attribute.
* scd/app-piv.c (do_getattr): Add CHV-USAGE.
(do_learn_status): Emit it.
* tools/card-tool.h (struct card_info_s): Add field cardtype.
* tools/card-call-scd.c (learn_status_cb): Parse "CARDTYPE".

* tools/gpg-card-tool.c (list_piv): Print PIN usage policy.
(list_card): Print card type.
(cmd_factoryreset): Implement for Yubikey with PIV.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agocard: Print keyinfo for PIV cards.
Werner Koch [Tue, 29 Jan 2019 08:30:15 +0000 (09:30 +0100)]
card: Print keyinfo for PIV cards.

* scd/app-piv.c (do_learn_status): Print CHV-STATUS.
* tools/card-tool.h (struct card_info_s): Rename chvretry to chvinfo.
* tools/card-call-scd.c (learn_status_cb): Depend CHV-STATUS on app
type.
* tools/gpg-card-tool.c (list_piv): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agocard: Make printing of key information more flexible.
Werner Koch [Tue, 29 Jan 2019 07:48:53 +0000 (08:48 +0100)]
card: Make printing of key information more flexible.

* tools/card-tool-misc.c: New.
* tools/card-tool.h: Rewored data structures for key infos.
* tools/gpg-card-tool.c: Ditto.
* tools/card-call-scd.c: Ditto.
--

Note that this also changes the way the key information is printed.
Formerly we printed it like:

  Signature key ....: <openpgp-fingerprint>
        created ....: <timestamp>
        keygrip ... : <keygrip>

now we do:

  Signature key ....: <keygrip>
        fingerprint : <openpgp-fingerprint>
        created ....: <timestamp>

This is because a keygrip is always available but a fingerprint and
the creation date are properties of an OpenPGP card.  A standard way
of listing keys is better than one depending on the type of card.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agoagent: Clear bogus pinentry cache, when it causes an error.
NIIBE Yutaka [Mon, 28 Jan 2019 03:58:13 +0000 (12:58 +0900)]
agent: Clear bogus pinentry cache, when it causes an error.

* agent/agent.h (PINENTRY_STATUS_*): Expose to public.
(struct pin_entry_info_s): Add status.
* agent/call-pinentry.c (agent_askpin): Clearing the ->status
before the loop, let the assuan_transact set ->status.  When
failure with PINENTRY_STATUS_PASSWORD_FROM_CACHE, it returns
soon.
* agent/findkey.c (unprotect): Clear the pinentry cache,
when it causes an error.

--

GnuPG-bug-id: 4348
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
3 weeks agocard: Implement the bulk of OpenPGP stuff into gpg-card-tool.
Werner Koch [Sun, 27 Jan 2019 19:12:00 +0000 (20:12 +0100)]
card: Implement the bulk of OpenPGP stuff into gpg-card-tool.

* tools/card-call-scd.c: New.
* tools/card-tool.h: new.
* tools/gpg-card-tool.c: Largely extended.
--

gpg-card-tool will eventually replace the --card-edit command of gpg
because it makes more sense to have a multi-protocol aware tool and
not just one for OpenPGP cards.  Most OpenPGP card things works now
but a few, those which require close interaction with gpg, still need
to be implemented.  And of course the whole planned non-interactive
stuff needs to be written.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agogpg: Fix just changed agent_get_s2k_count.
Werner Koch [Sat, 26 Jan 2019 22:17:54 +0000 (23:17 +0100)]
gpg: Fix just changed agent_get_s2k_count.

* g10/call-agent.c (agent_get_s2k_count): Actually return the count.
--

The previous push was definitely a bit to hasty.
Fixes-Commit: ec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agogpg: Move S2K encoding function to a shared file.
Werner Koch [Sat, 26 Jan 2019 22:10:38 +0000 (23:10 +0100)]
gpg: Move S2K encoding function to a shared file.

* g10/passphrase.c (encode_s2k_iterations): Move function to ...
* common/openpgp-s2k.c: new file.  Remove default intialization code.
* common/openpgpdefs.h (S2K_DECODE_COUNT): New to keep only one copy.
* g10/call-agent.c (agent_get_s2k_count): Change to return the count
and print an error.
* agent/protect.c: Include openpgpdefs.h
* g10/card-util.c (gen_kdf_data): Adjust for changes
* g10/gpgcompose.c: Include call-agent.h.
(sk_esk): Adjust for changes.
* g10/passphrase (passphrase_to_dek): Adjust for changes.
* g10/main.h (S2K_DECODE_COUNT): Remove macro.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agoscd: Improve app selection for app "undefined".
Werner Koch [Fri, 25 Jan 2019 18:12:32 +0000 (19:12 +0100)]
scd: Improve app selection for app "undefined".

* scd/app.c (app_new_register): Don't bail out early in undefined
mode.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agoscd: Fix flushing of CA-FPR data objects
Werner Koch [Fri, 25 Jan 2019 08:37:19 +0000 (09:37 +0100)]
scd: Fix flushing of CA-FPR data objects

* scd/app-openpgp.c (do_setattr): Add new table item to flush a
different tag.

--

For whatever reasons the OpenPGP card reads the 3 CA fingerprints from
one object but sets them individually using 3 different tags.  The
cache flushing was not prepared for this and so a changed CA
fingerprint showed only up after a card reset.  This patch fixes it.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agoagent: Support --mode=ssh option for CLEAR_PASSPHRASE.
NIIBE Yutaka [Fri, 25 Jan 2019 03:08:09 +0000 (12:08 +0900)]
agent: Support --mode=ssh option for CLEAR_PASSPHRASE.

* agent/command.c (cmd_clear_passphrase): Add support for SSH.

--

GnuPG-bug-id: 4340
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
3 weeks agodirmngr: Fix initialization of assuan's nPth hook.
NIIBE Yutaka [Fri, 25 Jan 2019 01:15:39 +0000 (10:15 +0900)]
dirmngr: Fix initialization of assuan's nPth hook.

* dirmngr/dirmngr.c (main): Move assuan_set_system_hooks to...
(thread_init): ... here.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
3 weeks agocommon: Extend function percent_data_escape.
Werner Koch [Thu, 24 Jan 2019 09:02:52 +0000 (10:02 +0100)]
common: Extend function percent_data_escape.

* common/percent.c (percent_data_escape): Add new args prefix and
plus_escape.
* agent/command.c (cmd_put_secret): Adjust for changed function

* common/t-percent.c (test_percent_data_escape): Extend test for the
prefix.
(test_percent_data_escape_plus): new test for the plus escaping.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 weeks agoscd: Support PASSWD --clear for OpenPGP card.
NIIBE Yutaka [Wed, 23 Jan 2019 03:01:51 +0000 (12:01 +0900)]
scd: Support PASSWD --clear for OpenPGP card.

* scd/app-openpgp.c (do_change_pin): Implement handling
APP_CHANGE_FLAG_CLEAR.

--

It is specified in the specification version 3.1 or later.  Some
version 2 cards (including Gnuk) support this feature.  Any version 1
card has no support for this feature.

For CHVNO = 1, it clears for both of 81 and 82; That is, user's key
usages for signing and others (decryption and auth).
For CHVNO = 3, it clears for 83, admin key.

For CHVNO = 2, it clears 82; That is, user's key usages
others (decryption and auth).

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
4 weeks agogpg: Stop early when trying to create a primary Elgamal key.
Werner Koch [Tue, 22 Jan 2019 09:06:15 +0000 (10:06 +0100)]
gpg: Stop early when trying to create a primary Elgamal key.

* g10/misc.c (openpgp_pk_test_algo2): Add extra check.
--

The problem is that --key-gen --batch with a parameter file didn't
detect that Elgamal is not capable of signing and so an error was only
triggered at the time the self-signature was created.  See the code
comment for details.

GnuPG-bug-id: 4329
Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agocard-tool: Add skeleton for new tool
Werner Koch [Tue, 22 Jan 2019 08:07:24 +0000 (09:07 +0100)]
card-tool: Add skeleton for new tool

* tools/gpg-card-tool.c: New.
* tools/gpg-card-tool-w32info.rc: New.
* tools/Makefile.am: Add new tool.
--

To support more cards than the OpenPGP card it is useful to have a
separate tool.  It will have have the "gpg --card-edit" style
interactive interface as well as direct command line options for all
commands.  In a first step the OpenPGP card will be supported, to
allow its use as an alternative to the gpg command, and the
forthcoming PIV card support.

The tool can be though as a direct interface to scdaemon.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agocommon: Add generic status print function.
Werner Koch [Tue, 22 Jan 2019 08:02:17 +0000 (09:02 +0100)]
common: Add generic status print function.

* common/status.c (gnupg_set_status_fd): New.
(gnupg_status_printf): New.
* po/Makevars (XGETTEXT_OPTIONS): Add gnupg-status_printf.
--

Some of the extra tools take a --status-fd option to print certain
status messages.  A generic printf style print function thus makes
sense.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agoscd: Support CHV-STATUS and CHECKPIN for PIV.
Werner Koch [Mon, 21 Jan 2019 14:01:45 +0000 (15:01 +0100)]
scd: Support CHV-STATUS and CHECKPIN for PIV.

* scd/app-piv.c (parse_pin_keyref): New.
(get_chv_status): New.
(do_getattr): Add name CHV-STATUS.
(verify_pin): Add arg keyref to support other PINs.
(do_change_pin): New.  Right now limited to --clear.
(do_check_pin): New.
(app_select_piv): Register new commands.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agoscd: Add option --clear to PASSWD.
Werner Koch [Mon, 21 Jan 2019 13:06:51 +0000 (14:06 +0100)]
scd: Add option --clear to PASSWD.

* scd/command.c (cmd_passwd): Add option --clear.
(send_status_printf): New.
* scd/app-common.h (APP_CHANGE_FLAG_CLEAR): New.
* scd/app-nks.c (do_change_pin): Return an error if that option is
used.
* scd/app-openpgp.c (do_change_pin): Ditto.
--

Card application may support this option to clear the PIN verification
status of a specific PIN.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agoscd: Add very basic support for PIV cards.
Werner Koch [Sun, 20 Jan 2019 10:45:57 +0000 (11:45 +0100)]
scd: Add very basic support for PIV cards.

* scd/app-piv.c: New.
* scd/Makefile.am (card_apps): Add app-piv.c
* scd/app.c (app_new_register): Try to get a Yubikey serial number.
Detect the PIV application.
(get_supported_applications): Add "piv".
--

Right now this allows the use of the authentication key (9A) for SSH
authentication.  More support will follow soon.

Tested with Yubikey-5.

4 weeks agoscd: One new and one improved 7816 function.
Werner Koch [Sun, 20 Jan 2019 10:41:23 +0000 (11:41 +0100)]
scd: One new and one improved 7816 function.

* scd/apdu.c (apdu_send_direct): New arg R_SW.
* scd/command.c (cmd_apdu): Ditto.
* scd/iso7816.c (iso7816_apdu_direct): New arg R_SW.
(iso7816_general_authenticate): New.
* scd/app-nks.c (get_chv_status, get_nks_version): Pass NULL for new
arg.
--

iso7816_general_authenticate will be used for the PIV card support.
The new arg to iso7816_apdu_direct and apdu_send_direct allows to get
the raw status word back without the need to handle an output buffer.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 weeks agossh: Simplify the curve name lookup.
Werner Koch [Thu, 17 Jan 2019 14:42:33 +0000 (15:42 +0100)]
ssh: Simplify the curve name lookup.

* agent/command-ssh.c (struct ssh_key_type_spec): Add field
alt_curve_name.
(ssh_key_types): Add some alternate curve names.
(ssh_identifier_from_curve_name): Lookup also bey alternative names
and return the canonical name.
(ssh_key_to_blob): Simplify the ECDSA case by using gcry_pk_get_curve
instead of the explicit mapping.
(ssh_receive_key): Likewise.  Use ssh_identifier_from_curve_name to
validate the curve name.  Remove the reverse mapping because since
GnuPG-2.2 Libgcrypt 1.7 is required.
(ssh_handler_request_identities): Log an error message.
--

This change will make it easier to support other curves, in particular
those from tokens.  Libgcrypt has a large list of alias names which we
now use to to make the mapping more flexible.

Signed-off-by: Werner Koch <wk@gnupg.org>
5 weeks agogpg: Report STATUS_NO_SECKEY when it is examined.
NIIBE Yutaka [Wed, 16 Jan 2019 01:27:21 +0000 (10:27 +0900)]
gpg: Report STATUS_NO_SECKEY when it is examined.

* g10/packet.h (struct pubkey_enc_list): Add result.
* g10/mainproc.c (proc_pubkey_enc): Initialize ->result.
(proc_encrypted): Report STATUS_NO_SECKEY status.
* g10/pubkey-enc.c (get_session_key): Set ->result.

--

This change is for GPGME compatibility.  Before this change,
gpgme/tests/json/t-json failed with t-decrypt-verify.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 weeks agodoc: Mark keyserver-options timeout and http-proxy as obsolete.
Werner Koch [Tue, 8 Jan 2019 10:21:07 +0000 (11:21 +0100)]
doc: Mark keyserver-options timeout and http-proxy as obsolete.

--

6 weeks agoscd: Fix for USB INTERRUPT transfer.
NIIBE Yutaka [Mon, 7 Jan 2019 05:08:51 +0000 (14:08 +0900)]
scd: Fix for USB INTERRUPT transfer.

* scd/ccid-driver.c (intr_cb): When LIBUSB_TRANSFER_NO_DEVICE,
just handle this event as failure.

--

It used to try another interrupt transfer request to make sure
if it fails again.

GnuPG-bug-id: 4308
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 weeks agoscd: Add two variants to the set of ISO7816 functions.
Werner Koch [Thu, 3 Jan 2019 14:18:15 +0000 (15:18 +0100)]
scd: Add two variants to the set of ISO7816 functions.

* scd/iso7816.c (iso7816_select_application_ext): New.
(iso7816_get_data_odd): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 weeks agoscd: Support "READKEY --advanced" for all cards.
Werner Koch [Thu, 3 Jan 2019 14:17:04 +0000 (15:17 +0100)]
scd: Support "READKEY --advanced" for all cards.

* scd/command.c (cmd_readkey): Reformat for advanced mode.
--

The --advanced option used to work only if the driver supported that
but not if we extracted the public key from an x.509 certificate.
This patch fixes that.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 weeks agodoc: Typo fix in code comment
Werner Koch [Wed, 2 Jan 2019 15:15:25 +0000 (16:15 +0100)]
doc: Typo fix in code comment

--

2 months agowks: Do not use compression for the encrypted data.
Werner Koch [Tue, 18 Dec 2018 07:21:03 +0000 (08:21 +0100)]
wks: Do not use compression for the encrypted data.

* tools/gpg-wks-client.c (encrypt_response): Add arg -z0.
* tools/gpg-wks-server.c (encrypt_stream): Ditto.
--

If for example a server was built without the development packages of
the compression libraries installed, the server will not be able to
decrypt a request.  In theory this can't happen due to the preference
system but it is just to easy to create the server's key using a
different version of gpg and then use gpg-wks-server built
differently.

For the short messages we exchange compression is not really required
and thus we better do without to make the system more robust.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agoscd: Fix description string.
NIIBE Yutaka [Tue, 18 Dec 2018 01:26:57 +0000 (10:26 +0900)]
scd: Fix description string.

* scd/app-openpgp.c (data_objects): Capitalize the word for usage.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agoSilence a few compiler warnings new with gcc 8.
Werner Koch [Mon, 17 Dec 2018 17:46:26 +0000 (18:46 +0100)]
Silence a few compiler warnings new with gcc 8.

* dirmngr/dns.c: Include gpgrt.h.  Silence -Warray-bounds also gcc.
* tools/gpg-pair-tool.c (command_respond): Init two vars to silence
gcc.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agocard: Suppress error message by agent_scd_cardlist.
NIIBE Yutaka [Wed, 12 Dec 2018 01:25:34 +0000 (10:25 +0900)]
card: Suppress error message by agent_scd_cardlist.

* g10/call-agent.c (agent_scd_cardlist): Add
FLAG_FOR_CARD_SUPPRESS_ERRORS.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agoagent: Make the S2K calibration time runtime configurabe.
Werner Koch [Tue, 11 Dec 2018 17:12:51 +0000 (18:12 +0100)]
agent: Make the S2K calibration time runtime configurabe.

* agent/protect.c (s2k_calibration_time): New file global var.
(calibrate_s2k_count): Use it here.
(get_calibrated_s2k_count): Replace function static var by ...
(s2k_calibrated_count): new file global var.
(set_s2k_calibration_time): New function.
* agent/gpg-agent.c (oS2KCalibration): New const.
(opts): New option --s2k-calibration.
(parse_rereadable_options): Parse that option.
--

Note that using an unrelistic high value (like 60000) takes quite some
time for calibration.

GnuPG-bug-id: 3399
Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agodirmngr: Retry another server from the pool on 502, 503, 504.
Werner Koch [Tue, 11 Dec 2018 12:39:41 +0000 (13:39 +0100)]
dirmngr: Retry another server from the pool on 502, 503, 504.

* dirmngr/ks-engine-hkp.c (handle_send_request_error): Add arg
http_status and handle it.
(ks_hkp_search): Get http_status froms end_request and pass on to
handle_send_request_error.
(ks_hkp_get): Ditto.
(ks_hkp_put): Ditto.
--

GnuPG-bug-id: 4175
Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agodirmngr: New function http_status2string.
Werner Koch [Tue, 11 Dec 2018 12:24:21 +0000 (13:24 +0100)]
dirmngr: New function http_status2string.

* dirmngr/http.c (http_status2string): New.
--

Right now only the standard 5xx codes.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agogpg: In search-keys return "Not found" instead of "No Data".
Werner Koch [Tue, 11 Dec 2018 11:29:58 +0000 (12:29 +0100)]
gpg: In search-keys return "Not found" instead of "No Data".

* g10/keyserver.c (keyserver_search): Check for NO_DATA.
--

GnuPG-bug-id: 3830
Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agotools: Use POSIX compatible arguments for find
Tomi Leppänen [Tue, 11 Dec 2018 07:42:33 +0000 (08:42 +0100)]
tools: Use POSIX compatible arguments for find

* tools/addgnupghome (filelist): Remove bashism.

2 months agog10: Fix print_pubkey_info new line output.
NIIBE Yutaka [Wed, 5 Dec 2018 07:44:59 +0000 (16:44 +0900)]
g10: Fix print_pubkey_info new line output.

* g10/keylist.c (print_pubkey_info): Reverse the condition.

--

This mistakes were introduced when replacing by estream.

It resulted 'gpg --card-status' from a process with no controlling
terminal fails.

Fixes-commit: fb2ba98963beea249474f5d6d7345cf9b4b7f570
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agowks: Fix filter expression syntax flaw.
Werner Koch [Tue, 4 Dec 2018 15:00:49 +0000 (16:00 +0100)]
wks: Fix filter expression syntax flaw.

* tools/wks-util.c (wks_get_key, wks_filter_uid): The filter
expression needs a space before the value.
(install_key_from_spec_file): Replace es_getline by es_read_line and
remove debug output.
--

A value of starting with '<' was considered an invalid operator due to
our tokenization method.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agogpg: Prepare revocation keys for use with v5 keys.
Werner Koch [Tue, 4 Dec 2018 14:43:19 +0000 (15:43 +0100)]
gpg: Prepare revocation keys for use with v5 keys.

* g10/packet.h (struct revocation_key): Add field 'fprlen'.
* g10/parse-packet.c (parse_revkeys): Set fprlen and allow for v5
keys.  Also fix reading of unitialized data at place where
MAX_FINGERPRINT_LEN is used.
* g10/revoke.c (gen_desig_revoke): Allow for v5 keys and use fprlen.
Do an explicit compare to avoid reading unitialized data.
* g10/sig-check.c (check_revocation_keys): Use the fprlen.
* g10/getkey.c (merge_selfsigs_main): Do an explicit copy to avoid
reading unitialized data.
* g10/import.c (revocation_present): Use fprlen.
* g10/keyedit.c (show_key_with_all_names): Use fprlen.
(menu_addrevoker): Use fprlen.  Allow for v5 keys.
* g10/keygen.c (keygen_add_revkey): Use fprlen.
(parse_revocation_key): Allow for v5 keys.
* g10/keyid.c (keyid_from_fingerprint): Allow for v5 keys.  Print a
better error message in case of bogus fingerprints.
* g10/keylist.c (print_revokers): Use fprlen.
--

The reading of uninitialized data is harmless but we better fix it to
make valgrind happy.  More serious was that we always passed
MAX_FINGERPRINT_LEN but we will need to support 20 and 32 octet
fingerprints and MAX_FINGERPRINT_LEN would be too large for a v4.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agowks: Allow reading of --install-key arguments from stdin.
Werner Koch [Tue, 4 Dec 2018 14:27:19 +0000 (15:27 +0100)]
wks: Allow reading of --install-key arguments from stdin.

* tools/wks-util.c (install_key_from_spec_file): New.
(wks_cmd_install_key): Call it.
* tools/gpg-wks-client.c (main): Allow --install-key w/o arguments.
* tools/gpg-wks-server.c (main): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agogpg: New list-option "show-only-fpr-mbox".
Werner Koch [Tue, 4 Dec 2018 11:32:28 +0000 (12:32 +0100)]
gpg: New list-option "show-only-fpr-mbox".

* g10/gpg.c (parse_list_options): Add option "show-only-fpr-mbox".
* g10/options.h (LIST_SHOW_ONLY_FPR_MBOX): New.
* g10/keylist.c (list_keyblock_simple): New.
(list_keyblock): Call it.
(list_all): Do not print the keyring name in LIST_SHOW_ONLY_FPR_MBOX
mode.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agowks: Create sub-directories
Werner Koch [Tue, 4 Dec 2018 10:37:54 +0000 (11:37 +0100)]
wks: Create sub-directories

* tools/wks-util.c (wks_compute_hu_fname): Stat and create directory
if needed.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agowks: Add new commands --install-key and --remove-key to the client.
Werner Koch [Tue, 4 Dec 2018 09:31:42 +0000 (10:31 +0100)]
wks: Add new commands --install-key and --remove-key to the client.

* tools/gpg-wks-client.c (aInstallKey, aRemoveKey, oDirectory): New.
(opts): Add "--install-key", "--remove-key" and "-C".
(parse_arguments): Parse them.
(main): Check that the given directory exists.  Implement the new
commands.
--

These commands maybe useful to prepare a WKD directory on a non-Unix
box using the standard wks client.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agowks: Move a few server functions to wks-util.
Werner Koch [Tue, 4 Dec 2018 08:45:42 +0000 (09:45 +0100)]
wks: Move a few server functions to wks-util.

* tools/gpg-wks-server.c (write_to_file): Move to ...
* tools/wks-util.c: here.
* tools/gpg-wks-server.c (compute_hu_fname): Move to ...
* tools/wks-util.c (wks_compute_hu_fname): here.
* tools/gpg-wks-server.c (fname_from_userid): Move to ...
* tools/wks-util.c (wks_fname_from_userid): here.
* tools/gpg-wks-server.c (command_install_key): Move to ...
* tools/wks-util.c (wks_cmd_install_key): here and change caller.
* tools/gpg-wks-server.c (command_remove_key): Move to ...
* tools/wks-util.c (wks_cmd_remove_key): here and change callers.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agobuild: Remove --with-*-prefix from configure_opts.
NIIBE Yutaka [Tue, 4 Dec 2018 03:32:01 +0000 (12:32 +0900)]
build: Remove --with-*-prefix from configure_opts.

* autogen.rc (configure_opts): Remove --with-*-prefix.

--

It seems that we haven't done cross-build for amd64 for a while,
we now use nPth instead of Pth.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agog10/mainproc: disable hash contexts when --skip-verify is used
Jussi Kivilinna [Sat, 1 Dec 2018 11:43:10 +0000 (13:43 +0200)]
g10/mainproc: disable hash contexts when --skip-verify is used

* g10/mainproc.c (proc_plaintext): Do not enable hash contexts when
opt.skip_verify is set.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 months agocommon/iobuf: fix memory wiping in iobuf_copy
Jussi Kivilinna [Sat, 1 Dec 2018 11:43:10 +0000 (13:43 +0200)]
common/iobuf: fix memory wiping in iobuf_copy

* common/iobuf.c (iobuf_copy): Wipe used area of buffer instead of
first sizeof(char*) bytes.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 months agocommon/mischelp: use platform memory zeroing function for wipememory
Jussi Kivilinna [Sat, 1 Dec 2018 11:43:09 +0000 (13:43 +0200)]
common/mischelp: use platform memory zeroing function for wipememory

* common/mischelp.h (wipememory): Replace macro with function
prototype.
(wipememory2): Remove.
* common/mischelp.c (wipememory): New.
* configure.ac (AC_CHECK_FUNCS): Check for 'explicit_bzero'.
--

In new wipememory function, memory is cleared through platform
provided secure memory zeroing function, SecureZeroMemory
or explicit_bzero.

If none of these is available, memset is called through
volatile function pointer to so that compiler won't optimize
away the call.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 months agoscd: Add strerror to new error message.
Werner Koch [Fri, 30 Nov 2018 11:38:51 +0000 (12:38 +0100)]
scd: Add strerror to new error message.

* agent/call-scd.c (wait_child_thread): Add %s.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agogpg: Improve error message about failed keygrip computation.
Werner Koch [Fri, 30 Nov 2018 11:35:37 +0000 (12:35 +0100)]
gpg: Improve error message about failed keygrip computation.

* g10/keyid.c (keygrip_from_pk): Print the fingerprint on failure.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agoscd: Serialize opening device by select_application.
NIIBE Yutaka [Wed, 28 Nov 2018 05:59:44 +0000 (14:59 +0900)]
scd: Serialize opening device by select_application.

* scd/app.c (app_new_register): Don't lock APP_LIST_LOCK here.
(select_application): Lock with APP_LIST_LOCK earlier.

--

What we want to do here is to serialize the call of
select_application.  In the old code, it was possible
that a call of select_application was blocked internally,
and then another call of select_application entered.

We can have a dedicated lock for call of select_application,
but it is easier to re-use APP_LIST_LOCK.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agoagent: Better serialization for scdaemon access.
NIIBE Yutaka [Tue, 27 Nov 2018 02:08:51 +0000 (11:08 +0900)]
agent: Better serialization for scdaemon access.

* agent/call-scd.c (unlock_scd): Move lock before accessing IN_USE.
(wait_child_thread): Add log_info for Windows, and fixed log_error
message.

--

The old code is still valid with cooperate threads, but this is
better.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agow32: Fix linkage of gpg-pair-tool
Andre Heinecke [Mon, 26 Nov 2018 12:05:26 +0000 (13:05 +0100)]
w32: Fix linkage of gpg-pair-tool

* tools/Makefile.am (gpg_pair_tool_LDADD): Add W32SOCKLIBS.

--
This is required because parts of libcommon depend on ws2_32.

2 months agoagent: Have a thread to wait for the child process of scdaemon.
NIIBE Yutaka [Mon, 26 Nov 2018 03:07:36 +0000 (12:07 +0900)]
agent: Have a thread to wait for the child process of scdaemon.

* agent/call-scd.c (wait_child_thread): New.
(start_scd): Create a thread for wait_child_thread.
(agent_scd_check_aliveness): Remove.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agoagent: Defer calling assuan_release when it's still in use.
NIIBE Yutaka [Mon, 26 Nov 2018 02:05:28 +0000 (11:05 +0900)]
agent: Defer calling assuan_release when it's still in use.

* agent/call-scd.c (struct scd_local_s): Remove LOCK, introduce IN_USE
and INVALID flags.
(unlock_scd): Call assuan_release when CTX is invalid.
(start_scd): Set IN_USE.
(agent_scd_check_aliveness): Don't call assuan_release when it's in use.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agoagent: Clean up SCDaemon management.
NIIBE Yutaka [Mon, 26 Nov 2018 01:37:02 +0000 (10:37 +0900)]
agent: Clean up SCDaemon management.

* agent/call-scd.c (struct scd_local_s): Remove ctrl_backlink.
(start_scd): Don't assign to the field.
(agent_scd_check_aliveness): Fix typo in comment.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 months agodirmngr: Avoid possible CSRF attacks via http redirects.
Werner Koch [Thu, 22 Nov 2018 21:27:56 +0000 (22:27 +0100)]
dirmngr: Avoid possible CSRF attacks via http redirects.

* dirmngr/http.h (parsed_uri_s): Add fields off_host and off_path.
(http_redir_info_t): New.
* dirmngr/http.c (do_parse_uri): Set new fields.
(same_host_p): New.
(http_prepare_redirect): New.
* dirmngr/t-http-basic.c: New test.
* dirmngr/ks-engine-hkp.c (send_request): Use http_prepare_redirect
instead of the open code.
* dirmngr/ks-engine-http.c (ks_http_fetch): Ditto.
--

With this change a http query will not follow a redirect unless the
Location header gives the same host.  If the host is different only
the host and port is taken from the Location header and the original
path and query parts are kept.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agodoc: Clarify use of clear and nodefault in the AKL.
Werner Koch [Wed, 21 Nov 2018 08:20:56 +0000 (09:20 +0100)]
doc: Clarify use of clear and nodefault in the AKL.

--

3 months agogpg: Start using OCB mode by default with Libgcrypt 1.9.
Werner Koch [Fri, 16 Nov 2018 08:19:10 +0000 (09:19 +0100)]
gpg: Start using OCB mode by default with Libgcrypt 1.9.

* g10/main.h (GCRYPT_VERSION_NUMBER): Fix type in condition.
--

GnuPG-bug-id: 4259
Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agodoc: Add NEWS item from recent 2.2 releases.
Werner Koch [Fri, 16 Nov 2018 07:30:47 +0000 (08:30 +0100)]
doc: Add NEWS item from recent 2.2 releases.

--

3 months agocard: Display UIF setting.
NIIBE Yutaka [Thu, 15 Nov 2018 04:57:31 +0000 (13:57 +0900)]
card: Display UIF setting.

* g10/call-agent.h (agent_card_info_s): Add UIF fields.
* g10/call-agent.c (learn_status_cb): Put UIF DOs info.
* g10/card-util.c (current_card_status): Output for UIF.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>