-
Notifications
You must be signed in to change notification settings - Fork 2
/
ta.go
64 lines (48 loc) · 1.06 KB
/
ta.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
package openssl
import (
"io/ioutil"
"os/exec"
log "github.com/cihub/seelog"
)
type TA struct {
path string
content []byte
}
func (o *Openssl) LoadOrCreateTA(filename string) (*TA, error) {
ta, err := o.LoadTA(filename)
if err != nil {
return o.CreateTA(filename)
}
return ta, nil
}
func (o *Openssl) LoadTA(filename string) (*TA, error) {
filename = o.Path + "/" + filename
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
ta := &TA{}
ta.path = filename
ta.content = content
return ta, nil
}
func (o *Openssl) CreateTA(filename string) (*TA, error) {
var err error
filename = o.Path + "/" + filename
log.Info("Generate TLS-Auth Key (", filename, ")")
ta := &TA{}
ta.path = filename
ta.content, err = exec.Command("openvpn", "--genkey", "--secret", "/dev/stdout").Output()
if err != nil {
log.Error(err)
return nil, err
}
err = ioutil.WriteFile(filename, ta.content, 0600)
return ta, err
}
func (ta *TA) GetFilePath() string {
return ta.path
}
func (ta *TA) String() string {
return string(ta.content)
}