aboutsummaryrefslogtreecommitdiffstats
path: root/agent/command-ssh.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2025-01-22agent: Fix ssh-agent's request_identities for skipped keys.Werner Koch1-2/+4
* agent/command-ssh.c (ssh_send_available_keys): Adjust key counter for skipped keys. -- Fixes-commit: 8b8a8b246c443d5631a88ec59b88edf00aa0ff51 which introduced a regression due to an extra variable for counting the keys. The bug showed up for example if a card with a Brainpool Auth key was also used. Unfortunately OpenSSH still does not allow for Brainpool keys.
2024-07-22agent: Avoid memory leak when handling ssh keys.Jakub Jelen1-0/+4
* agent/command-ssh.c (ssh_send_available_keys): Close file and directory on error paths. -- GnuPG-bug-id: 7201 Signed-off-by: Jakub Jelen <[email protected]>
2024-01-22agent: Add "ephemeral" Assuan option.Werner Koch1-4/+4
* agent/agent.h (struct ephemeral_private_key_s): New. (struct server_control_s): Add ephemeral_mode and ephemeral_keys. (GENKEY_FLAG_NO_PROTECTION, GENKEY_FLAG_PRESET): New. * agent/genkey.c (clear_ephemeral_keys): New. (store_key): Add arg ctrl and implement ephemeral_mode. Change all callers. (agent_genkey): Replace args no_protection and preset by a generic new flags arg. * agent/findkey.c (wipe_and_fclose): New. (agent_write_private_key): Add arg ctrl and implement ephemeral_mode. Change all callers. (agent_update_private_key): Ditto (read_key_file): Ditto. (agent_key_available): Ditto. * agent/command-ssh.c (card_key_available): Do not update display s/n in ephemeral mode. This is however enver triggred. * agent/gpg-agent.c (agent_deinit_default_ctrl): Cleanup ephemeral keys. * agent/command.c (cmd_genkey): Use the new flags instead of separate vars. (cmd_readkey): Create a shadow key only in non-ephemeral_mode. (cmd_getinfo): Add sub-command "ephemeral". (option_handler): Add option "ephemeral". -- The idea here that a session can be switched in an ephemeral mode which does not store or read keys from disk but keeps them local to the session. GnuPG-bug-id: 6944
2023-07-18agent,build,w32: Fix use of SOCKET.NIIBE Yutaka1-0/+4
* configure.ac (HAVE_SOCKET): Detect SOCKET type. * agent/command-ssh.c [HAVE_SOCKET] (start_command_handler_ssh): Use SOCKET to cast. -- GnuPG-bug-id: 6508 Signed-off-by: NIIBE Yutaka <[email protected]>
2023-05-26agent: Create and use Token entries to track the display s/n.Werner Koch1-2/+7
* agent/findkey.c (agent_write_private_key): Add arg dispserialno and update the token. (agent_write_shadow_key): Add arg dispserialno and adjust all callers. -- GnuPG-bug-id: 6135 Note that this has been forward ported from 2.2
2023-05-26agent: Create and use Token entries to track the display s/n.Werner Koch1-2/+7
* agent/findkey.c (agent_write_private_key): Add arg dispserialno and update the token. (agent_write_shadow_key): Add arg dispserialno and adjust all callers. -- GnuPG-bug-id: 6135 Note that this has been forward ported from 2.2
2023-04-18ssh: Allow to prefer on-disk keys over active card keys.Werner Koch1-5/+13
* agent/command-ssh.c (ssh_send_available_keys): Redefine the order of keys. -- GnuPG-bug-id: 6212
2023-03-13agent: Make --disable-extended-key-format a dummy option.Werner Koch1-1/+1
* agent/agent.h (opt): Remove enable_extended_key_format. * agent/gpg-agent.c (enum cmd_and_opt_values): Turn oDisableExtendedKeyFormat and oEnableExtendedKeyFormat into dummy options. * agent/protect.c (do_encryption): Remove arg use_ocb and corresponding code. (agent_protect): Ditto. Change all callers. * agent/findkey.c (agent_write_private_key): Simplify due to the removal of disable-extended-key-format. (write_extended_private_key): Fold into agent_write_private_key. -- This change is related to GnuPG-bug-id: 6386 but should have no visible effect except for the removal of option --disable-extended-key-format.
2023-02-01ssh: Allow to define the order in which keys are returned.Werner Koch1-56/+171
* agent/findkey.c (public_key_from_file): Add arg r_sshorder. (agent_ssh_key_from_file): Ditto. * agent/command-ssh.c (struct key_collection_item_s): New. (struct key_collection_s): New. (search_control_file): Add art r_lnr. (add_to_key_array): New. (free_key_array): New. (compare_key_collection_items): New. (ssh_send_available_keys): Rewrite to return the keys in the user given order. -- GnuPG-bug-id: 6212 We now first return the keys from active cards, followed by keys listed in sshcontrol, finally from those with the "Use-for-ssh" key attribute. Keys from active cards are returned sorted by their S/N. Keys from sshcontrol are returned in the order they are given in that file. Use-for-ssh keys are ordered by the value assigned to that key attribute. The values for the latter are clamped at 99999.
2022-11-02agent: Avoid blanks in the ssh key's comment.Werner Koch1-0/+5
* agent/command-ssh.c (card_key_available): Replace blanks. -- For managing the authorized_key file of ssh it is convenient if the comment does not have any spaces. Thus we now return cardno:FFFE_50FF3D01 instead of cardno:FFFE 50FF3D01 Note that gpg --export-ssh-key uses the keyid as comment because it does not known the S/N of the card. Gpg-agent however does not know about OpenPGP and uses the s/n.
2022-10-14agent,w32: Support Win32-OpenSSH emulation by gpg-agent.NIIBE Yutaka1-32/+38
* agent/agent.h (start_command_handler_ssh_stream): New. * agent/command-ssh.c (start_command_handler_ssh_stream): New. * agent/gpg-agent.c (oWin32OpenSSHSupport): New. (W32_DEFAILT_AGENT_PIPE_NAME): New. (main): Add oWin32OpenSSHSupport support. (win32_openssh_thread): New. (handle_connections): Spawn win32_openssh_thread. * configure.ac (NEED_GPGRT_VERSION): Require libgpg-error 1.46. -- GnuPG-bug-id: 3883 Signed-off-by: NIIBE Yutaka <[email protected]>
2022-06-28agent: Don't assume "OPENPGP.3" key means "Use-for-ssh:".NIIBE Yutaka1-2/+2
* agent/command-ssh.c: Fix comments. * agent/findkey.c (public_key_from_file): Remove "OPENPGP.3" check. -- GnuPG-bug-id: 5996 Signed-off-by: NIIBE Yutaka <[email protected]>
2022-06-22agent: Add KEYATTR command.NIIBE Yutaka1-1/+1
* agent/agent.h (agent_raw_key_from_file): Add R_KEYMETA argument. (agent_update_private_key): New. * agent/command-ssh.c (data_sign): Follow the change of the function agent_raw_key_from_file. * agent/command.c (do_one_keyinfo): Likewise. (cmd_keyattr): New. (register_commands): Add an entry of cmd_keyattr. * agent/findkey.c (agent_update_private_key): New. (agent_raw_key_from_file): Add R_KEYMETA argument. -- GnuPG-bug-id: 5988 Signed-off-by: NIIBE Yutaka <[email protected]>
2022-06-15agent,ssh: Fix for make not-inserted OpenPGP.3 keys available for SSH.Werner Koch1-5/+8
* agent/command-ssh.c (ssh_send_available_keys): Do not bump key_counter for ignored keys. Also use opt.debug instead of opt.verbose and fix a memory leak. -- The error shown by "ssh-add -l" before this fix was: error fetching identities: incomplete messag Fixes-commit: 193fcc2f7a8cca5240ce50499c54f99235a87e1c GnuPG-bug-id: 5996
2022-05-26agent,ssh: Make not-inserted OpenPGP.3 keys available for SSH.NIIBE Yutaka1-80/+160
* agent/agent.h (agent_ssh_key_from_file): New. * agent/command-ssh.c (get_ssh_keyinfo_on_cards): New. (ssh_send_available_keys): Loop on the GNUPG_PRIVATE_KEYS_DIR. Support keys by agent_ssh_key_from_file. (ssh_handler_request_identities): Move card key handling to ssh_send_available_keys. * agent/findkey.c (public_key_from_file): New. Adding handling for SSH. (agent_public_key_from_file): Use public_key_from_file. (agent_ssh_key_from_file): New. -- GnuPG-bug-id: 5996 Signed-off-by: NIIBE Yutaka <[email protected]>
2022-05-20agent: Fix a bug accessing after release when opt.verbose.NIIBE Yutaka1-4/+4
* agent/command-ssh.c (ssh_handler_request_identities): Don't release KEY_PUBLIC too early. -- Signed-off-by: NIIBE Yutaka <[email protected]>
2022-05-20agent: Factor out handling scanning over ssh keys.NIIBE Yutaka1-42/+48
* agent/command-ssh.c (ssh_send_available_keys): New. (ssh_handler_request_identities): Use ssh_send_available_keys. -- GnuPG-bug-id: 5985 Signed-off-by: NIIBE Yutaka <[email protected]>
2022-04-14ssh: Returned faked response for the new session-bind extension.Werner Koch1-0/+14
* agent/command-ssh.c (SSH_OPT_CONSTRAIN_MAXSIGN): New. (SSH_OPT_CONSTRAIN_EXTENSION): New. (ssh_handler_add_identity): Ignore them. (ssh_handler_extension): Take success for session-bind. -- OpenSSH 8.9 does not gracefully allow communication with older agent implementations. Until this new OpenSSH feature has been settled we return a faked response. Code has not yet been tested. GnuPG-bug-id: 5931
2022-04-14agent: Ignore MD5 Fingerprints for ssh keysJakub Jelen1-2/+4
-- * agent/command-ssh.c (add_control_entry): Ignore failure of the MD5 digest Signed-off-by: Jakub Jelen <[email protected]>
2022-04-07agent: Fix for possible support of Cygwin OpenSSH.NIIBE Yutaka1-1/+5
* agent/command-ssh.c (start_command_handler_ssh): Use es_sysopen. -- With new (not-yet-released) libgpg-error, gpg-agent should be able to handle connection from Cygwin version of OpenSSH. Signed-off-by: NIIBE Yutaka <[email protected]>
2022-04-04agent:w32: Fix for use of socket.NIIBE Yutaka1-7/+7
* agent/command-ssh.c (get_client_info): Use type gnupg_fd_t for socket, until call of socket API. (start_command_handler_ssh): Don't convert here. -- Signed-off-by: NIIBE Yutaka <[email protected]>
2022-01-28ssh: Fix adding an ed25519 key with a zero length comment.Werner Koch1-4/+10
* agent/command-ssh.c (sexp_key_construct): Do not put an empty string into an S-expression. (stream_read_string): Do not not try to a read a zero length block. -- Actually we could handles this different by not putting a comment tag into the s-expression, however this requires more code and at other places we already return "(none)" instead of an empty comment. The second fix is more or less a cosmetic thing to get better error messages in case the underlying read system call returns an error. GnuPG-bug-id: 5794
2021-05-11A few minor code cleanups and typo fixes.Werner Koch1-1/+1
* agent/command-ssh.c (ssh_handler_request_identities): Remove double check of ERR. * g10/getkey.c (get_pubkey_byname): Remove double use of break. * g10/pkglue.c (pk_encrypt): Handle possible NULL-ptr access due to failed malloc. Signed-off-by: Werner Koch <[email protected]>
2021-03-29agent: Skip unknown unknown ssh curves seen on cards.Werner Koch1-6/+16
* agent/command-ssh.c (ssh_handler_request_identities): Skip unknown curves. -- For example when using my standard ed25519 token and testing cards with only Brainpool support, the ssh-agent failed due to the unknown curves seen on the card. This patches fixes this by ignoring keys with unknown curves. Signed-off-by: Werner Koch <[email protected]>
2021-03-15gpg: New option --no-auto-trust-new-key.Beta-2.3.0-beta1655Werner Koch1-1/+1
* g10/gpg.c (oNoAutoTrustNewKey): New. (opts): Add --no-auto-trust-new-key. (main): Set it. * g10/options.h (opt): Add flags.no_auto_trust_new_key. Signed-off-by: Werner Koch <[email protected]>
2021-01-25agent: Support ssh-agent extensions for environment variables.Werner Koch1-1/+85
* common/session-env.c (session_env_list_stdenvnames): Extend to allow return all names as one string. * agent/command-ssh.c (SSH_REQUEST_EXTENSION): New. (SSH_RESPONSE_EXTENSION_FAILURE): New. (request_specs): Add handler for the extension command. (ssh_handler_extension): New. -- The extension mechanism is specified in https://tools.ietf.org/html/draft-miller-ssh-agent-04 Signed-off-by: Werner Koch <[email protected]>
2020-10-20Replace most of the remaining stdio calls by estream calls.Werner Koch1-12/+12
-- We need to use es_fopen on Windows to cope with non-ascii file names. This is quite a large but fortunately straightforward change. At a very few places we keep using stdio (for example due to the use of popen). GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <[email protected]>
2020-08-17agent: Allow to pass a timestamp to genkey and import.Werner Koch1-2/+4
* agent/command.c (cmd_genkey): Add option --timestamp. (cmd_import_key): Ditto. * agent/genkey.c (store_key): Add arg timestamp and change callers. (agent_genkey): Ditto. * agent/findkey.c (write_extended_private_key): Add args timestamp and new key to write a Created line. (agent_write_private_key): Add arg timestamp. (agent_write_shadow_key): Ditto. agent/protect-tool.c (agent_write_private_key): Ditto as dummy arg. Signed-off-by: Werner Koch <[email protected]>
2020-08-10agent: Add option --pss to pksign to be used by smartcards.Werner Koch1-0/+1
* agent/command.c (cmd_sethash): Add option --pss and allow for --hash=null. * agent/agent.h (struct server_control_s): Add digest.is_pss and zero where needed. * agent/pksign.c (agent_pksign_do): Allow for PSS with cards. * scd/command.c (cmd_pksign): Add for --hash=none. -- This is not a full implementaion of PSS but allows scdaemon card drivers to detect already PSS formatted data. Signed-off-by: Werner Koch <[email protected]>
2020-06-24agent: separate out daemon handling infrastructure for reuseJames Bottomley1-5/+5
* agent/call-scd.c: Factor re-usable code out to ... * agent/call-daemon.c: new. Store infos in an array to allow for other backend daemons. * agent/Makefile.am (gpg_agent_SOURCES): Add new file. * agent/agent.h: Include assuan.h. (enum daemon_type): New. (opt): Replace scdaemon_program by daemon_program array. Replace scd_local by a array d_local. Change users accordingly. -- The model I'm using for a TPM daemon is the current scdaemon. That includes start and stop handlers plus liveness checks and an assuan socket generator. To avoid massive code duplication (and save me a lot of effort), I've elected to strip this code out of call-scd.c into a generic framework which can then be reused as is by the TPM handling daemon. Signed-off-by: James Bottomley <[email protected]> Co-authored-by: Werner Koch <[email protected]> Modified original patch for 2.2 heavily to fit the new framework used in master (gnupg 2.3) Signed-off-by: Werner Koch <[email protected]>
2020-06-05agent,ssh: Tighten condition for EdDSA.NIIBE Yutaka1-2/+1
* agent/command-ssh.c (ssh_key_to_blob): Prepare for non-prefixed point representation of EdDSA. Signed-off-by: NIIBE Yutaka <[email protected]>
2020-06-05agent: Remove duplicated code for EdDSA.NIIBE Yutaka1-30/+10
* agent/command-ssh.c (ssh_receive_key): Curve is "Ed25519". Use sexp_key_construct always. Signed-off-by: NIIBE Yutaka <[email protected]>
2020-05-18agent: Allow to use SETHASH for arbitrary data.Werner Koch1-0/+2
* agent/agent.h (struct server_control_s): Add field digest.data. * agent/gpg-agent.c (agent_deinit_default_ctrl): Free that field. * agent/command.c (reset_notify): Ditto. (start_command_handler): ditto. (cmd_sethash): Add new option --inquire. * agent/call-scd.c (agent_card_pksign): For now return an error if inquire mode was used. * agent/command-ssh.c (ssh_handler_sign_request): Make sure digest.data is cleared. * agent/divert-scd.c (divert_pksign): Implement inquire mode. * agent/pksign.c (agent_pksign_do): Ditto. -- This is required to support EdDSA according to RFC8410. GnuPG-bug-id: 4888
2020-02-18Spelling cleanup.Daniel Kahn Gillmor1-1/+1
No functional changes, just fixing minor spelling issues. --- Most of these were identified from the command line by running: codespell \ --ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \ --skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \ doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \ NEWS README README.maint TODO Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2020-02-13agent: Allow signing with card key even without a stub key.Werner Koch1-1/+1
* agent/call-scd.c (agent_card_serialno): Allow NULL for R_SERIAL. (struct readkey_status_parm_s): New. (readkey_status_cb): New. (agent_card_readkey): Add optional arg R_KEYREF and change all callers. * agent/findkey.c (key_parms_from_sexp): Allow also a "public-key". * agent/divert-scd.c (ask_for_card): Allow for SHADOW_INFO being NULL. * agent/pksign.c (agent_pksign_do): Fallback to sign with an on-card if there is no stub key yet. Create the stub key. Also fixed a misnaming between s_pkey and s_skey. -- This change allows to create OpenPGP keys directly from a card without first making sure that a stub key exists. It is also the less surprising behaviour. Signed-off-by: Werner Koch <[email protected]>
2020-01-13agent: handle SSH operation by KEYGRIP.NIIBE Yutaka1-86/+15
* agent/command-ssh.c (card_key_available): Supply KEYINFO argument. Call agent_card_readkey by KEYGRIP of KEYINFO. Don't use $AUTHKEYID, but IDSTR of KEYINFO. (ssh_handler_request_identities): Follow the change of card_key_available. Signed-off-by: NIIBE Yutaka <[email protected]>
2020-01-09agent: SSH: SCD KEYINFO to list available keys.NIIBE Yutaka1-36/+21
* agent/agent.h (agent_card_cardlist): Remove. (agent_card_keyinfo): Add CAP argument. * agent/call-scd.c (card_cardlist_cb): Remove. (agent_card_cardlist): Remove. (agent_card_keyinfo): Support CAP constraint. * agent/command-ssh.c (card_key_list): Remove. (ssh_handler_request_identities): Use SCD KEYINFO command. * agent/command.c (cmd_keyinfo): Follow the API change. * agent/divert-scd.c (ask_for_card): Likewise. Signed-off-by: NIIBE Yutaka <[email protected]>
2019-05-21agent: For SSH key, don't put NUL-byte at the end.NIIBE Yutaka1-2/+2
* agent/command-ssh.c (ssh_key_to_protected_buffer): Update the length by the second call of gcry_sexp_sprint. -- GnuPG-bug-id: 4502 Signed-off-by: NIIBE Yutaka <[email protected]>
2019-05-14agent: Replace most assert by log_assert.Werner Koch1-3/+2
--
2019-05-03agent: Put Token lines into the key files.Werner Koch1-1/+1
* agent/findkey.c (write_extended_private_key): Add args serialno and keyref. Write a Token line if that does not yet exist. (agent_write_private_key): Add args serialno and keyref and change all callers. (agent_write_shadow_key): Skip leading spaces. * agent/keyformat.txt: Improve extended key format docs. -- Noet that the extended key forma is the defaqult in 2.3. This patch is a first step to better handle tokens which carray the same key. Signed-off-by: Werner Koch <[email protected]>
2019-01-17ssh: Simplify the curve name lookup.Werner Koch1-84/+54
* 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 <[email protected]>
2018-10-24all: fix spelling and typosDaniel Kahn Gillmor1-1/+1
Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2018-10-24ssh: Fix possible infinite loop in case of an read error.Werner Koch1-3/+4
* agent/command-ssh.c (ssh_handler_add_identity): Handle other errors than EOF. -- GnuPG-bug-id: 4221 Signed-off-by: Werner Koch <[email protected]>
2018-10-22agent: Fix build regression for Windows.Werner Koch1-8/+10
* agent/command-ssh.c (get_client_info): Turn client_uid into an int. Fix setting of it in case of a failed getsocketopt. * agent/command.c (start_command_handler): Fix setting of the pid and uid for Windows. -- Fixes-commit: 28aa6890588cc108639951bb4bef03ac17743046 which obviously was only added to master. Signed-off-by: Werner Koch <[email protected]>
2018-04-10agent: Improve the unknown ssh flag detection.Werner Koch1-24/+31
* agent/command-ssh.c (ssh_handler_sign_request): Simplify detection of flags. -- Signed-off-by: Werner Koch <[email protected]>
2018-04-09agent: unknown flags on ssh signing requests cause an error.T3880-fixT3880Daniel Kahn Gillmor1-1/+9
* agent/command-ssh.c (ssh_handler_sign_request): if a flag is passed during an signature request that we do not know how to apply, return GPG_ERR_UNKNOWN_OPTION. -- https://tools.ietf.org/html/draft-miller-ssh-agent-02#section-4.5 says: If the agent does not support the requested flags, or is otherwise unable or unwilling to generate the signature (e.g. because it doesn't have the specified key, or the user refused confirmation of a constrained key), it must reply with a SSH_AGENT_FAILURE message. Signed-off-by: Daniel Kahn Gillmor <[email protected]> GnuPG-bug-id: 3880
2018-04-09agent: change documentation reference for ssh-agent protocol.Daniel Kahn Gillmor1-2/+4
* agent/command-ssh.c: repoint documentation reference. -- Damien Miller is now documenting the ssh-agent protocol via the IETF. Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2018-04-06agent: Support SSH signature flags.NIIBE Yutaka1-1/+16
* agent/command-ssh.c (SSH_AGENT_RSA_SHA2_256): New. (SSH_AGENT_RSA_SHA2_512): New. (ssh_handler_sign_request): Override SPEC when FLAGS is specified. -- GnuPG-bug-id: 3880 Reported-by: Daniel Kahn Gillmor <[email protected]> Signed-off-by: NIIBE Yutaka <[email protected]>
2018-03-27agent: Make the request origin a part of the cache items.Werner Koch1-1/+1
* agent/cache.c (agent_put_cache): Add arg 'ctrl' and change all callers to pass it. (agent_get_cache): Ditto. * agent/cache.c (struct cache_items_s): Add field 'restricted'. (housekeeping): Adjust debug output. (agent_flush_cache): Ditto. (agent_put_cache): Ditto. Take RESTRICTED into account. (agent_get_cache): Ditto. -- If requests are coming from different sources they should not share the same cache. This way we make sure that a Pinentry pops up for a remote request to a key we have already used locally. GnuPG-bug-id: 3858 Signed-off-by: Werner Koch <[email protected]>
2018-01-26agent: Fix sending connecting process uid to pinentry.NIIBE Yutaka1-1/+9
* agent/command-ssh.c (get_client_info): Use LOCAL_PEERCRED. -- LOCAL_PEERUID was wrong (while there is LOCAL_PEERUUID). For FreeBSD and macOS, we can use LOCAL_PEERCRED to get uid. GnuPG-bug-id: 3757 Fixes-commit: 28aa6890588cc108639951bb4bef03ac17743046 Signed-off-by: NIIBE Yutaka <[email protected]>