cvss-suite 3.0.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +4 -4
  3. data/.github/workflows/rubocop.yml +3 -4
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +20 -0
  6. data/.rubocop_todo.yml +2 -2
  7. data/CHANGES.md +34 -0
  8. data/CODE_OF_CONDUCT.md +0 -5
  9. data/Gemfile +0 -6
  10. data/LICENSE.md +12 -2
  11. data/README.md +20 -11
  12. data/cvss_suite.gemspec +12 -14
  13. data/lib/cvss_suite/cvss.rb +7 -55
  14. data/lib/cvss_suite/cvss2/cvss2.rb +2 -8
  15. data/lib/cvss_suite/cvss2/cvss2_base.rb +0 -6
  16. data/lib/cvss_suite/cvss2/cvss2_environmental.rb +0 -6
  17. data/lib/cvss_suite/cvss2/cvss2_temporal.rb +0 -6
  18. data/lib/cvss_suite/cvss3/cvss3.rb +8 -8
  19. data/lib/cvss_suite/cvss3/cvss3_base.rb +8 -14
  20. data/lib/cvss_suite/cvss3/cvss3_environmental.rb +11 -17
  21. data/lib/cvss_suite/cvss3/cvss3_temporal.rb +3 -9
  22. data/lib/cvss_suite/cvss31/cvss31.rb +8 -8
  23. data/lib/cvss_suite/cvss31/cvss31_base.rb +8 -14
  24. data/lib/cvss_suite/cvss31/cvss31_environmental.rb +11 -17
  25. data/lib/cvss_suite/cvss31/cvss31_temporal.rb +3 -9
  26. data/lib/cvss_suite/cvss40/cvss40.rb +43 -0
  27. data/lib/cvss_suite/cvss40/cvss40_all_up.rb +40 -0
  28. data/lib/cvss_suite/cvss40/cvss40_base.rb +86 -0
  29. data/lib/cvss_suite/cvss40/cvss40_calc_helper.rb +397 -0
  30. data/lib/cvss_suite/cvss40/cvss40_constants_levels.rb +26 -0
  31. data/lib/cvss_suite/cvss40/cvss40_constants_macro_vector_lookup.rb +278 -0
  32. data/lib/cvss_suite/cvss40/cvss40_constants_max_composed.rb +41 -0
  33. data/lib/cvss_suite/cvss40/cvss40_constants_max_severity.rb +31 -0
  34. data/lib/cvss_suite/cvss40/cvss40_environmental.rb +105 -0
  35. data/lib/cvss_suite/cvss40/cvss40_environmental_security.rb +47 -0
  36. data/lib/cvss_suite/cvss40/cvss40_supplemental.rb +66 -0
  37. data/lib/cvss_suite/cvss40/cvss40_threat.rb +34 -0
  38. data/lib/cvss_suite/cvss_31_and_before.rb +61 -0
  39. data/lib/cvss_suite/cvss_40_and_later.rb +51 -0
  40. data/lib/cvss_suite/cvss_metric.rb +7 -7
  41. data/lib/cvss_suite/cvss_property.rb +23 -8
  42. data/lib/cvss_suite/errors.rb +0 -6
  43. data/lib/cvss_suite/helpers/cvss31_helper.rb +0 -6
  44. data/lib/cvss_suite/helpers/cvss3_helper.rb +0 -6
  45. data/lib/cvss_suite/invalid_cvss.rb +0 -6
  46. data/lib/cvss_suite/version.rb +1 -7
  47. data/lib/cvss_suite.rb +48 -11
  48. metadata +40 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b5de123089a1d8250c5fdccbf1d859a0da8be387ed88875fb88a5613a786cbb
4
- data.tar.gz: cd9150e3086e5f3304f9b4c3de53f587d25b41033218c398aa1e925385e22cee
3
+ metadata.gz: 773b87ded42d73797271e4dd4c05a261b69bc957295fe75654084f4edf4a4521
4
+ data.tar.gz: e5ecc4e25e13cc8663ca12cbb8b065246ee25b0e44fbfb6bfdbbfdb61ef16b61
5
5
  SHA512:
