Class: CVESchema::CVE

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_schema/cve.rb,
lib/cve_schema/cve/id.rb,
lib/cve_schema/cve/na.rb,
lib/cve_schema/cve/credit.rb,
lib/cve_schema/cve/impact.rb,
lib/cve_schema/cve/source.rb,
lib/cve_schema/cve/vendor.rb,
lib/cve_schema/cve/affects.rb,
lib/cve_schema/cve/exploit.rb,
lib/cve_schema/cve/product.rb,
lib/cve_schema/cve/version.rb,
lib/cve_schema/cve/solution.rb,
lib/cve_schema/cve/timeline.rb,
lib/cve_schema/cve/data_meta.rb,
lib/cve_schema/cve/reference.rb,
lib/cve_schema/cve/timestamp.rb,
lib/cve_schema/cve/description.rb,
lib/cve_schema/cve/work_around.rb,
lib/cve_schema/cve/problem_type.rb,
lib/cve_schema/cve/configuration.rb,
lib/cve_schema/cve/has_lang_value.rb,
lib/cve_schema/cve/impact/cvss_v2.rb,
lib/cve_schema/cve/impact/cvss_v3.rb

Overview

Represents a "cve" JSON object.

Defined Under Namespace

Modules: HasLangValue, Timestamp Classes: Affects, Configuration, Credit, DataMeta, Description, Exploit, ID, Impact, ProblemType, Product, Reference, Solution, Source, Timeline, Vendor, Version, WorkAround

Constant Summary collapse

DATA_TYPES =
{
  'CVE' => :CVE,
  'CNA' => :CNA,
  'CVEMENTOR' => :CVEMENTOR
}
DATA_FORMAT =
{
  'MITRE' => :MITRE
}
DATA_VERSIONS =
{
  '4.0' => :"4.0"
}
NA =

The n/a constant.

'n/a'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_type:, data_format:, data_version:, data_meta:, affects: nil, configuration: [], problemtype: [], references: [], description: [], exploit: [], credit: [], impact: nil, solution: [], source: nil, work_around: [], timeline: []) ⇒ CVE

Initializes the CVE.

Parameters:

  • data_type (:CVE, :CNA, :CVEMENTOR)
  • data_format (:MITRE)
  • data_version (:"4.0")
  • data_meta (DataMeta)
  • affects (Affects, nil) (defaults to: nil)
  • configuration (Array<Configuration>) (defaults to: [])
  • ] (ArrayProblemType)

    problemtype

  • references (Array<Reference>) (defaults to: [])
  • description (Array<Description>) (defaults to: [])
  • exploit (Array<Exploit>) (defaults to: [])
  • credit (Array<Credit>) (defaults to: [])
  • impact (Array<Impact>) (defaults to: nil)
  • solution (Array<Solution>) (defaults to: [])
  • source (Source, nil) (defaults to: nil)
  • work_around (Array<WorkAround>) (defaults to: [])
  • timeline (Array<Timeline>) (defaults to: [])


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
# File 'lib/cve_schema/cve.rb', line 140

def initialize(data_type: , data_format: , data_version: , data_meta: ,
               affects: nil,
               configuration: [],
               problemtype: [],
               references: [],
               description: [],
               exploit: [],
               credit: [],
               impact: nil,
               solution: [],
               source: nil,
               work_around: [],
               timeline: []
              )
  @data_type    = data_type
  @data_format  = data_format
  @data_version = data_version

  @data_meta = data_meta
  @affects   = affects
  @configuration = configuration
  @problemtype = problemtype
  @references = references
  @description = description
  @exploit = exploit
  @credit = credit
  @impact = impact
  @solution = solution
  @source = source
  @work_around = work_around
  @timeline = timeline
end

Instance Attribute Details

#affectsAffects? (readonly)

Returns:



53
54
55
# File 'lib/cve_schema/cve.rb', line 53

def affects
  @affects
end

#configurationArray<Configuration> (readonly) Also known as: configurations

Returns:



56
57
58
# File 'lib/cve_schema/cve.rb', line 56

def configuration
  @configuration
end

#creditArray<Credit> (readonly) Also known as: credits

Returns:



80
81
82
# File 'lib/cve_schema/cve.rb', line 80

def credit
  @credit
end

#data_format:MITRE (readonly)

Returns:

  • (:MITRE)


38
39
40
# File 'lib/cve_schema/cve.rb', line 38

def data_format
  @data_format
end

#data_metaDataMeta (readonly) Also known as: metadata

Returns:



48
49
50
# File 'lib/cve_schema/cve.rb', line 48

