Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify ssh dir #2981

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/backends/age.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ $ GOPASS_AGE_PASSWORD=mypassword gopass init --crypto age <age1...>
Notice the extra space in front of the command to skip most shell's history.
You'll need to set your name and username using `git` directly if you're using it as storage backend (the default one).

You can also specify the ssh directory by setting environment variable
```
$ GOPASS_SSH_DIR=/Downloads/new_ssh_dir gopass init --crypto age <age1...>
```

## Features

* Encryption using `age` library, can be decrypted using the `age` CLI
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Some configuration options are only available through setting environment variab
| `GOPASS_NO_NOTIFY` | `bool` | Set to any non-empty value to prevent notifications |
| `GOPASS_NO_REMINDER` | `bool` | Set to any non-empty value to prevent reminders |
| `GOPASS_PW_DEFAULT_LENGTH` | `int` | Set to any integer value larger than zero to define a different default length in the `generate` command. By default the length is 24 characters. |
| `GOPASS_SSH_DIR` | `string` | Set to a filepath that contains ssh keys. Overrides default location. |
| `GOPASS_UMASK` | `octal` | Set to any valid umask to mask bits of files created by gopass |
| `GOPASS_UNCLIP_CHECKSUM` | `string` | (internal) Used between gopass and it's unclip helper. |
| `GOPASS_UNCLIP_NAME` | `string` | (internal) Used between gopass and it's unclip helper. |
Expand Down
27 changes: 21 additions & 6 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) {
sshDir, err := getSSHDir()
if err != nil {
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)

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

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

func getSSHDir() (string, error) {
preferredPath := os.Getenv("GOPASS_SSH_DIR")
sshDir := filepath.Join(preferredPath, ".ssh")
if preferredPath != "" && fsutil.IsDir(sshDir) {
return preferredPath, 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) {
return sshDir, nil
}

return "", ErrNoSSHDir
}

// 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
Loading