gnupg.git
6 months agoagent: Default to extended key format.
Werner Koch [Wed, 6 Mar 2019 13:09:57 +0000 (14:09 +0100)]
agent: Default to extended key format.

* agent/gpg-agent.c (oDisableExtendedKeyFormat, oNoop): New.
(oEnableExtendedKeyFormat): Remove.
(opts): Make --enable-extended-key-format a dummy option.  Add
disable-extended-key-format.
(parse_rereadable_options): Implement oDisableExtendedKeyFormat.
--

Extended key format is supported since vesion 2.1.12 which should have
long been replaced by a newer version inh all installations.  Thus for
2.3 we will make use of the extended-key-format by default.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agodoc: First take on instructions on how to init PIV cards
Werner Koch [Wed, 6 Mar 2019 11:46:09 +0000 (12:46 +0100)]
doc: First take on instructions on how to init PIV cards

--

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Allow PEM encoded certificates in "writecert".
Werner Koch [Wed, 6 Mar 2019 11:40:45 +0000 (12:40 +0100)]
card: Allow PEM encoded certificates in "writecert".

* tools/gpg-card.c (cmd_writecert): Convert from base64.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Print the keyref also for non-initialized slots.
Werner Koch [Wed, 6 Mar 2019 09:23:56 +0000 (10:23 +0100)]
card: Print the keyref also for non-initialized slots.

* tools/gpg-card.c (list_one_kinfo): Add arg label_keyref and change
callers.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoagent: Fix detection of exit of scdaemon.
NIIBE Yutaka [Wed, 6 Mar 2019 01:33:54 +0000 (10:33 +0900)]
agent: Fix detection of exit of scdaemon.

* agent/call-scd.c (start_scd): Acquire START_SCD_LOCK for
SCD_LOCAL_LIST.  Move common case code to fast path.
Release START_SCD_LOCK before calling unlock_scd.
When new CTX is allocated, clear INVALID flag.
(agent_reset_scd): Serialize the access to SCD_LOCAL_LIST by
START_SCD_LOCK.

--

GnuPG-bug-id: 4377
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agocard: Print card version. Check for bad Yubikeys.
Werner Koch [Tue, 5 Mar 2019 16:40:08 +0000 (17:40 +0100)]
card: Print card version.  Check for bad Yubikeys.

* scd/app.c (app_new_register): Set card version for Yubikeys.
(app_write_learn_status): Print CARDVERSION and APPVERSION.
* tools/card-call-scd.c (learn_status_cb): Detect them.
* tools/gpg-card.h (struct card_info_s): Add appversion and
cardversion.
* tools/gpg-card.c (list_openpgp): Remove version printing from serial
number.
(print_a_version): New.
(list_card): Print card and app version.
(cmd_generate): Do not allow broken Yubikeys.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd: Rename a shared info field name.
Werner Koch [Tue, 5 Mar 2019 16:17:39 +0000 (17:17 +0100)]
scd: Rename a shared info field name.

* scd/app-piv.c (app_select_piv):
* scd/app-common.h (struct app_ctx_s): Rename 'card_version' to
'cardversion'.  Rename all users.  Add 'appversion'.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd:piv: Implement import of private keys for Yubikeys.
Werner Koch [Tue, 5 Mar 2019 14:49:20 +0000 (15:49 +0100)]
scd:piv: Implement import of private keys for Yubikeys.

* scd/app-piv.c (concat_tlv_list): Add arg 'secure' and adjust
 callers.
(writekey_rsa, writekey_ecc): New.
(do_writekey): New.
(do_writecert): Provide a better error message for an empty cert.
(app_select_piv): Register do_writekey.
* scd/iso7816.c (iso7816_send_apdu): New.
* scd/app-common.h (APP_WRITEKEY_FLAG_FORCE): New.
* agent/command.c (cmd_keytocard): Make the timestamp optional.
* tools/card-call-scd.c (inq_writekey_parms): Remove.
(scd_writekey): Rewrite.
* tools/gpg-card.c (cmd_writekey): New.
(enum cmdids): Add cmdWRITEKEY.
(dispatch_command, interactive_loop): Call cmd_writekey.
--

This has been tested with gpgsm and RSA keys.  For ECC keys only
partly tested using the sample OpenPGP nistp256 and nistp384 keys
because gpgsm does not yet support ECC certificates and thus we can't
write the certificates to the cert object after a writekey.  Note that
they nevertheless show up in "gpgcard list" because gpg-card searches
for them in gpg and gpgsm.  However, this does not work completely.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agogpg: Make invalid primary key algos obvious in key listings.
Werner Koch [Tue, 5 Mar 2019 11:39:11 +0000 (12:39 +0100)]
gpg: Make invalid primary key algos obvious in key listings.

