funtoo / keychain

keychain ssh-agent front-end
http://www.funtoo.org
GNU General Public License v2.0
762 stars 108 forks source link

Null argument causes keys not to be processed #123

Open HaleTom opened 4 years ago

HaleTom commented 4 years ago

Keychain behaves strangely when encountering a null argument.

Here, $noask is null:

% printf "%q\n" "$noask"
''
% printf "%q\n" "$keys"                                     
id_4096_jvlk.me$'\n'id_4096rsa_20kdf$'\n'id_android$'\n'id_boxy_rsa
% 
% keychain --quiet -k all; eval $(keychain --eval --confhost --quick "$noask" "$keys")

 * keychain 2.8.5 ~ http://www.funtoo.org
 * Starting ssh-agent...

%

The exact command, but with $noask not surrounded by "s:

% keychain --quiet -k all; eval $(keychain --eval --confhost --quick $noask "$keys")

 * keychain 2.8.5 ~ http://www.funtoo.org
 * Starting ssh-agent...
 * Adding 4 ssh key(s): /home/ravi/.ssh/id_4096_jvlk.me /home/ravi/.ssh/id_4096rsa_20kdf /home/ravi/.ssh/id_android /home/ravi/.ssh/id_boxy_rsa
Enter passphrase for /home/ravi/.ssh/id_4096_jvlk.me:
 * ssh-add: Identities added: /home/ravi/.ssh/id_4096_jvlk.me /home/ravi/.ssh/id_4096rsa_20kdf /home/ravi/.ssh/id_android /home/ravi/.ssh/id_boxy_rsa

%

This is the context for why I want to do this:

function keychain_load {
  noask=''; [[ ! -t 0 || ! -t 1 ]] && noask='--noask'  # Don't ask for password if either STDIN or STDOUT is !isatty
  eval $(keychain --eval --quiet --agents ssh --inherit local-once --absolute --dir "$XDG_CACHE_HOME"/keychain --confhost --quick $noask "$keys")
}
export_function keychain_load
HaleTom commented 4 years ago

Strangely, it breaks when the null argument given before the keys are listed, so this works fine:

% keychain --quiet -k all; eval $(keychain --eval --confhost --quick "$keys" "$noask" ) 

 * keychain 2.8.5 ~ http://www.funtoo.org
 * Starting ssh-agent...
 * Adding 4 ssh key(s): /home/ravi/.ssh/id_4096_jvlk.me /home/ravi/.ssh/id_4096rsa_20kdf /home/ravi/.ssh/id_android /home/ravi/.ssh/id_boxy_rsa
Enter passphrase for /home/ravi/.ssh/id_4096_jvlk.me: ^C
% 
mrl5 commented 2 years ago

hello @HaleTom - if you'd like to report a bug kindly use https://bugs.funtoo.org/

you can also reach us on Discord - for more info check https://www.funtoo.org/Welcome