Skip to content

Commit

Permalink
added documentation, prefer GOPASS_SSHDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelLau committed Oct 30, 2024
1 parent 67c27fe commit 799289e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
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
23 changes: 8 additions & 15 deletions internal/backend/crypto/age/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er

sshDir, err := getSSHDir()
if err != nil {
debug.Log("asdf: %s", err)
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)

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

files, err := os.ReadDir(sshDir)
Expand Down Expand Up @@ -67,28 +67,21 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er
}

func getSSHDir() (string, error) {
preferredPath := os.Getenv("GOPASS_SSHDIR")
if preferredPath != "" {
return preferredPath, nil
}
preferredPath := os.Getenv("GOPASS_SSH_DIR")
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)
if 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) {
debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir)

return "", fmt.Errorf("no identities found: %w", ErrNoSSHDir)
if fsutil.IsDir(sshDir) {
return sshDir, nil
}

return "", nil
return "", ErrNoSSHDir
}

// parseSSHIdentity parses a SSH public key file and returns the recipient and the identity.
Expand Down

0 comments on commit 799289e

Please sign in to comment.