forked from bronze1man/goStrongswanVici
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.go
76 lines (57 loc) · 1.6 KB
/
shared.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
// this file contains the functions for managing shared secrets
package goStrongswanVici
import (
"fmt"
)
type Key struct {
ID string `json:"id,omitempty"`
Typ string `json:"type"`
Data string `json:"data"`
Owners []string `json:"owners"`
}
type UnloadKeyRequest struct {
ID string `json:"id"`
}
type keyList struct {
Keys []string `json:"keys"`
}
// load a shared secret into the IKE daemon
func (c *ClientConn) LoadShared(key *Key) error {
requestMap := &map[string]interface{}{}
err := ConvertToGeneral(key, requestMap)
if err != nil {
return fmt.Errorf("error creating request: %v", err)
}
msg, err := c.Request("load-shared", *requestMap)
if msg["success"] != "yes" {
return fmt.Errorf("unsuccessful loadSharedKey: %v", msg["errmsg"])
}
return nil
}
// unload (delete) a shared secret from the IKE daemon
func (c *ClientConn) UnloadShared(key *UnloadKeyRequest) error {
requestMap := &map[string]interface{}{}
err := ConvertToGeneral(key, requestMap)
if err != nil {
return fmt.Errorf("error creating request: %v", err)
}
msg, err := c.Request("unload-shared", *requestMap)
if msg["success"] != "yes" {
return fmt.Errorf("unsuccessful loadSharedKey: %v", msg["errmsg"])
}
return nil
}
// get a the names of the shared secrets currently loaded
func (c *ClientConn) GetShared() ([]string, error) {
msg, err := c.Request("get-shared", nil)
if err != nil {
fmt.Errorf("Error making request: %v", err)
return nil, err
}
keys := &keyList{}
err = ConvertFromGeneral(msg, keys)
if err != nil {
fmt.Errorf("Error converting data: %v", err)
}
return keys.Keys, err
}