-
Notifications
You must be signed in to change notification settings - Fork 1
/
rhsa-oval.go
227 lines (215 loc) · 6.83 KB
/
rhsa-oval.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
package main
import "encoding/xml"
//import "fmt"
import "github.com/davecgh/go-spew/spew"
import "io/ioutil"
import "os"
import "regexp"
type OvalData struct {
Description string
References []string
Rights string
}
func main() {
var oval map[string]OvalData
oval = ParseOval("")
spew.Dump(oval)
oval = ParseOval("/Users/smeier/tmp/com.redhat.rhsa-all.xml2")
spew.Dump(oval)
oval = ParseOval("/Users/smeier/tmp/com.redhat.rhsa-all.xml")
spew.Dump(oval)
}
func ParseOval(file string) map[string]OvalData {
if file == "" {
return nil
}
if _, err := os.Stat(file); os.IsNotExist(err) {
return nil
}
// OvalDefinitions was generated 2019-04-24 22:06:30 by root on localhost.localdomain.
type OvalDefinitions struct {
XMLName xml.Name `xml:"oval_definitions"`
Text string `xml:",chardata"`
Xmlns string `xml:"xmlns,attr"`
Oval string `xml:"oval,attr"`
RedDef string `xml:"red-def,attr"`
UnixDef string `xml:"unix-def,attr"`
Xsi string `xml:"xsi,attr"`
SchemaLocation string `xml:"schemaLocation,attr"`
Generator struct {
Text string `xml:",chardata"`
ProductName string `xml:"product_name"`
ProductVersion string `xml:"product_version"`
SchemaVersion string `xml:"schema_version"`
Timestamp string `xml:"timestamp"`
ContentVersion string `xml:"content_version"`
} `xml:"generator"`
Definitions struct {
Text string `xml:",chardata"`
Definition []struct {
Text string `xml:",chardata"`
Class string `xml:"class,attr"`
ID string `xml:"id,attr"`
Version string `xml:"version,attr"`
Metadata struct {
Text string `xml:",chardata"`
Title string `xml:"title"`
Affected struct {
Text string `xml:",chardata"`
Family string `xml:"family,attr"`
Platform []string `xml:"platform"`
} `xml:"affected"`
Reference []struct {
Text string `xml:",chardata"`
RefID string `xml:"ref_id,attr"`
RefURL string `xml:"ref_url,attr"`
Source string `xml:"source,attr"`
} `xml:"reference"`
Description string `xml:"description"`
Advisory struct {
Text string `xml:",chardata"`
From string `xml:"from,attr"`
Severity string `xml:"severity"`
Rights string `xml:"rights"`
Issued struct {
Text string `xml:",chardata"`
Date string `xml:"date,attr"`
} `xml:"issued"`
Updated struct {
Text string `xml:",chardata"`
Date string `xml:"date,attr"`
} `xml:"updated"`
Cve []struct {
Text string `xml:",chardata"`
Href string `xml:"href,attr"`
Public string `xml:"public,attr"`
Impact string `xml:"impact,attr"`
Cwe string `xml:"cwe,attr"`
Cvss2 string `xml:"cvss2,attr"`
Cvss3 string `xml:"cvss3,attr"`
} `xml:"cve"`
Bugzilla []struct {
Text string `xml:",chardata"`
Href string `xml:"href,attr"`
ID string `xml:"id,attr"`
} `xml:"bugzilla"`
AffectedCpeList struct {
Text string `xml:",chardata"`
Cpe []string `xml:"cpe"`
} `xml:"affected_cpe_list"`
} `xml:"advisory"`
} `xml:"metadata"`
Criteria struct {
Text string `xml:",chardata"`
Operator string `xml:"operator,attr"`
Criterion []struct {
Text string `xml:",chardata"`
Comment string `xml:"comment,attr"`
TestRef string `xml:"test_ref,attr"`
} `xml:"criterion"`
Criteria []struct {
Text string `xml:",chardata"`
Operator string `xml:"operator,attr"`
Criterion []struct {
Text string `xml:",chardata"`
Comment string `xml:"comment,attr"`
TestRef string `xml:"test_ref,attr"`
} `xml:"criterion"`
Criteria []struct {
Text string `xml:",chardata"`
Operator string `xml:"operator,attr"`
Criteria []struct {
Text string `xml:",chardata"`
Operator string `xml:"operator,attr"`
Criterion []struct {
Text string `xml:",chardata"`
Comment string `xml:"comment,attr"`
TestRef string `xml:"test_ref,attr"`
} `xml:"criterion"`
} `xml:"criteria"`
Criterion []struct {
Text string `xml:",chardata"`
Comment string `xml:"comment,attr"`
TestRef string `xml:"test_ref,attr"`
} `xml:"criterion"`
} `xml:"criteria"`
} `xml:"criteria"`
} `xml:"criteria"`
} `xml:"definition"`
} `xml:"definitions"`
Tests struct {
Text string `xml:",chardata"`
RpminfoTest []struct {
Text string `xml:",chardata"`
Check string `xml:"check,attr"`
Comment string `xml:"comment,attr"`
ID string `xml:"id,attr"`
Version string `xml:"version,attr"`
Object struct {
Text string `xml:",chardata"`
ObjectRef string `xml:"object_ref,attr"`
} `xml:"object"`
State struct {
Text string `xml:",chardata"`
StateRef string `xml:"state_ref,attr"`
} `xml:"state"`
} `xml:"rpminfo_test"`
} `xml:"tests"`
Objects struct {
Text string `xml:",chardata"`
RpminfoObject []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Version string `xml:"version,attr"`
Name string `xml:"name"`
} `xml:"rpminfo_object"`
} `xml:"objects"`
States struct {
Text string `xml:",chardata"`
RpminfoState []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
AttrVersion string `xml:"version,attr"`
SignatureKeyid struct {
Text string `xml:",chardata"`
Operation string `xml:"operation,attr"`
} `xml:"signature_keyid"`
Version struct {
Text string `xml:",chardata"`
Operation string `xml:"operation,attr"`
} `xml:"version"`
Arch struct {
Text string `xml:",chardata"`
Datatype string `xml:"datatype,attr"`
Operation string `xml:"operation,attr"`
} `xml:"arch"`
Evr struct {
Text string `xml:",chardata"`
Datatype string `xml:"datatype,attr"`
Operation string `xml:"operation,attr"`
} `xml:"evr"`
} `xml:"rpminfo_state"`
} `xml:"states"`
}
var ovaldata OvalDefinitions
data, _ := ioutil.ReadFile(file)
_ = xml.Unmarshal([]byte(data), &ovaldata)
oval := make(map[string]OvalData)
for _, def := range ovaldata.Definitions.Definition {
id := def.ID
id = "CESA-" + id[len(id)-8:len(id)-4] + ":" + id[len(id)-4:]
var cves []string
for _, ref := range def.Metadata.Reference {
matched, _ := regexp.MatchString(`^CVE`, ref.RefID)
if matched {
cves = append(cves, ref.RefID)
}
}
var current = oval[id]
current.Description = def.Metadata.Description
current.Rights = def.Metadata.Advisory.Rights
current.References = cves
oval[id] = current
}
return oval
}