* g10/keylist.c (print_key_line): Print a warning for invalid algos.
--

Non-OpenPGP compliant keys now show a warning flag on the sec or pub
line like in:

  gpg: can't encode a 256 bit MD into a 88 bits frame, algo=8
  sec   cv25519 2019-01-30 [INVALID_ALGO]
        4239F3D606A19258E7A88C3F9A3F4F909C5034C5
  uid           [ultimate] ffffff

Instead of showing the usage flags "[CE]".  Without this patch only
the error message is printed and the reason for it was not immediately
obvious (cv25519 is encryption only but we always consider the primary
key as having the "C" flag).

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoagent: Minor change to the KEYTOCARD command.
Werner Koch [Tue, 5 Mar 2019 11:08:27 +0000 (12:08 +0100)]
agent: Minor change to the KEYTOCARD command.

* agent/command.c (cmd_keytocard): Make timestamp optional.  Use
modern parser function.
* agent/call-scd.c (agent_card_writekey): Rename an arg and for
clarity return gpg_error_t instead of int.
* agent/divert-scd.c (divert_writekey): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agosm: Print Yubikey attestation extensions with --dump-cert.
Werner Koch [Fri, 1 Mar 2019 14:23:49 +0000 (15:23 +0100)]
sm: Print Yubikey attestation extensions with --dump-cert.

* sm/keylist.c (oidtranstbl): Add Yubikey OIDs.
(OID_FLAG_HEX): New.
(print_hex_extn): New.
(list_cert_raw): Make use of that flag.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd:piv: Add feature to read Yubikey attestation certificates.
Werner Koch [Fri, 1 Mar 2019 13:04:29 +0000 (14:04 +0100)]
scd:piv: Add feature to read Yubikey attestation certificates.

* scd/app-piv.c (do_readcert): Add hack to read Yubikey attestaions.
--

Use
  gpg-card 'readcert PIV.ATST.9A >x.crt'
to store the attestation certificate for 9A into X.CRT.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd:piv: Allow writecert to only write matching certs.
Werner Koch [Fri, 1 Mar 2019 11:58:56 +0000 (12:58 +0100)]
scd:piv: Allow writecert to only write matching certs.

* scd/app-piv.c (do_readkey): Read the key from the cert here instead
of letting the upper layer do this.
(do_writecert): Check that the cert matches the key and that a key has
already been generated.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Remove the "admin" command.
Werner Koch [Fri, 1 Mar 2019 11:20:24 +0000 (12:20 +0100)]
card: Remove the "admin" command.

* tools/gpg-card.c (cmd_passwd): Remove arg allow_admin.
(enum cmdids): Rename cmdAUTHENTICATE to cmdAUTH and cmdFACTORYRESET
to cmdFACTRST.
(cmds): Remove column 'admin_only'.
(interactive_loop): Remove admin_only stuff.
--

That command has always been an annoyance.  Symbols have been renamed
for source cosmetics.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agosm: Don't mark a cert as de-vs compliant if it leads to SHA-1 sigs.
Werner Koch [Thu, 28 Feb 2019 13:43:42 +0000 (14:43 +0100)]
sm: Don't mark a cert as de-vs compliant if it leads to SHA-1 sigs.

* sm/keylist.c (print_compliance_flags): Also check the diges_also.
--

A certificate with algorithm sha1WithRSAEncryption can be de-vs
compliant (e.g. if the next in the chain used sha256WithRSAEncryption
to sign it and RSA is long enough) but flagging it as such is useless
because that certificate can't be used because it will create
signatures using the non-compliant SHA-1 algorithm.

Well, it could be used for encryption.  But also evaluating the
key-usage flags here would make it harder for the user to understand
why certain certificates are listed as de-vs compliant and others are
not.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoagent: PKSIGN should return signature in same format for card.
NIIBE Yutaka [Wed, 27 Feb 2019 01:37:26 +0000 (10:37 +0900)]
agent: PKSIGN should return signature in same format for card.

* agent/pksign.c (agent_pksign_do):

--

It's best to keep same data format by libgcrypt.

