Skip to content

Commit

Permalink
Also check Path if GPG4Win install location is not found (gopasspw#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz authored Feb 24, 2018
1 parent 899cb6c commit 13eae4b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions backend/crypto/gpg/cli/gpg_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cli

import (
"os/exec"
"path/filepath"

"github.com/justwatchcom/gopass/utils/fsutil"
Expand All @@ -14,19 +15,27 @@ func detectBinaryCandidates(bin string) ([]string, error) {
// gpg.exe for GPG4Win 3.0.0; would be gpg2.exe for 2.x
bins := make([]string, 0, 4)

// try to detect location
// try to detect location of installed GPG4Win
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\GnuPG`, registry.QUERY_VALUE|registry.WOW64_32KEY)
if err != nil {
return bins, err
}

v, _, err := k.GetStringValue("Install Directory")
if err != nil {
return bins, err
if v, _, err := k.GetStringValue("Install Directory"); err == nil && v != "" {
for _, b := range []string{bin, "gpg2.exe", "gpg.exe"} {
gpgPath := filepath.Join(v, "bin", b)
if fsutil.IsFile(gpgPath) {
bins = append(bins, gpgPath)
}
}
}

// try to detect location for GPG installed somewhere on the PATH
for _, b := range []string{bin, "gpg2.exe", "gpg.exe"} {
gpgPath := filepath.Join(v, "bin", b)
gpgPath, err := exec.LookPath(b)
if err != nil {
continue
}
if fsutil.IsFile(gpgPath) {
bins = append(bins, gpgPath)
}
Expand Down

0 comments on commit 13eae4b

Please sign in to comment.