-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeychain.go
More file actions
33 lines (30 loc) · 1.04 KB
/
keychain.go
File metadata and controls
33 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// the idea is, that there will exist different platform dependent
// implementation of how to get a Volume's encryption password, using
// the platforms standard keychain-protocol
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
// get the Volume's encryption password from Mac OS Xs keychain, using the
// label the Volume has defined in the config file
func GetPassword_mac(label string) string {
var (
// this elaborate bash command will look up the Volume's encryption
// password via the label
// we do it via bash since the security program is build in to OS X
// and therefore doesnt add an extra dependency
bash_cmd string = fmt.Sprintf("security 2>&1 >/dev/null find-generic-password -gl '%s' |grep password|cut -d \\\" -f 2", label)
out bytes.Buffer
)
// we assume that bash has been installed to /bin/bash
// this is stupid and should be done otherwise
cmd := exec.Command("/bin/bash", "-c", bash_cmd)
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return ""
}
return strings.TrimSpace(out.String())
}