For card (due to historical reasons), gpg-agent or scdaemon used to
prefix 0x00 when it starts 0x80, so that it can be parsed signed MPI
as well as unsigned MPI.  It used to do nothing for preceding zeros.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agoscd: Simplify the app_readkey parameters.
Werner Koch [Tue, 26 Feb 2019 15:42:50 +0000 (16:42 +0100)]
scd: Simplify the app_readkey parameters.

* scd/app-help.c (app_help_pubkey_from_cert): New.
* scd/command.c (cmd_readkey): Refactor to use that new function and
handle the --advanced flag only here.
* scd/app.c (app_readkey): Remove parm advanced.
* scd/app-common.h (struct app_ctx_s): Remove parm advanced from the
readkey member.
* scd/app-nks.c (do_readkey): Adjust for removed parm.
* scd/app-piv.c (do_readkey): Ditto.
* scd/app-openpgp.c (do_readkey): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoconf: New option --show-socket.
Werner Koch [Mon, 25 Feb 2019 14:55:13 +0000 (15:55 +0100)]
conf: New option --show-socket.

* tools/gpgconf-comp.c (gc_component_t): Move this enum to ...
* tools/gpgconf.h: here.
* tools/gpgconf.c (oShowSocket): New.
(opts): Add new option.
(main): Implement new option.
--

This is a convenience options for software which directly connects to
gpg-agent and thus needs to new the socket.  By using --show-socket
along with --launch that software can also autostart the agent or the
dirmngr.  Without this two calls to gpgconf would be required.

Actually the same behaviour can be achieved by running
gpg-connect-agent to query the running gpg-agent's socket via GETINFO.
The gpg-connect also makes sure that the agent is started.  This is
not anymore suggested because gpgconf shall in future be used for all
such things.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agolibdns: Avoid using compound literals (8).
NIIBE Yutaka [Tue, 26 Feb 2019 03:26:02 +0000 (12:26 +0900)]
libdns: Avoid using compound literals (8).

* dirmngr/dns.h (dns_quietinit): Remove.
(dns_hints_i_new): Remove.

--

Even before our change, dns_quietinit was questionable macro;  There
was no place in dns.c which requires overrides in initializer list.
Only redundant zero were.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (7).
NIIBE Yutaka [Tue, 26 Feb 2019 03:13:35 +0000 (12:13 +0900)]
libdns: Avoid using compound literals (7).

* dirmngr/dns.h (DNS_OPTS_INIT, dns_opts): Remove.
* dirmngr/dns-stuff.c (libdns_res_open): Use zero-ed, and initialized
automatic variable for opts.
* dirmngr/dns.c (send_query, resolve_query, resolve_addrinfo):
Likewise.

--

In fact, DNS_OPTS_INIT was only needed when args are none.  With
partially specified initialization, C99 guarantees zero-ed other
members just like static object.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (6).
NIIBE Yutaka [Tue, 26 Feb 2019 02:55:32 +0000 (11:55 +0900)]
libdns: Avoid using compound literals (6).

* dirmngr/dns.h (dns_rr_i_new): Remove.
(dns_rr_i_init): Remove unused second argument.
* dirmngr/dns.c (dns_p_dump, dns_hints_query, print_packet)
(parse_packet): Use automatic variable for struct dns_rr_i.
(dns_d_cname): No need to call dns_rr_i_init after memset 0.
(dns_rr_i_init): Remove unused second argument.  Return nothing.
* dirmngr/dns-stuff.c (resolve_addr_libdns, get_dns_cert_libdns)
(getsrv_libdns): Follow the change of dns_rr_i_init.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (5).
NIIBE Yutaka [Tue, 26 Feb 2019 02:43:10 +0000 (11:43 +0900)]
libdns: Avoid using compound literals (5).

* dirmngr/dns.h (dns_rr_foreach): Don't use dns_rr_i_new.
Call dns_rr_grep with NULL.
* dirmngr/dns.c (dns_rr_grep): Support NULL for error_.

--

Here we still use C99 feature of struct member initialization in
dns_rr_foreach, for struct dns_rr_i.  Note that in C99, it guarantees
non-specified member fields are initialized by zero.  So, there's no
need to use dns_rr_i_new at all.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (4).
NIIBE Yutaka [Tue, 26 Feb 2019 01:58:16 +0000 (10:58 +0900)]
libdns: Avoid using compound literals (4).

* dirmngr/dns.h (dns_d_new*): Remove.
* dirmngr/dns.c (parse_packet): Use dns_d_init with automatic
variable.
(parse_domain): Likewise.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (3).
NIIBE Yutaka [Tue, 26 Feb 2019 01:34:03 +0000 (10:34 +0900)]
libdns: Avoid using compound literals (3).

