/
main_linux.go
79 lines (71 loc) · 2.09 KB
/
main_linux.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"crypto/rand"
"encoding/binary"
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"golang.org/x/crypto/scrypt"
)
func main() {
stateFile := flag.String("state-file", "", "File in which to save persistent state")
pandaScrypt := flag.Bool("panda-scrypt", false, "Run in subprocess mode to process passphrase")
cliFlag := flag.Bool("cli", false, "If true, the CLI will be used, even if the GUI is available")
devFlag := flag.Bool("dev", false, "Is this a development environment?")
flag.Parse()
if *pandaScrypt {
var numBytes uint32
if err := binary.Read(os.Stdin, binary.LittleEndian, &numBytes); err != nil {
panic(err)
}
if numBytes > 1024*1024 {
panic("passphrase too large")
}
passphrase := make([]byte, int(numBytes))
if _, err := os.Stdin.Read(passphrase); err != nil {
panic(err)
}
data, err := scrypt.Key(passphrase, nil, 1<<17, 16, 4, 32*3)
if err != nil {
panic(err)
}
os.Stdout.Write(data)
os.Exit(0)
}
dev := os.Getenv("POND") == "dev" || *devFlag
runtime.GOMAXPROCS(4)
if len(*stateFile) == 0 && dev {
*stateFile = "state"
}
if len(*stateFile) == 0 {
home := os.Getenv("HOME")
if len(home) == 0 {
fmt.Fprintf(os.Stderr, "$HOME not set. Please either export $HOME or use --state-file to set the location of the state file explicitly.\n")
os.Exit(1)
}
persistentDir := filepath.Join(home, "Persistent")
if stat, err := os.Lstat(persistentDir); err == nil && stat.IsDir() {
// Looks like Tails.
*stateFile = filepath.Join(persistentDir, ".pond")
} else {
configDir := filepath.Join(home, ".config")
os.Mkdir(configDir, 0700)
*stateFile = filepath.Join(configDir, "pond")
}
}
if !haveGUI || *cliFlag || len(os.Getenv("PONDCLI")) > 0 {
client := NewCLIClient(*stateFile, rand.Reader, false /* testing */, true /* autoFetch */)
client.disableV2Ratchet = true
client.dev = dev
client.Start()
} else {
ui := NewGTKUI()
client := NewGUIClient(*stateFile, ui, rand.Reader, false /* testing */, true /* autoFetch */)
client.disableV2Ratchet = true
client.dev = dev
client.Start()
ui.Run()
}
}