cvss 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@cvss"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.2 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cvss.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Paolo Perego
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Cvss
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cvss'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cvss
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cvss'
4
+
5
+ raise "usage: cvss vector" if ARGV[0].nil?
6
+
7
+ cvss = Cvss::Engine.new
8
+
9
+ puts cvss.base if cvss.parse(ARGV[0])
10
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cvss/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cvss"
8
+ gem.version = Cvss::VERSION
9
+ gem.authors = ["Paolo Perego"]
10
+ gem.email = ["thesp0nge@gmail.com"]
11
+ gem.description = %q{cvss is a rubygem for parsing cvss vector and calculate cvss score given some parameter.}
12
+ gem.summary = %q{cvss is a rubygem for parsing cvss vector and calculate cvss score given some parameter.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec"
22
+
23
+ end
@@ -0,0 +1,11 @@
1
+ require "cvss/version"
2
+ require 'cvss/parser'
3
+ require 'cvss/helpers'
4
+
5
+ module Cvss
6
+ class Engine
7
+ include Cvss::Parser
8
+ include Cvss::Helpers
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Cvss
2
+ module Helpers
3
+ def data_integrity
4
+ @base[:i]
5
+ end
6
+ def data_confidentiality
7
+ @base[:c]
8
+ end
9
+ def data_availability
10
+ @base[:a]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ module Cvss
2
+ module Parser
3
+
4
+ attr_reader :base
5
+
6
+ # It parses a string and it says if it's a good CVSS vector or not.
7
+ def parse(string)
8
+ @base = {}
9
+
10
+ toks = string.split("/")
11
+ return parse_base(toks)
12
+ end
13
+
14
+
15
+ private
16
+ # AV:N/AC:L/Au:N/C:N/I:N/A:C
17
+ def parse_base(tokens)
18
+ return false if tokens.count != 6
19
+ av = tokens[0].split(":")
20
+ return false if av.count != 2 or av[0] != "AV" or (av[1] != "N" and av[1] != "L" and av[1] != "A")
21
+
22
+ ac = tokens[1].split(":")
23
+ return false if ac.count != 2 or ac[0] != "AC" or (ac[1] != "H" and ac[1] != "M" and ac[1] != "L")
24
+ au = tokens[2].split(":")
25
+
26
+ return false if au.count != 2 or au[0] != "Au" or (au[1] != "M" and au[1] != "S" and au[1] != "N")
27
+
28
+ c = tokens[3].split(":")
29
+ return false if c.count != 2 or c[0] != "C" or (c[1] != "P" and c[1] != "C" and c[1] != "N")
30
+
31
+ i = tokens[4].split(":")
32
+ return false if i.count != 2 or i[0] != "I" or (i[1] != "P" and i[1] != "C" and i[1] != "N")
33
+
34
+ a = tokens[5].split(":")
35
+ return false if a.count != 2 or a[0] != "A" or (a[1] != "P" and a[1] != "C" and a[1] != "N")
36
+
37
+
38
+
39
+
40
+ @base = {:av=>av[1], :ac=>ac[1], :au=>au[1], :c=>c[1], :i=>i[1], :a=>a[1]}
41
+ true
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Cvss
2
+ VERSION = "0.50.0"
3
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe "CVSS library" do
4
+ let(:cvss) { Cvss::Engine.new() }
5
+ describe "parser" do
6
+
7
+ it "should have a parser method" do
8
+ cvss.should respond_to(:parse)
9
+
10
+ end
11
+ it "should recognize a bad input" do
12
+ cvss.parse("this is a test string").should be_false
13
+ end
14
+
15
+ it "should recognize a good input" do
16
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C").should be_true
17
+ end
18
+
19
+ it "should recognize Access Vector" do
20
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
21
+ cvss.base[:av].should == "N"
22
+ end
23
+
24
+ it "should recognize Access Complexity" do
25
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
26
+ cvss.base[:ac].should == "L"
27
+ end
28
+ it "should recognize Authentication" do
29
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
30
+ cvss.base[:au].should == "N"
31
+ end
32
+ it "should recognize Confidentiality" do
33
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
34
+ cvss.base[:c].should == "N"
35
+ end
36
+ it "should recognize Integrity" do
37
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
38
+ cvss.base[:i].should == "N"
39
+ end
40
+ it "should recognize Availability" do
41
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
42
+ cvss.base[:a].should == "C"
43
+ end
44
+ end
45
+ describe "helper" do
46
+ it "should have a data integrity helper" do
47
+ cvss.should respond_to(:data_integrity)
48
+ end
49
+ it "should have a data confidentiality helper" do
50
+ cvss.should respond_to(:data_confidentiality)
51
+ end
52
+ it "should have a data availability helper" do
53
+ cvss.should respond_to(:data_availability)
54
+ end
55
+
56
+ it "should recognize Confidentiality" do
57
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
58
+ cvss.data_confidentiality.should == "N"
59
+ end
60
+ it "should recognize Integrity" do
61
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
62
+ cvss.data_integrity.should == "N"
63
+ end
64
+ it "should recognize Availability" do
65
+ cvss.parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
66
+ cvss.data_availability.should == "C"
67
+ end
68
+
69
+
70
+ end
71
+ end
@@ -0,0 +1 @@
1
+ require 'cvss'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cvss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.50.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paolo Perego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: cvss is a rubygem for parsing cvss vector and calculate cvss score given
47
+ some parameter.
48
+ email:
49
+ - thesp0nge@gmail.com
50
+ executables:
51
+ - cvss
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rvmrc
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/cvss
62
+ - cvss.gemspec
63
+ - lib/cvss.rb
64
+ - lib/cvss/helpers.rb
65
+ - lib/cvss/parser.rb
66
+ - lib/cvss/version.rb
67
+ - spec/cvss_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: ''
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ segments:
82
+ - 0
83
+ hash: -1438894689176709869
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: -1438894689176709869
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.24
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: cvss is a rubygem for parsing cvss vector and calculate cvss score given
99
+ some parameter.
100
+ test_files:
101
+ - spec/cvss_spec.rb
102
+ - spec/spec_helper.rb