6
- metadata.gz: 32ef998978e20dfb978dacccfda21b587f31a63ea5426e3e0fc9a1b1c448696d27c641375cb8d35c917c19779098ce2aceca88aaa035efcda6da8d5a5c8c8860
7
- data.tar.gz: 5347e86397270b74cb5b78b5a1fc5eb7e9d9a6de13d56de62a4170c84c459406fd2cfe614434af7a83fdc434ed64ffe17de4738bb418fd4b771c01807140e1fc
6
+ metadata.gz: 3538af971b672a09547bc6f1286714876c7fe4ee61d19d4fddfaf961c42b014040cabd4259c0e22cb177064109d877a7339101ff7258afeb1b3ed937ed3cc516
7
+ data.tar.gz: 8b3ffb3367ee5437b1ee0026ca7f1677da233c844124455886c580cb2cedc5cd0b72c712a920741dc942600fc58a99c4f88f3c6c3b23ae750c962e6cc3ba1907
@@ -8,16 +8,16 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  strategy:
10
10
  matrix:
11
- ruby: [ '2.6', '2.7', '3.0', '3.1' ]
11
+ ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2', '3.3' ]
12
12
  steps:
13
- - uses: actions/checkout@v2
13
+ - uses: actions/checkout@v4
14
14
  - name: Set up ${{ matrix.ruby }}
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
18
  - name: Install gems
19
19
  run: |
20
- gem install bundler -v ">= 1.10"
21
- bundle install --jobs 4 --retry 3
20
+ gem install bundler -v "2.4.22"
21
+ bundle _2.4.22_ install --jobs 4 --retry 3
22
22
  - name: Run tests
23
23
  run: bundle exec rspec spec
@@ -8,15 +8,14 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v2
11
+ - uses: actions/checkout@v4
12
12
  - name: Set up Ruby 2.6
13
13
  uses: ruby/setup-ruby@v1
14
14
  with:
15
15
  ruby-version: 2.6
16
16
  - name: Install gems
17
17
  run: |
18
- gem update --system
19
- gem install bundler -v ">= 1.10"
20
- gem install rubocop
18
+ gem install bundler -v "2.4.22"
19
+ bundle install --jobs 4 --retry 3
21
20
  - name: Run checks
22
21
  run: rubocop -F --fail-level C -f s
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --warning
data/.rubocop.yml CHANGED
@@ -4,6 +4,10 @@ AllCops:
4
4
  TargetRubyVersion: 2.6
5
5
  SuggestExtensions: false
6
6
 
7
+ Metrics/AbcSize:
8
+ Exclude:
9
+ - 'lib/cvss_suite/cvss40/cvss40_calc_helper.rb'
10
+
7
11
  Metrics/LineLength:
8
12
  Max: 120
9
13
  Exclude:
@@ -14,17 +18,33 @@ Metrics/ClassLength:
14
18
  Exclude:
15
19
  - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
16
20
  - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
21
+ - 'lib/cvss_suite/cvss40/cvss40_calc_helper.rb'
22
+
23
+ Metrics/CyclomaticComplexity:
24
+ Exclude:
25
+ - 'lib/cvss_suite/cvss40/cvss40_calc_helper.rb'
17
26
 
18
27
  Metrics/MethodLength:
19
28
  Exclude:
20
29
  - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
21
30
  - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
31
+ - 'lib/cvss_suite/cvss40/cvss40_environmental.rb'
32
+ - 'lib/cvss_suite/cvss40/cvss40_calc_helper.rb'
33
+
34
+ Metrics/ModuleLength:
35
+ Exclude:
36
+ - 'lib/cvss_suite/cvss40/cvss40_constants_macro_vector_lookup.rb'
37
+
38
+ Metrics/PerceivedComplexity:
39
+ Exclude:
40
+ - 'lib/cvss_suite/cvss40/cvss40_calc_helper.rb'
22
41
 
23
42
  Metrics/BlockLength:
24
43
  Exclude:
25
44
  - 'spec/cvss2/cvss2_spec.rb'
26
45
  - 'spec/cvss3/cvss3_spec.rb'
27
46
  - 'spec/cvss31/cvss31_spec.rb'
