forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes a number of issue around GPG, improves the GPG binary detection and covers some windows cases. Fixes #5 Fixes gopasspw#334 Fixes gopasspw#418
- Loading branch information
1 parent
a67f26f
commit f98eef3
Showing
17 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// +build !windows | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
|
||
"github.com/blang/semver" | ||
) | ||
|
||
func (g *GPG) detectBinary(bin string) error { | ||
for _, b := range []string{bin, "gpg", "gpg2", "gpg1", "gpg"} { | ||
if p, err := exec.LookPath(b); err == nil { | ||
g.binary = p | ||
// if we found a GPG 2.x binary we're good, otherwise we try the | ||
// others as well | ||
if g.Version(context.Background()).GTE(semver.Version{Major: 2}) { | ||
break | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gpg | ||
package cli | ||
|
||
import "testing" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// +build windows | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"path/filepath" | ||
|
||
"github.com/justwatchcom/gopass/utils/fsutil" | ||
|
||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
func (g *GPG) detectBinary(bin string) error { | ||
// set default | ||
g.binary = "gpg.exe" | ||
|
||
// try to detect location | ||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\GnuPG`, registry.QUERY_VALUE|registry.WOW64_32KEY) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v, _, err := k.GetStringValue("Install Directory") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// gpg.exe for GPG4Win 3.0.0; would be gpg2.exe for 2.x | ||
for _, b := range []string{bin, "gpg.exe", "gpg2.exe"} { | ||
gpgPath := filepath.Join(v, "bin", b) | ||
if fsutil.IsFile(gpgPath) { | ||
g.binary = gpgPath | ||
return nil | ||
} | ||
} | ||
return errors.New("gpg.exe not found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gpg | ||
package cli | ||
|
||
import ( | ||
"bufio" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build !windows | ||
|
||
package gpg | ||
package cli | ||
|
||
import "syscall" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build windows | ||
|
||
package gpg | ||
package cli | ||
|
||
func umask(mask int) int { | ||
return -1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gpg | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build !windows | ||
|
||
package sub | ||
|
||
import "context" | ||
|
||
func (s *Store) gitFixConfigOSDep(ctx context.Context) error { | ||
// nothing to do | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// +build windows | ||
|
||
package sub | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func (s *Store) gitFixConfigOSDep(ctx context.Context) error { | ||
if err := s.gitCmd(ctx, "gitFixConfigOSDep", "config", "--local", "gpg.program", "TODO"); err != nil { | ||
return errors.Wrapf(err, "failed to set git config gpg.program") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters