-
Notifications
You must be signed in to change notification settings - Fork 46
/
interlock.go
113 lines (85 loc) · 2.28 KB
/
interlock.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// INTERLOCK | https://github.com/usbarmory/interlock
// Copyright (c) WithSecure Corporation
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
// +build linux
package main
import (
"flag"
"log"
"os"
"github.com/usbarmory/interlock/internal"
)
func init() {
log.SetOutput(os.Stdout)
}
func main() {
var op string
conf := interlock.GetConfig()
conf.SetDefaults()
flag.BoolVar(&conf.Debug, "d", false, "debug mode")
flag.BoolVar(&conf.TestMode, "t", false, "test mode (WARNING: disables authentication)")
flag.StringVar(&conf.BindAddress, "b", interlock.BindAddress, "binding address:port pair")
flag.StringVar(&op, "o", "", "operation ((open:<volume>)|close|derive:<data>)")
var configPath = flag.String("c", "interlock.conf", "configuration file path")
// Ensure that no temporary file from Go internal functions end up in
// unencrypted space (relevant only after luksMount() but applied
// ASAP).
os.Setenv("TMPDIR", conf.MountPoint)
flag.Parse()
if op == "" {
if os.Geteuid() == 0 {
log.Fatal("Please do not run this application with administrative privileges")
}
if conf.TestMode {
log.Println("*** WARNING *** authentication disabled (test mode switch enabled)")
}
log.SetFlags(log.Ldate | log.Ltime)
if interlock.Revision == "" && interlock.Build == "" {
log.Printf("starting INTERLOCK\n")
} else {
log.Printf("starting INTERLOCK %s - %s\n", interlock.Revision, interlock.Build)
}
} else {
log.SetFlags(0)
}
if *configPath != "" {
err := conf.Set(*configPath)
if err != nil {
log.Fatal(err)
}
if op == "" {
log.Printf("configuration file %s successfully parsed", *configPath)
}
}
if err := conf.SetMountPoint(); err != nil {
log.Fatal(err)
}
if err := conf.EnableCiphers(); err != nil {
log.Fatal(err)
}
if err := conf.EnableHSM(); err != nil {
log.Fatal(err)
}
if op != "" {
if err := interlock.Op(op); err != nil {
log.Fatal(err)
}
return
}
conf.Print()
if conf.Debug {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.Println("debug mode enabled")
} else {
interlock.EnableSyslog()
}
srv, err := interlock.ConfigureServer()
if err != nil {
log.Fatal(err)
}
if err := interlock.StartServer(srv); err != nil {
log.Fatal(err)
}
}