def data_meta
  @data_meta
end

#data_type:CVE, ... (readonly)

Returns:

  • (:CVE, :CNA, :CVEMENTOR)


31
32
33
# File 'lib/cve_schema/cve.rb', line 31

def data_type
  @data_type
end

#data_version:"4.0" (readonly)

Returns:

  • (:"4.0")


45
46
47
# File 'lib/cve_schema/cve.rb', line 45

def data_version
  @data_version
end

#descriptionArray<Description> (readonly) Also known as: descriptions

Returns:



70
71
72
# File 'lib/cve_schema/cve.rb', line 70

def description
  @description
end

#exploitArray<Exploit> (readonly) Also known as: exploits

Returns:



75
76
77
# File 'lib/cve_schema/cve.rb', line 75

def exploit
  @exploit
end

#impactImpact? (readonly)

Returns:



85
86
87
# File 'lib/cve_schema/cve.rb', line 85

def impact
  @impact
end

#problemtypeProblemType (readonly) Also known as: problem_type, problem_types

Returns:



61
62
63
# File 'lib/cve_schema/cve.rb', line 61

def problemtype
  @problemtype
end

#referencesArray<Reference> (readonly)

Returns:



67
68
69
# File 'lib/cve_schema/cve.rb', line 67

def references
  @references
end

#solutionArray<Solution> (readonly) Also known as: solutions

Returns:



88
89
90
# File 'lib/cve_schema/cve.rb', line 88

def solution
  @solution
end

#sourceSource? (readonly)

Returns:



93
94
95
# File 'lib/cve_schema/cve.rb', line 93

def source
  @source
end

#timelineArray<Timeline> (readonly)

Returns:



101
102
103
# File 'lib/cve_schema/cve.rb', line 101

def timeline
  @timeline
end

#work_aroundArray<WorkAround> (readonly) Also known as: work_arounds

Returns:



96
97
98
# File 'lib/cve_schema/cve.rb', line 96

def work_around
  @work_around
end

Class Method Details

.from_json(json) ⇒ Hash{Symbol => Object}

Maps the JSON Hash into a Symbols Hash for #initialize.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The maped Symbol Hash.

Raises:

  • (MissingJSONKey)

    The "data_type", "data_format", "data_version", or "CVE_data_key" JSON keys were missing.



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
# File 'lib/cve_schema/cve.rb', line 188

def self.from_json(json)
  {
    data_type:    if (data_type = json['data_type'])
                    DATA_TYPES.fetch(data_type) do
                      raise UnknownJSONValue.new('data_type',data_type)
                    end
                  else
                    raise MissingJSONKey.new('data_type')
                  end,

    data_format:  if (data_format = json['data_format'])
                    DATA_FORMAT.fetch(data_format) do
                      raise UnknownJSONValue.new('data_format',data_format)
                    end
                  else
                    raise MissingJSONKey.new('data_format')
                  end,

    data_version: if (data_version = json['data_version'])
                    DATA_VERSIONS.fetch(data_version) do
                      raise UnknownJSONValue.new('data_version',data_version)
                    end
                  else
                    raise MissingJSONKey.new('data_version')
                  end,

    data_meta: if (cve_data_meta = json['CVE_data_meta'])
                 DataMeta.load(cve_data_meta)
               else
                 raise MissingJSONKey.new('CVE_data_meta')
               end,

    affects:   json['affects'] && Affects.load(json['affects']),
    configuration: Array(json['configuration']).map(&Configuration.method(:load)),
    problemtype: Array(json['problemtype'] && json['problemtype']['problemtype_data']).map(&ProblemType.method(:load)),

    references: Array(json['references'] && json['references']['reference_data']).map(&Reference.method(:load)),

    description: Array(json['description'] && json['description']['description_data']).map(&Description.method(:load)),

    exploit: Array(json['exploit']).map(&Exploit.method(:load)),
    credit: Array(json['credit']).map(&Credit.method(:load)),
    impact: json['impact'] && Impact.load(json['impact']),
    solution: Array(json['solution']).map(&Solution.method(:load)),
    source: json['source'] && Source.load(json['source']),
    work_around: Array(json['work_around']).map(&WorkAround.method(:load)),
    timeline: Array(json['timeline']).map(&Timeline.method(:load))
  }
end

.load(json) ⇒ self

Loads the CVE data from parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (self)

Raises:

  • (MissingJSONKey)

    The "data_type", "data_format", "data_version", or "CVE_data_key" JSON keys were missing.



252
253
254
# File 'lib/cve_schema/cve.rb', line 252

def self.load(json)
  new(**from_json(json))
end