Bug 2564

Summary: ssh_config AddKeysToAgent doesn't set key name/path
Product: Portable OpenSSH Reporter: alves.rjc
Component: sshAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: enhancement CC: djm, git
Priority: P5    
Version: 7.2p1   
Hardware: Other   
OS: Linux   
Bug Depends on:    
Bug Blocks: 3079    
Attachments:
Description Flags
probable fix
none
AddKeysToAgent: Use filename when comment is empty none

Description alves.rjc 2016-04-18 02:05:42 AEST
Hi everyone,

This request is a small enhancement to the feature introduced in https://bugzilla.mindrot.org/show_bug.cgi?id=1699 to include the name or path of/to the ssh key.

Currently if a key is added automatically by having the option AddKeysToAgent enabled the name/path to the key is not included.
This contrasts with keys added manually via ssh-add which include this information. So when using "ssh-add -l" the following is seen:

  2048 SHA256:aF4h47lpohn7aXTMtlWFMfEXWtT7zN1CMh2M/NGXgTM  (RSA)
  2048 SHA256:ihNn8ml5z5rLXULYnXibgBSSZ7PiHVXzgCQywXqGi6I .ssh/test (RSA)

The first line was added automatically by use of AddKeysToAgent. The second was added by calling "ssh-add .ssh/test".

The missing information could come from the "IdentityFile" in ssh_config or the "-i" parameter if specified in the command line.

Having the name of the key is useful to know which keys are currently loaded on the agent.

Thanks,
Renato
Comment 1 Damien Miller 2016-10-28 15:13:25 AEDT
Created attachment 2885 [details]
probable fix

Could you please try this patch?
Comment 2 alves.rjc 2016-10-29 11:06:35 AEDT
Hi Damien,

The patch doesn't seem to affect anything.
I get exactly the same output as before in both situations.
Comment 3 Vincent Brillault 2016-11-23 09:30:29 AEDT
Created attachment 2894 [details]
AddKeysToAgent: Use filename when comment is empty

I took a look at this bug by chance and I think I found the 'issue':
ssh-add has a check verifying if the 'comment' of the key is NULL or contains only '\0' and replace it with the filename in that case (see https://github.com/openssh/openssh-portable/blob/master/ssh-add.c#L261-L262, seems to have been added in https://github.com/openssh/openssh-portable/commit/2681cdb6e0de7c1af549dac37a9531af202b4434)

The attached patch simply duplicate that behaviour (looking at sshkey_parse_private_fileblob_type, RSA key always have a 'NULL' comment).
It seems to fix the issue for me, can you confirm?
Comment 4 alves.rjc 2016-11-23 11:18:01 AEDT
(In reply to Vincent Brillault from comment #3)
> Created attachment 2894 [details]

You have a small typo (dupplicate) in the commit message, otherwise the patch works great and fixes the issue.

Can we get it reviewed and merged?

Thanks,
Renato
Comment 5 Damien Miller 2020-01-25 18:17:25 AEDT
A similar fix has been committed and will be in OpenSSH 8.2
Comment 6 Damien Miller 2021-04-23 15:08:16 AEST
closing resolved bugs as of 8.6p1 release