-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_cpe.go
82 lines (65 loc) · 2.88 KB
/
api_cpe.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
package schema
import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
type CpeItem struct {
Cpe Cpe `json:"cpe"`
}
// Cpe is also the unit struct for each cpe record in db
type Cpe struct {
// Id is the auto generated ID for document DB
Id *primitive.ObjectID `json:"-" bson:"_id,omitempty"`
// Name is the cpe 2.3 format of CPE, which is also the primary key in cpe collection (index)
Name string `json:"cpeName" bson:"cpeName"`
// NameID is the UUID given from NVD, mitre does not contain this field
NameID string `json:"cpeNameId" bson:"cpeNameId"`
// NameParsed is the parsed result for 'Name' which is generated by ourselves to improve search performance
NameParsed CPEParsedMap `json:"-" bson:"cpeNameParsed"`
// LastModified is the last time this CPE has been modified
// Format: 2022-08-11T15:15:10.593
// Note: mitre does not contain this field
LastModified *string `json:"lastModified" bson:"lastModified"`
// Created is the time when CPE is created
// Format: 2022-08-11T15:15:10.593
// Note: mitre does not contain this field
Created *string `json:"created" bson:"created"`
// Titles are Human readable title for CPE
Titles []Title `json:"titles,omitempty" bson:"titles"`
// References are Internet resource for CPE
References []ReferenceCpe `json:"refs,omitempty" bson:"refs"`
// Deprecated shows whether the cpe is deprecated due to other cpes
// Note: mitre does not contain this field
Deprecated bool `json:"deprecated" bson:"deprecated"`
DeprecatedBy []Deprecate `json:"deprecatedBy,omitempty" bson:"deprecatedBy"`
Deprecates []Deprecate `json:"deprecates,omitempty" bson:"deprecates"`
}
// Title is Human readable title for CPE
type Title struct {
// Title is the name of the product. E.g., McAfee e-Business Server 8.5.2, GNU Emacs 22.1
Title string `json:"title" bson:"title"`
// Lang is the language of product. E.g., en
Lang string `json:"lang" bson:"lang"`
}
// ReferenceCpe is Internet resource for CPE
type ReferenceCpe struct {
// Ref is the URL link that related to the product
Ref string `json:"ref" bson:"ref"`
// Type is the type of the reference.
// All possible value: "Advisory", "Change Log", "Product", "Project", "Vendor", "Version"
// ref. https://csrc.nist.gov/schema/nvd/api/2.0/cpe_api_json_2.0.schema
Type string `json:"type" bson:"type"`
}
type Deprecate struct {
CpeName string `json:"cpeName"`
CpeNameId string `json:"cpeNameId"`
}
// SetParsed parses the cpe to parts and store into struct, which is expected to write to database
// when -db-type=mongo to provide querying cpe with cpe match string
//
// E.g. 1, cpeNameMatchString=cpe:2.3:*:Microsoft, matches CPEs with vendor=Microsoft
// E.g. 2, cpeNameMatchString=cpe:2.3:o:microsoft:windows_10, matches CPEs with part=o, vendor=microsoft and product=windows_10
func (c *Cpe) SetParsed() {
if parsed := NewCPEParsedMap(c.Name); len(parsed) > 0 {
c.NameParsed = parsed
}
}