* dirmngr/dns.h (dns_p_new): Remove.
* dirmngr/dns.c (dns_hosts_query): Use dns_p_init with automatic
variable.
(dns_hints_query, dns_res_glue, parse_packet, query_hosts)
(send_query, show_hints, echo_port): Likewise.

--

Implicit automatic allocation by compound literals is confusing
for C90 code.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals (2).
NIIBE Yutaka [Tue, 26 Feb 2019 01:04:09 +0000 (10:04 +0900)]
libdns: Avoid using compound literals (2).

* dirmngr/dns.h (dns_strsection1, dns_strsection3): Remove.
(dns_strclass1, dns_strclass3): Remove.
(dns_strtype1, dns_strtype3): Remove.
(dns_strsection, dns_strclass, dns_strtype): Directly use the
function.
* dirmngr/dns.c (dns_strsection): Use automatic variable.
(dns_strclass, dns_strtype): Likewise.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agolibdns: Avoid using compound literals.
NIIBE Yutaka [Tue, 26 Feb 2019 00:42:54 +0000 (09:42 +0900)]
libdns: Avoid using compound literals.

* dirmngr/dns.c (dns_inet_pton, dns_so_tcp_keep): Use automatic
variables.
(dns_poll, dns_send_nopipe): Likewise, adding const qualifier.

--

Compound literals is a feature of C99.  Because we only use C90 plus
some limited features, in the project, it's better to avoid it.

Besides, we make sure when it's read-only.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agoscd: PIV: Always require a PIN for signing with 9C.
Werner Koch [Mon, 25 Feb 2019 10:29:30 +0000 (11:29 +0100)]
scd: PIV: Always require a PIN for signing with 9C.

* scd/app-piv.c (verify_chv): Add arg 'force'.
(do_sign): Use force for 0x9c.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Rename gpg-card-tool to gpg-card.
Werner Koch [Mon, 25 Feb 2019 08:28:22 +0000 (09:28 +0100)]
card: Rename gpg-card-tool to gpg-card.

* tools/card-tool-keys.c: Rename to card-keys.c.
* tools/card-tool-misc.c: Rename to card-misc.c.
* tools/card-tool-yubikey.c: Rename to card-yubikey.c.
* tools/card-tool.h: Rename to gpg-card.h.
* tools/gpg-card-tool-w32info.rc: Rename to gpg-card-w32info.rc
* doc/card-tool.texi: Rename top gpg-card.texi

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoagent: Fix for suggested Libgcrypt use.
Werner Koch [Fri, 22 Feb 2019 13:09:02 +0000 (14:09 +0100)]
agent: Fix for suggested Libgcrypt use.

* agent/divert-scd.c (divert_pkdecrypt): Skip a flags parameter.
--

The libgcrypt docs say that a "flags" parameter should always be used
in the input of pkdecrypt.  Thus we should allow that parameter also
when parsing an s-expression to figure out the algorithm for use with
scdaemon.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agogpgscm: Build well even if NDEBUG defined.
NIIBE Yutaka [Mon, 25 Feb 2019 01:44:16 +0000 (10:44 +0900)]
gpgscm: Build well even if NDEBUG defined.

* gpgscm/scheme.c (gc_reservation_failure): Fix adding ";".
[!NDEBUG] (scheme_init_custom_alloc): Don't init seserved_lineno.

--

Picked from libgpg-error commit of:
8a9397896fd202dcfb3fb46259e43bc05a0ddd2e

In some build environment, NDEBUG is defined (although it's
bad practice).  This change supports such a situation.

GnuPG-bug-id: 3959
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agoscd: internal driver: Submit SET_INTERFACE control transfer.
NIIBE Yutaka [Fri, 22 Feb 2019 11:05:09 +0000 (20:05 +0900)]
scd: internal driver: Submit SET_INTERFACE control transfer.

* scd/ccid-driver.c (ccid_open_usb_reader): Alway submit SET_INTERFACE
control transfer.

--

This handling is not mondatory, but it's better to do so, because
there are card reader with pinpad and token with ack button, which
support user interaction.

User interaction status should be reset at open time.  The status
should be reset when the session is closed/stopped.  In practice,
since cleanup routine in a driver may not be called properly, it's
good to submit SET_INTERFACE at open time.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agosm: Fix certificate creation with key on card.
Werner Koch [Thu, 21 Feb 2019 16:32:39 +0000 (17:32 +0100)]
sm: Fix certificate creation with key on card.

