From 2f5817c258b6fa48d7933de0508e3c8b90e80e68 Mon Sep 17 00:00:00 2001 From: mikhailde Date: Mon, 14 Oct 2024 17:16:31 +0300 Subject: [PATCH] Fix: Support all SSH private key formats in ssh-agent plugin The previous implementation only supported OpenSSH private keys, which start with "-----BEGIN OPENSSH PRIVATE KEY-----". This commit improves the plugin to support all valid private key formats by using the 'file' command to identify them based on their content. This change ensures that the ssh-agent plugin can handle keys in various formats, including PKCS#1, PKCS#8, and OpenSSH. --- plugins/ssh-agent/ssh-agent.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index becd5ea17..acf56cc35 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -44,8 +44,8 @@ function _add_identities() { if [[ ${#identities[@]} -eq 0 ]]; then # Iterate over files in .ssh folder. for file in "$HOME/.ssh"/*; do - # Check if file is a regular file and starts with "-----BEGIN OPENSSH PRIVATE KEY-----". - if [[ -f "$file" && $(command head -n 1 "$file") =~ ^-----BEGIN\ OPENSSH\ PRIVATE\ KEY----- ]]; then + # Check if file is a valid private key using file magic. + if [[ -f "$file" && $(file -b "$file") == *"private key"* ]]; then # Add filename (without path) to identities array. identities+=("${file##*/}") fi