Last active
September 23, 2018 08:45
-
-
Save lvillani/e4bb64d63873613bb98dcdc76ab2eb06 to your computer and use it in GitHub Desktop.
Allows you to open an Enpass 6 vault using SQLCipher's CLI tool
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
package main | |
import ( | |
"crypto/sha512" | |
"encoding/hex" | |
"fmt" | |
"log" | |
"os" | |
"os/user" | |
"strings" | |
"syscall" | |
"golang.org/x/crypto/pbkdf2" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
const ( | |
vault = "~/Library/Containers/in.sinew.Enpass6-Desktop-Beta/Data/Documents/Enpass6-Beta/Vaults/primary/vault.enpassdb" | |
iter = 100000 | |
) | |
func main() { | |
pass, err := readPassword() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
vaultPath, err := expandTilde(vault) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
salt, err := readSalt(vaultPath) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
key := pbkdf2.Key([]byte(pass), []byte(salt), iter, 32, sha512.New) | |
hexs := strings.ToUpper(hex.EncodeToString(key)) | |
fmt.Printf("PRAGMA key = \"x'%v'\";\n", hexs) | |
fmt.Println("SELECT count(*) FROM sqlite_master;") | |
} | |
func expandTilde(s string) (string, error) { | |
if strings.Index(s, "~") != 0 { | |
return s, nil | |
} | |
u, err := user.Current() | |
if err != nil { | |
return "", err | |
} | |
return strings.Replace(s, "~", u.HomeDir, 1), nil | |
} | |
func readPassword() (string, error) { | |
fmt.Print("Password: ") | |
data, err := terminal.ReadPassword(int(syscall.Stdin)) | |
if err != nil { | |
return "", err | |
} | |
fmt.Println() | |
return strings.TrimSpace(string(data)), nil | |
} | |
func readSalt(vault string) ([]byte, error) { | |
buf := make([]byte, 16) | |
f, err := os.Open(vault) | |
if err != nil { | |
return nil, err | |
} | |
defer f.Close() | |
if _, err := f.Read(buf); err != nil { | |
return nil, err | |
} | |
return buf, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment