-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
148 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// +build !windows | ||
|
||
package action | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
// clearClipboard will spwan a copy of gopass that waits in a detached background | ||
// process group until the timeout is expired. It will then compare the contents | ||
// of the clipboard and erase it if it still contains the data gopass copied | ||
// to it. | ||
func clearClipboard(content []byte, timeout int) error { | ||
hash := fmt.Sprintf("%x", sha256.Sum256(content)) | ||
|
||
cmd := exec.Command(os.Args[0], "unclip", "--timeout", strconv.Itoa(timeout)) | ||
// https://groups.google.com/d/msg/golang-nuts/shST-SDqIp4/za4oxEiVtI0J | ||
cmd.SysProcAttr = &syscall.SysProcAttr{ | ||
Setpgid: true, | ||
} | ||
cmd.Env = append(os.Environ(), "GOPASS_UNCLIP_CHECKSUM="+hash) | ||
return cmd.Start() | ||
} |
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,23 @@ | ||
// +build windows | ||
|
||
package action | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
) | ||
|
||
// clearClipboard will spwan a copy of gopass that waits in a detached background | ||
// process group until the timeout is expired. It will then compare the contents | ||
// of the clipboard and erase it if it still contains the data gopass copied | ||
// to it. | ||
func clearClipboard(content []byte, timeout int) error { | ||
hash := fmt.Sprintf("%x", sha256.Sum256(content)) | ||
|
||
cmd := exec.Command(os.Args[0], "unclip", "--timeout", strconv.Itoa(timeout)) | ||
cmd.Env = append(os.Environ(), "GOPASS_UNCLIP_CHECKSUM="+hash) | ||
return cmd.Start() | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !windows | ||
|
||
package fsutil | ||
|
||
import ( | ||
|
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,70 @@ | ||
// +build windows | ||
|
||
package fsutil | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// CleanPath resolves common aliases in a path and cleans it as much as possible | ||
func CleanPath(path string) string { | ||
// http://stackoverflow.com/questions/17609732/expand-tilde-to-home-directory | ||
if path[:2] == "~/" { | ||
usr, _ := user.Current() | ||
dir := usr.HomeDir | ||
path = strings.Replace(path, "~/", dir+"/", 1) | ||
} | ||
if p, err := filepath.Abs(path); err == nil { | ||
return p | ||
} | ||
return filepath.Clean(path) | ||
} | ||
|
||
// IsDir checks if a certain path exists and is a directory | ||
// https://stackoverflow.com/questions/10510691/how-to-check-whether-a-file-or-directory-denoted-by-a-path-exists-in-golang | ||
func IsDir(path string) bool { | ||
fi, err := os.Lstat(path) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
// not found | ||
return false | ||
} | ||
fmt.Printf("failed to check dir %s: %s\n", path, err) | ||
return false | ||
} | ||
if fi.Mode()&os.ModeSymlink != 0 { | ||
fmt.Printf("dir %s is a symlink. ignoring", path) | ||
return false | ||
} | ||
|
||
return fi.IsDir() | ||
} | ||
|
||
// IsFile checks if a certain path is actually a file | ||
func IsFile(path string) bool { | ||
fi, err := os.Lstat(path) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
// not found | ||
return false | ||
} | ||
fmt.Printf("failed to check dir %s: %s\n", path, err) | ||
return false | ||
} | ||
if fi.Mode()&os.ModeSymlink != 0 { | ||
fmt.Printf("dir %s is a symlink. ignoring", path) | ||
return false | ||
} | ||
|
||
return fi.Mode().IsRegular() | ||
} | ||
|
||
// Tempdir returns a temporary directory suiteable for sensitive data. On | ||
// Windows, just return empty string for ioutil.TempFile. | ||
func Tempdir() string { | ||
return "" | ||
} |
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,9 @@ | ||
// +build !windows | ||
|
||
package gpg | ||
|
||
import "syscall" | ||
|
||
func umask(mask int) int { | ||
return syscall.Umask(mask) | ||
} |
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,7 @@ | ||
// +build windows | ||
|
||
package gpg | ||
|
||
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