-
Notifications
You must be signed in to change notification settings - Fork 43
/
entry.go
291 lines (258 loc) · 7.7 KB
/
entry.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package ipsec
import (
"encoding/xml"
"github.com/PaloAltoNetworks/pango/util"
)
const (
ProtocolEsp = "esp"
ProtocolAh = "ah"
)
const (
EncryptionDes = "des"
Encryption3des = "3des"
EncryptionAes128 = "aes-128-cbc"
EncryptionAes192 = "aes-192-cbc"
EncryptionAes256 = "aes-256-cbc"
EncryptionAes128Gcm = "aes-128-gcm"
EncryptionAes256Gcm = "aes-256-gcm"
EncryptionNull = "null"
)
const (
TimeSeconds = "seconds"
TimeMinutes = "minutes"
TimeHours = "hours"
TimeDays = "days"
)
const (
SizeKb = "kb"
SizeMb = "mb"
SizeGb = "gb"
SizeTb = "tb"
)
// Entry is a normalized, version independent representation of an interface
// management profile.
type Entry struct {
Name string
Protocol string
Encryption []string
Authentication []string
DhGroup string
LifetimeType string
LifetimeValue int
LifesizeType string
LifesizeValue int
}
// Copy copies the information from source Entry `s` to this object. As the
// Name field relates to the XPATH of this object, this field is not copied.
func (o *Entry) Copy(s Entry) {
o.Protocol = s.Protocol
o.Encryption = s.Encryption
o.Authentication = s.Authentication
o.DhGroup = s.DhGroup
o.LifetimeType = s.LifetimeType
o.LifetimeValue = s.LifetimeValue
o.LifesizeType = s.LifesizeType
o.LifesizeValue = s.LifesizeValue
}
// SpecifyEncryption takes normalizes encryption values and changes them to the
// version specific values PAN-OS will be expecting.
//
// Param v should be 1 if you're running against PAN-OS 6.1; 2 if you're
// running against 7.0 or later.
func (o *Entry) SpecifyEncryption(v int) {
if len(o.Encryption) == 0 {
return
}
nv := make([]string, len(o.Encryption))
switch v {
case 2:
for i := range o.Encryption {
switch o.Encryption[i] {
case EncryptionDes:
nv[i] = "des"
case Encryption3des:
nv[i] = "3des"
case EncryptionAes128:
nv[i] = "aes-128-cbc"
case EncryptionAes192:
nv[i] = "aes-192-cbc"
case EncryptionAes256:
nv[i] = "aes-256-cbc"
case EncryptionAes128Gcm:
nv[i] = "aes-128-gcm"
case EncryptionAes256Gcm:
nv[i] = "aes-256-gcm"
case EncryptionNull:
nv[i] = "null"
default:
nv[i] = o.Encryption[i]
}
}
case 1:
for i := range o.Encryption {
switch o.Encryption[i] {
case Encryption3des:
nv[i] = "3des"
case EncryptionAes128:
nv[i] = "aes128"
case EncryptionAes192:
nv[i] = "aes192"
case EncryptionAes256:
nv[i] = "aes256"
case EncryptionNull:
nv[i] = "null"
default:
nv[i] = o.Encryption[i]
}
}
default:
copy(nv, o.Encryption)
}
o.Encryption = nv
}
// NormalizeEncryption normalizes the fields in o.Encryption.
func (o *Entry) NormalizeEncryption() {
if len(o.Encryption) == 0 {
return
}
nv := make([]string, len(o.Encryption))
for i := range o.Encryption {
switch o.Encryption[i] {
case "des":
nv[i] = EncryptionDes
case "3des":
nv[i] = Encryption3des
case "aes-128-cbc", "aes128":
nv[i] = EncryptionAes128
case "aes-192-cbc", "aes192":
nv[i] = EncryptionAes192
case "aes-256-cbc", "aes256":
nv[i] = EncryptionAes256
case "aes-128-gcm":
nv[i] = EncryptionAes128Gcm
case "aes-256-gcm":
nv[i] = EncryptionAes256Gcm
case "null":
nv[i] = EncryptionNull
default:
nv[i] = o.Encryption[i]
}
}
o.Encryption = nv
}
/** Structs / functions for this namespace. **/
type normalizer interface {
Normalize() Entry
}
type container_v1 struct {
Answer entry_v1 `xml:"result>entry"`
}
func (o *container_v1) Normalize() Entry {
ans := Entry{
Name: o.Answer.Name,
DhGroup: o.Answer.DhGroup,
}
if o.Answer.Esp != nil {
ans.Protocol = ProtocolEsp
ans.Encryption = util.MemToStr(o.Answer.Esp.Encryption)
ans.Authentication = util.MemToStr(o.Answer.Esp.Authentication)
} else if o.Answer.Ah != nil {
ans.Protocol = ProtocolAh
ans.Authentication = util.MemToStr(o.Answer.Ah.Authentication)
}
if o.Answer.Lifetime != nil {
if o.Answer.Lifetime.Seconds != 0 {
ans.LifetimeType = TimeSeconds
ans.LifetimeValue = o.Answer.Lifetime.Seconds
} else if o.Answer.Lifetime.Minutes != 0 {
ans.LifetimeType = TimeMinutes
ans.LifetimeValue = o.Answer.Lifetime.Minutes
} else if o.Answer.Lifetime.Hours != 0 {
ans.LifetimeType = TimeHours
ans.LifetimeValue = o.Answer.Lifetime.Hours
} else if o.Answer.Lifetime.Days != 0 {
ans.LifetimeType = TimeDays
ans.LifetimeValue = o.Answer.Lifetime.Days
}
}
if o.Answer.Lifesize != nil {
if o.Answer.Lifesize.Kb != 0 {
ans.LifesizeType = SizeKb
ans.LifesizeValue = o.Answer.Lifesize.Kb
} else if o.Answer.Lifesize.Mb != 0 {
ans.LifesizeType = SizeMb
ans.LifesizeValue = o.Answer.Lifesize.Mb
} else if o.Answer.Lifesize.Gb != 0 {
ans.LifesizeType = SizeGb
ans.LifesizeValue = o.Answer.Lifesize.Gb
} else if o.Answer.Lifesize.Tb != 0 {
ans.LifesizeType = SizeTb
ans.LifesizeValue = o.Answer.Lifesize.Tb
}
}
return ans
}
type entry_v1 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Esp *espType `xml:"esp"`
Ah *ahType `xml:"ah"`
DhGroup string `xml:"dh-group,omitempty"`
Lifetime *lifetimeType `xml:"lifetime"`
Lifesize *lifesizeType `xml:"lifesize"`
}
type espType struct {
Encryption *util.MemberType `xml:"encryption"`
Authentication *util.MemberType `xml:"authentication"`
}
type ahType struct {
Authentication *util.MemberType `xml:"authentication"`
}
type lifetimeType struct {
Seconds int `xml:"seconds,omitempty"`
Minutes int `xml:"minutes,omitempty"`
Hours int `xml:"hours,omitempty"`
Days int `xml:"days,omitempty"`
}
type lifesizeType struct {
Kb int `xml:"kb,omitempty"`
Mb int `xml:"mb,omitempty"`
Gb int `xml:"gb,omitempty"`
Tb int `xml:"tb,omitempty"`
}
func specify_v1(e Entry) interface{} {
ans := entry_v1{
Name: e.Name,
DhGroup: e.DhGroup,
}
switch e.Protocol {
case ProtocolEsp:
ans.Esp = &espType{
Encryption: util.StrToMem(e.Encryption),
Authentication: util.StrToMem(e.Authentication),
}
case ProtocolAh:
ans.Ah = &ahType{util.StrToMem(e.Authentication)}
}
switch e.LifetimeType {
case TimeSeconds:
ans.Lifetime = &lifetimeType{Seconds: e.LifetimeValue}
case TimeMinutes:
ans.Lifetime = &lifetimeType{Minutes: e.LifetimeValue}
case TimeHours:
ans.Lifetime = &lifetimeType{Hours: e.LifetimeValue}
case TimeDays:
ans.Lifetime = &lifetimeType{Days: e.LifetimeValue}
}
switch e.LifesizeType {
case SizeKb:
ans.Lifesize = &lifesizeType{Kb: e.LifesizeValue}
case SizeMb:
ans.Lifesize = &lifesizeType{Mb: e.LifesizeValue}
case SizeGb:
ans.Lifesize = &lifesizeType{Gb: e.LifesizeValue}
case SizeTb:
ans.Lifesize = &lifesizeType{Tb: e.LifesizeValue}
}
return ans
}