* sm/certreqgen.c (create_request): Fix for certmode.
--

When using an existing key from a card for certificate signing (in
contrast to the default of generating a CSR), the code tried to use
the same key for signing instead of the Signing-Key parameter.  It is
perfectly okay to use the regular signing path via gpg-agent for
certificate creation - only self-signed certificates with a key on the
card require the direct use of the card key (via "SCD PKSIGN").

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Print usage info for each key.
Werner Koch [Thu, 21 Feb 2019 11:43:07 +0000 (12:43 +0100)]
card: Print usage info for each key.

* tools/card-call-scd.c (learn_status_cb): Handle extended
KEYPARIRINFO.
* tools/card-tool.h (struct key_info_s): Add field 'usage'.
* tools/gpg-card-tool.c (list_one_kinfo): Show usage flags.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd: Extend KEYPAIRINFO by key usage info.
Werner Koch [Thu, 21 Feb 2019 08:24:37 +0000 (09:24 +0100)]
scd: Extend KEYPAIRINFO by key usage info.

* scd/app-openpgp.c (send_keypair_info): Append usage string.
* scd/app-piv.c (struct data_object_s): Remove column 'binary'.  Add
column 'usage'.
(dump_all_do): Adjust for removed 'binary'.
(send_keypair_and_cert_info): Append usage string.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agocard: Print the keyref in the listing.
Werner Koch [Thu, 21 Feb 2019 07:42:33 +0000 (08:42 +0100)]
card: Print the keyref in the listing.

* tools/gpg-card-tool.c (list_one_kinfo): Print the keyref.
--

The named keys are nice but knowing the actual keyref mapping to them
is also useful.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd: Don't let the "undefined" app cause a conflict error.
Werner Koch [Thu, 21 Feb 2019 07:40:59 +0000 (08:40 +0100)]
scd: Don't let the "undefined" app cause a conflict error.

* scd/app.c (check_conflict): Ignore "undefined".

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agosm: Prepare algo mapping to handle values > 255.
Werner Koch [Thu, 21 Feb 2019 07:51:27 +0000 (08:51 +0100)]
sm: Prepare algo mapping to handle values > 255.

* sm/misc.c (transform_sigval): Allow for larger values of MDALGO and
PKALGO.
--

Libgcrypt already defines larger values for them, so we should be
prepared in case we use them in the future.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoscd: Clear CHV status on timeout error.
NIIBE Yutaka [Thu, 21 Feb 2019 06:50:43 +0000 (15:50 +0900)]
scd: Clear CHV status on timeout error.

* scd/app-openpgp.c (clear_chv_status): New.
(do_change_pin): Use clear_chv_status.
(do_sign): Call clear_chv_status on GPG_ERR_TIMEOUT.
(do_auth, do_decipher): Likewise.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agoscd: Handle ack button timeout as GPG_ERR_TIMEOUT.
NIIBE Yutaka [Thu, 21 Feb 2019 06:16:11 +0000 (15:16 +0900)]
scd: Handle ack button timeout as GPG_ERR_TIMEOUT.

* scd/apdu.h (SW_ACK_TIMEOUT): New.
* scd/iso7816.c (map_sw): Return GPG_ERR_TIMEOUT for SW_ACK_TIMEOUT.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
6 months agotests: Add "disable-scdaemon" in gpg-agent.conf.
NIIBE Yutaka [Thu, 21 Feb 2019 03:26:09 +0000 (12:26 +0900)]
tests: Add "disable-scdaemon" in gpg-agent.conf.

* tests/openpgp/defs.scm: Add "disable-scdaemon".  Remove
  "scdaemon-program".
* tests/gpgme/gpgme-defs.scm, tests/gpgsm/gpgsm-defs.scm: Likewise.
* tests/inittests, tests/pkits/inittests: Add "disable-scdaemon"

--

Before this change, running "make check" accesses USB device by
scdaemon on host computer.  If there is any smartcard/token available,
it may affect test results.  Because default key choice depends on
smartcard/token availability now and existing tests have nothing about
testing smartcard/token, disabling scdaemon is good.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
7 months agoagent: Terminate pinentry process gracefully, by watching socket.
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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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

--

7 months 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>
7 months 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>
7 months 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>
7 months 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.

--

7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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.

7 months 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>
7 months 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>
7 months agodoc: Fix typo
Werner Koch [Tue, 29 Jan 2019 21:15:49 +0000 (22:15 +0100)]
doc: Fix typo

--

7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
7 months 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>
8 months 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.

8 months 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>
8 months 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>