47
+ - 'spec/cvss40/cvss40_spec.rb'
28
48
 
29
49
  Style/IfUnlessModifier:
30
50
  Exclude:
data/.rubocop_todo.yml CHANGED
@@ -36,7 +36,7 @@ Metrics/ClassLength:
36
36
  # Offense count: 1
37
37
  # Configuration parameters: IgnoredMethods.
38
38
  Metrics/CyclomaticComplexity:
39
- Max: 9
39
+ Max: 13
40
40
 
41
41
  # Offense count: 13
42
42
  # Configuration parameters: CountComments, ExcludedMethods.
@@ -51,7 +51,7 @@ Metrics/ParameterLists:
51
51
  # Offense count: 1
52
52
  # Configuration parameters: IgnoredMethods.
53
53
  Metrics/PerceivedComplexity:
54
- Max: 10
54
+ Max: 14
55
55
 
56
56
  # Offense count: 1
57
57
  Naming/AccessorMethodName:
data/CHANGES.md CHANGED
@@ -2,6 +2,40 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [3.2.2] - 2024-08-04
6
+
7
+ ### Fixes
8
+ * Add extra CVSS vector validations for 3.1 and lower. Fixes [#41](https://github.com/0llirocks/cvss-suite/issues/41)
9
+
10
+ ### Notes
11
+ * An invalid value like E:R (R doesn't exists) now counts as invalid, resulting in an invalid vector. In <= 3.2.1 an invalid value would be ignored/counted as default value.
12
+
13
+ ## [3.2.1] - 2024-05-25
14
+
15
+ ### Fixes
16
+ * String.truncate method in Rails gets overwritten. Fixes [#39](https://github.com/0llirocks/cvss-suite/issues/39)
17
+
18
+ ## [3.2.0] - 2024-05-04
19
+
20
+ ### Improvements
21
+ * Add support for CVSS version 4. Closes [#32](https://github.com/0llirocks/cvss-suite/issues/32). Many thanks to @brphelps for adding this feature.
22
+
23
+ ### Notes
24
+ * CVSS version 4 no longer has multiple scores, only one overall score. Keep that in mind when using CVSS version 4.
25
+
26
+ ## [3.1.1] - 2023-10-15
27
+
28
+ ### Fixes
29
+ * CVSS prefix is missing in v3.1.0. Fixes [#33](https://github.com/0llirocks/cvss-suite/issues/33)
30
+
31
+ ## [3.1.0] - 2022-09-27
32
+
33
+ ### Fixes
34
+ * Metrics are no longer order-dependent. Fixes [#30](https://github.com/0llirocks/cvss-suite/issues/30)
35
+
36
+ ### Improvements
37
+ * Temporal and Environmental metrics can now be partly omitted instead of setting them to X.
38
+
5
39
  ## [3.0.1] - 2022-03-13
6
40
 
7
41
  ### Notes
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,10 +1,5 @@
1
1
  CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
 
3
- Copyright (c) 2016-2022 Siemens AG
4
- Copyright (c) 2022 0llirocks
5
-
6
- Authors: 0llirocks <http://0lli.rocks>
7
-
8
3
  This work is licensed under the terms of the MIT license.
9
4
  See the LICENSE.md file in the top-level directory.
10
5
 
data/Gemfile CHANGED
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
data/LICENSE.md CHANGED
@@ -1,7 +1,17 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2022 Siemens AG
4
- Copyright (c) 2022 0llirocks
3
+ Copyright (c) 2016-2022 Siemens AG\
4
+ Copyright (c) 2022-2024 0llirocks
5
+
6
+ Author: 0llirocks <https://github.com/0llirocks>
7
+
8
+ Contributors:
9
+ - Florian Wininger <https://github.com/fwininger>
10
+ - Adam David <https://github.com/adamrdavid>
11
+ - Alexandre Zanni <https://github.com/noraj>
12
+ - joePedantic <https://github.com/joePedantic>
13
+ - Brandyn Phelps <https://github.com/brphelps>
14
+ - Karim ElGhandour <https://github.com/kghandour>
5
15
 
6
16
  Permission is hereby granted, free of charge, to any person obtaining a copy of
7
17
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  [![Cvss Support](https://img.shields.io/badge/CVSS-v2-brightgreen.svg)](https://www.first.org/cvss/v2/guide)
6
6
  [![Cvss Support](https://img.shields.io/badge/CVSS-v3.0-brightgreen.svg)](https://www.first.org/cvss/v3.0/user-guide)
7
7
  [![Cvss Support](https://img.shields.io/badge/CVSS-v3.1-brightgreen.svg)](https://www.first.org/cvss/v3.1/user-guide)
8
+ [![Cvss Support](https://img.shields.io/badge/CVSS-v4.0-brightgreen.svg)](https://www.first.org/cvss/v4.0/user-guide)
8
9
  [![RSpec](https://github.com/0llirocks/cvss-suite/workflows/RSpec/badge.svg)](https://github.com/0llirocks/cvss-suite/actions)
9
10
 
10
11
  This Ruby gem helps you to process the vector of the [**Common Vulnerability Scoring System**](https://www.first.org/cvss/specification-document).
@@ -18,6 +19,12 @@ Add this line to your application's Gemfile:
18
19
  gem 'cvss-suite'
19
20
  ```
20
21
 
22
+ Since the naming of this gem is not following the naming convention you can also add the following line to automatically require the gem:
23
+
24
+ ```ruby
25
+ gem 'cvss-suite', require: 'cvss_suite'
26
+ ```
27
+
21
28
  And then execute:
22
29
 
23
30
  $ bundle
@@ -39,12 +46,12 @@ If you are still using CvssSuite 1.x please refer to the [specific branch](https
39
46
  ```ruby
40
47
  require 'cvss_suite'
41
48
 
42
- cvss3 = CvssSuite.new('CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H')
49
+ cvss4 = CvssSuite.new('CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N')
43
50
 
44
- vector = cvss3.vector # 'CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H'
45
- version = cvss3.version # 3.0
46
- valid = cvss3.valid? # true
47
- severity = cvss3.severity # 'High'
51
+ vector = cvss4.vector # 'CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N'
52
+ version = cvss4.version # 4.0
53
+ valid = cvss4.valid? # true
54
+ severity = cvss4.severity # 'Critical'
48
55
 
49
56
  cvss31 = CvssSuite.new('CVSS:3.1/AV:P/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:H/E:H/RL:U/RC:U')
50
57
 
@@ -53,6 +60,13 @@ version = cvss31.version # 3.1
53
60
  valid = cvss31.valid? # true
54
61
  severity = cvss31.severity # 'Medium'
55
62
 
63
+ cvss3 = CvssSuite.new('CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H')
64
+
65
+ vector = cvss3.vector # 'CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H'
66
+ version = cvss3.version # 3.0
67
+ valid = cvss3.valid? # true
68
+ severity = cvss3.severity # 'High'
69
+
56
70
  cvss = CvssSuite.new('AV:A/AC:M/Au:S/C:P/I:P/A:P/E:POC/RL:TF/RC:UC/CDP:L/TD:M/CR:M/IR:M/AR:M')
57
71
 
58
72
  vector = cvss.vector # 'AV:A/AC:M/Au:S/C:P/I:P/A:P/E:POC/RL:TF/RC:UC/CDP:L/TD:M/CR:M/IR:M/AR:M'
@@ -61,6 +75,7 @@ valid = cvss.valid? # true
61
75
  severity = cvss.severity # 'Low'
62
76
 
63
77
  # Scores
78
+ score = cvss4.overall_score # 9.3, cvss4 only has overall score
64
79
  base_score = cvss.base_score # 4.9
65
80
  temporal_score = cvss.temporal_score # 3.6
66
81
  environmental_score = cvss.environmental_score # 3.2
@@ -100,14 +115,8 @@ valid = cvss.valid? # false
100
115
  cvss.base_score # will throw CvssSuite::Errors::InvalidVector: Vector is not valid!
101
116
  ```
102
117
 
103
- ## Notable Features
104
-
105
- Properties (Access Vector, Remediation Level, etc) do have a position attribute, with this they can be ordered the same way they appear in the vector.
106
-
107
118
  ## Known Issues
108
119
 
109
- Currently it is not possible to leave an attribute blank instead of ND/X. If you don't have a value for an attribute, please use ND/X instead.
110
-
111
120
  There is a possibility of implementations generating different scores (+/- 0,1) due to small floating-point inaccuracies. This can happen due to differences in floating point arithmetic between different languages and hardware platforms.
112
121
 
113
122
  ## Changelog
data/cvss_suite.gemspec CHANGED
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -22,15 +16,18 @@ Gem::Specification.new do |spec|
22
16
  spec.authors = ['0llirocks']
23
17
 
24
18
  spec.summary = 'Ruby gem for processing cvss vectors.'
25
- spec.description = 'This Ruby gem helps you to process the vector of the Common Vulnerability Scoring System (https://www.first.org/cvss/specification-document).
26
- Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.'
19
+ spec.description = 'This Ruby gem calculates the score based on the vector of the
20
+ Common Vulnerability Scoring System (https://www.first.org/cvss/specification-document)
21
+ in version 4.0, 3.1, 3.0 and 2.'
22
+
23
+ spec.homepage = 'https://cvss-suite.0lli.rocks'
27
24
 
28
25
  spec.metadata = {
29
- 'bug_tracker_uri' => 'https://github.com/0llirocks/cvss-suite/issues',
30
- 'changelog_uri' => 'https://github.com/0llirocks/cvss-suite/blob/master/CHANGES.md',
31
- 'documentation_uri' => 'https://www.rubydoc.info/gems/cvss-suite/' + CvssSuite::VERSION,
32
- 'homepage_uri' => 'https://cvss-suite.0lli.rocks',
33
- 'source_code_uri' => 'https://github.com/0llirocks/cvss-suite'
26
+ 'bug_tracker_uri' => 'https://github.com/0llirocks/cvss-suite/issues',
27
+ 'changelog_uri' => 'https://github.com/0llirocks/cvss-suite/blob/master/CHANGES.md',
28
+ 'documentation_uri' => "https://www.rubydoc.info/gems/cvss-suite/#{CvssSuite::VERSION}",
29
+ 'homepage_uri' => 'https://cvss-suite.0lli.rocks',
30
+ 'source_code_uri' => 'https://github.com/0llirocks/cvss-suite'
34
31
  }
35
32
 
36
33
  spec.required_ruby_version = '>= 2.6.0'
@@ -40,8 +37,9 @@ Besides calculating the Base, Temporal and Environmental Score, you are able to
40
37
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
41
38
  spec.require_paths = ['lib']
42
39
 
43
- spec.add_development_dependency 'bundler', '>= 1.10'
40
+ spec.add_development_dependency 'bundler', '2.4.22'
44
41
  spec.add_development_dependency 'rspec', '~> 3.4'
45
42
  spec.add_development_dependency 'rspec-its', '~> 1.2'
43
+ spec.add_development_dependency 'rubocop', '1.50.2'
46
44
  spec.add_development_dependency 'simplecov', '~> 0.18'
47
45
  end
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -15,11 +9,7 @@ module CvssSuite
15
9
  class Cvss
16
10
  ##
17
11
  # Metric of a CVSS vector.
18
- attr_reader :base, :temporal, :environmental
19
-
20
- ##
21
- # Returns the vector itself.
22
- attr_reader :vector
12
+ attr_reader :base
23
13
 
24
14
  ##
25
15
  # Creates a new CVSS vector by a +vector+.
@@ -34,20 +24,6 @@ module CvssSuite
34
24
  init_metrics
35
25
  end
36
26
 
37
- ##
38
- # Returns if CVSS vector is valid.
39
- def valid?
40
- if @amount_of_properties == required_amount_of_properties
41
- base = @base.valid?
42
- temporal = @base.valid? && @temporal.valid?
43
- environmental = @base.valid? && @environmental.valid?
44
- full = @base.valid? && @temporal.valid? && @environmental.valid?
45
- base || temporal || environmental || full
46
- else
47
- false
48
- end
49
- end
50
-
51
27
  ##
52
28
  # Returns the severity of the CVSS vector.
53
29
  def severity
@@ -71,53 +47,29 @@ module CvssSuite
71
47
  end
72
48
 
73
49
  ##
74
- # Returns the Overall Score of the CVSS vector.
75
- def overall_score
76
- check_validity
77
- return temporal_score if @temporal.valid? && !@environmental.valid?
78
- return environmental_score if @environmental.valid?
79
-
80
- base_score
50
+ # Returns the vector itself.
51
+ def vector
52
+ @vector.to_s
81
53
  end
82
54
 
83
55
  private
84
56
 
85
57
  def extract_metrics
86
- properties = prepared_vector.split('/')
58
+ properties = @vector.split('/')
87
59
  @amount_of_properties = properties.size
88
60
  properties.each_with_index do |property, index|
89
61
  property = property.split(':')
90
62
  @properties.push({ name: property[0], selected: property[1], position: index })
91
63
  end
64
+ @properties = [] if @properties.group_by { |p| p[:name] }.select { |_k, v| v.size > 1 }.length.positive?
92
65
  end
93
66
 
94
67
  def check_validity
95
68
  raise CvssSuite::Errors::InvalidVector, 'Vector is not valid!' unless valid?
96
69
  end
97
70
 
98
- def prepared_vector
99
- start_of_vector = @vector.index('AV')
100
-
101
- if start_of_vector.nil?
102
- ''
103
- elsif start_of_vector == 1
104
- match_array = @vector.scan(/\((?>[^)(]+|\g<0>)*\)/)
105
- if match_array.length == 1 && match_array[0] == @vector
106
- @vector.slice!(0)
107
- @vector.slice!(@vector.length - 1)
108
- @vector
109
- else
110
- ''
111
- end
112
- else
113
- @vector[start_of_vector..]
114
- end
115
- end
116
-
117
71
  def required_amount_of_properties
118
- total = @base.count if @base.valid?
119
- total += @temporal.count if @temporal.valid?
120
- total += @environmental.count if @environmental.valid?
72
+ total = @base.count
121
73
  total || 0
122
74
  end
123
75
  end
@@ -1,15 +1,9 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
12
- require_relative '../cvss'
6
+ require_relative '../cvss_31_and_before'
13
7
  require_relative 'cvss2_base'
14
8
  require_relative 'cvss2_temporal'
15
9
  require_relative 'cvss2_environmental'
@@ -17,7 +11,7 @@ require_relative 'cvss2_environmental'
17
11
  module CvssSuite
18
12
  ##
19
13
  # This class represents a CVSS vector in version 2.
20
- class Cvss2 < Cvss
14
+ class Cvss2 < Cvss31AndBefore
21
15
  ##
22
16
  # Returns the Version of the CVSS vector.
23
17
  def version
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -1,15 +1,9 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
12
- require_relative '../cvss'
6
+ require_relative '../cvss_31_and_before'
13
7
  require_relative 'cvss3_base'
14
8
  require_relative 'cvss3_temporal'
15
9
  require_relative 'cvss3_environmental'
@@ -17,7 +11,7 @@ require_relative 'cvss3_environmental'
17
11
  module CvssSuite
18
12
  ##
19
13
  # This class represents a CVSS vector in version 3.0.
20
- class Cvss3 < Cvss
14
+ class Cvss3 < Cvss31AndBefore
21
15
  ##
22
16
  # Returns the Version of the CVSS vector.
23
17
  def version
@@ -45,6 +39,12 @@ module CvssSuite
45
39
  Cvss3Helper.round_up(@environmental.score(@base, @temporal))
46
40
  end
47
41
 
42
+ ##
43
+ # Returns the vector itself.
44
+ def vector
45
+ "#{CvssSuite::CVSS_VECTOR_BEGINNINGS.find { |beginning| beginning[:version] == version }[:string]}#{@vector}"
46
+ end
47
+
48
48
  private
49
49
 
50
50
  def init_metrics
@@ -1,11 +1,5 @@
1
1
  # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
2
  #
3
- # Copyright (c) 2016-2022 Siemens AG
4
- # Copyright (c) 2022 0llirocks
5
- #
6
- # Authors:
7
- # 0llirocks <http://0lli.rocks>
8
- #
9
3
  # This work is licensed under the terms of the MIT license.
10
4
  # See the LICENSE.md file in the top-level directory.
11
5
 
@@ -51,40 +45,40 @@ module CvssSuite
51
45
 
52
46
  def init_properties
53
47
  @properties.push(@attack_vector =
54
- CvssProperty.new(name: 'Attack Vector', abbreviation: 'AV', position: [0],
48
+ CvssProperty.new(name: 'Attack Vector', abbreviation: 'AV',
55
49
  values: [{ name: 'Network', abbreviation: 'N', weight: 0.85 },
56
50
  { name: 'Adjacent', abbreviation: 'A', weight: 0.62 },
57
51
  { name: 'Local', abbreviation: 'L', weight: 0.55 },
58
52
  { name: 'Physical', abbreviation: 'P', weight: 0.2 }]))
59
53
  @properties.push(@attack_complexity =
60
- CvssProperty.new(name: 'Attack Complexity', abbreviation: 'AC', position: [1],
54
+ CvssProperty.new(name: 'Attack Complexity', abbreviation: 'AC',
61
55
  values: [{ name: 'Low', abbreviation: 'L', weight: 0.77 },
62
56
  { name: 'High', abbreviation: 'H', weight: 0.44 }]))
63
57
  @properties.push(@privileges_required =
64
- CvssProperty.new(name: 'Privileges Required', abbreviation: 'PR', position: [2],
58
+ CvssProperty.new(name: 'Privileges Required', abbreviation: 'PR',
65
59
  values: [{ name: 'None', abbreviation: 'N', weight: 0.85 },
66
60
  { name: 'Low', abbreviation: 'L', weight: 0.62 },
67
61
  { name: 'High', abbreviation: 'H', weight: 0.27 }]))
68
62
  @properties.push(@user_interaction =
69
- CvssProperty.new(name: 'User Interaction', abbreviation: 'UI', position: [3],
63
+ CvssProperty.new(name: 'User Interaction', abbreviation: 'UI',
70
64
  values: [{ name: 'None', abbreviation: 'N', weight: 0.85 },
71
65
  { name: 'Required', abbreviation: 'R', weight: 0.62 }]))
72
66
  @properties.push(@scope =
73
- CvssProperty.new(name: 'Scope', abbreviation: 'S', position: [4],
67
+ CvssProperty.new(name: 'Scope', abbreviation: 'S',
74
68
  values: [{ name: 'Unchanged', abbreviation: 'U' },
75
69
  { name: 'Changed', abbreviation: 'C' }]))
76
70
  @properties.push(@confidentiality =
77
- CvssProperty.new(name: 'Confidentiality', abbreviation: 'C', position: [5],
71
+ CvssProperty.new(name: 'Confidentiality', abbreviation: 'C',
78
72
  values: [{ name: 'None', abbreviation: 'N', weight: 0.0 },
79
73
  { name: 'Low', abbreviation: 'L', weight: 0.22 },
80
74
  { name: 'High', abbreviation: 'H', weight: 0.56 }]))
81
75
  @properties.push(@integrity =
82
- CvssProperty.new(name: 'Integrity', abbreviation: 'I', position: [6],
76
+ CvssProperty.new(name: 'Integrity', abbreviation: 'I',
83
77
  values: [{ name: 'None', abbreviation: 'N', weight: 0.0 },
84
78
  { name: 'Low', abbreviation: 'L', weight: 0.22 },
85
79
  { name: 'High', abbreviation: 'H', weight: 0.56 }]))
86
80
  @properties.push(@availability =
87
- CvssProperty.new(name: 'Availability', abbreviation: 'A', position: [7],
81
+ CvssProperty.new(name: 'Availability', abbreviation: 'A',
88
82
  values: [{ name: 'None', abbreviation: 'N', weight: 0.0 },
89
83
  { name: 'Low', abbreviation: 'L', weight: 0.22 },
90
84
  { name: 'High', abbreviation: 'H', weight: 0.56 }]))