Skip to content

Commit

Permalink
specify ssh dir
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Lau <[email protected]>
  • Loading branch information
JoelLau committed Oct 30, 2024
1 parent 6ecca43 commit a3e6156
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions internal/backend/crypto/age/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er
return sshCache, nil
}

// notice that this respects the GOPASS_HOMEDIR env variable, and won't
// find a .ssh folder in your home directory if you set GOPASS_HOMEDIR
uhd := appdir.UserHome()
sshDir := filepath.Join(uhd, ".ssh")
if !fsutil.IsDir(sshDir) {
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)
sshDir, err := getSSHDir()
if err != nil {
debug.Log("asdf: %s", err)

return nil, fmt.Errorf("no identities found: %w", ErrNoSSHDir)
return nil, fmt.Errorf("asdf: %w", err)
}

files, err := os.ReadDir(sshDir)
Expand Down Expand Up @@ -69,6 +66,31 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er
return ids, nil
}

func getSSHDir() (string, error) {
preferredPath := os.Getenv("GOPASS_SSHDIR")
if preferredPath != "" {
return preferredPath, nil
}
sshDir := filepath.Join(preferredPath, ".ssh")
if !fsutil.IsDir(sshDir) {
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)

return "", fmt.Errorf("no identities found: %w", ErrNoSSHDir)
}

// notice that this respects the GOPASS_HOMEDIR env variable, and won't
// find a .ssh folder in your home directory if you set GOPASS_HOMEDIR
uhd := appdir.UserHome()
sshDir = filepath.Join(uhd, ".ssh")
if !fsutil.IsDir(sshDir) {
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)

return "", fmt.Errorf("no identities found: %w", ErrNoSSHDir)
}

return "", nil
}

// parseSSHIdentity parses a SSH public key file and returns the recipient and the identity.
func (a *Age) parseSSHIdentity(ctx context.Context, pubFn string) (string, age.Identity, error) {
privFn := strings.TrimSuffix(pubFn, ".pub")
Expand Down

0 comments on commit a3e6156

Please sign in to comment.