module Cvss3Vectors

Constants

VECTORS

Attributes

ac[R]
ai[R]
ar[R]
av[R]
ci[R]
cr[R]
ex[R]
ii[R]
ir[R]
pr[R]
rc[R]
rl[R]
sc[R]
ui[R]

Public Instance Methods

ac=(ac) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 98
def ac=(ac)
  @ac = case ac
        when 'high', 'H'
          ::Cvss3::Metrics::ATTACK_COMPLEXITY[:high]
        when 'low', 'L'
          ::Cvss3::Metrics::ATTACK_COMPLEXITY[:low]
        else
          raise 'Bad Argument'
    end
end
ai=(ai) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 221
def ai=(ai)
  @ai = case ai
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        else
          raise 'Bad Argument'
    end
end
ar=(ar) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 518
def ar=(ar)
  @ar = case ar
        when 'low', 'L' then ::Cvss3::Metrics::CIA_REQUIREMENT[:low]
        when 'medium', 'M' then ::Cvss3::Metrics::CIA_REQUIREMENT[:medium]
        when 'high', 'H' then ::Cvss3::Metrics::CIA_REQUIREMENT[:high]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::CIA_REQUIREMENT[:not_defined]
        else
          raise 'Bad Argument'
    end
end
av=(av) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 79
def av=(av)
  @av = case av
        when 'physical', 'P'
          ::Cvss3::Metrics::ATTACK_VECTOR[:physical]
        when 'local', 'L'
          ::Cvss3::Metrics::ATTACK_VECTOR[:local]
        when 'adjacent network', 'A'
          ::Cvss3::Metrics::ATTACK_VECTOR[:adjacent_network]
        when 'network', 'N'
          ::Cvss3::Metrics::ATTACK_VECTOR[:network]
        else
          raise 'Bad Argument'
    end
end
ci=(ci) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 187
def ci=(ci)
  @ci = case ci
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        else
          raise 'Bad Argument'
    end
end
cr=(cr) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 488
def cr=(cr)
  @cr = case cr
        when 'low', 'L' then ::Cvss3::Metrics::CIA_REQUIREMENT[:low]
        when 'medium', 'M' then ::Cvss3::Metrics::CIA_REQUIREMENT[:medium]
        when 'high', 'H' then ::Cvss3::Metrics::CIA_REQUIREMENT[:high]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::CIA_REQUIREMENT[:not_defined]
        else
          raise 'Bad Argument'
    end
end
cvss3=(cvss3) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 75
def cvss3=(cvss3)
  raise 'Bad CVSS 3.0 Vector String' if cvss3 != '3.0'
end
ex=(ex) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 441
def ex=(ex)
  @ex = case ex
        when 'unproven', 'U' then ::Cvss3::Metrics::EXPLOITABILITY[:unproven]
        when 'proof-of-concept', 'P', 'POC' then ::Cvss3::Metrics::EXPLOITABILITY[:poc]
        when 'functional', 'F' then ::Cvss3::Metrics::EXPLOITABILITY[:functional]
        when 'high', 'H' then ::Cvss3::Metrics::EXPLOITABILITY[:high]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::EXPLOITABILITY[:not_defined]
        else
          raise 'Bad Argument'
  end
end
get_key(vector, value) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 71
def get_key(vector, value)
  get_key = eval('::Cvss3::Metrics::' + vector + '_KEY')[(eval('::Cvss3::Metrics::' + vector).select { |_k, v| v == value }).keys[0]]
end
ii=(ii) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 204
def ii=(ii)
  @ii = case ii
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        else
          raise 'Bad Argument'
    end
end
init(ex = 'ND', rl = 'ND', rc = 'ND', _cd = 'ND', _td = 'ND', cr = 'ND', ir = 'ND', ar = 'ND', mav = 'ND', mac = 'ND', mpv = 'ND', mui = 'ND', mc = 'ND', mi = 'ND', ma = 'ND', ms = 'ND') click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 533
def init(ex = 'ND', rl = 'ND', rc = 'ND', _cd = 'ND', _td = 'ND', cr = 'ND', ir = 'ND', ar = 'ND',
         mav = 'ND', mac = 'ND', mpv = 'ND', mui = 'ND', mc = 'ND', mi = 'ND', ma = 'ND', ms = 'ND')
  self.ex = ex
  self.rl = rl
  self.rc = rc

  self.cr = cr
  self.ir = ir
  self.ar = ar

  self.mav = mav
  self.mac = mac
  self.mpr = mpv
  self.mui = mui

  self.mc = mc
  self.mi = mi
  self.ma = ma
end
ir=(ir) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 503
def ir=(ir)
  @ir = case ir
        when 'low', 'L' then ::Cvss3::Metrics::CIA_REQUIREMENT[:low]
        when 'medium', 'M' then ::Cvss3::Metrics::CIA_REQUIREMENT[:medium]
        when 'high', 'H' then ::Cvss3::Metrics::CIA_REQUIREMENT[:high]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::CIA_REQUIREMENT[:not_defined]
        else
          raise 'Bad Argument'
    end
end
key() click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 66
def key
  set_key
  @key
end
ma(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 433
def ma(raw = false)
  if raw
    @ma ||= @ai
  else
    ma = get_key('CIA_IMPACT', @ma) unless @ma.nil?
    end
end
ma=(ma) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 418
def ma=(ma)
  @ma = case ma
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end
mac(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 276
def mac(raw = false)
  if raw
    @mac ||= @ac
  else
    mac = get_key('ATTACK_COMPLEXITY', @mac) unless @mac.nil?
     end
end
mac=(mac) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 263
def mac=(mac)
  @mac = case mac
         when 'high', 'H'
           ::Cvss3::Metrics::ATTACK_COMPLEXITY[:high]
         when 'low', 'L'
           ::Cvss3::Metrics::ATTACK_COMPLEXITY[:low]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end
mav(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 255
def mav(raw = false)
  if raw
    @mav ||= @av
  else
    mav = get_key('ATTACK_VECTOR', @mav) unless @mav.nil?
    end
end
mav=(mav) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 238
def mav=(mav)
  @mav = case mav
         when 'physical', 'P'
           ::Cvss3::Metrics::ATTACK_VECTOR[:physical]
         when 'local', 'L'
           ::Cvss3::Metrics::ATTACK_VECTOR[:local]
         when 'adjacent network', 'A'
           ::Cvss3::Metrics::ATTACK_VECTOR[:adjacent_network]
         when 'network', 'N'
           ::Cvss3::Metrics::ATTACK_VECTOR[:network]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end
mc(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 387
def mc(raw = false)
  if raw
    @mv ||= @ci
  else
    mc = get_key('CIA_IMPACT', @mc) unless @mc.nil?
    end
end
mc=(mc) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 372
def mc=(mc)
  @mc = case mc
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end
mi(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 410
def mi(raw = false)
  if raw
    @mi ||= @ii
  else
    mi = get_key('CIA_IMPACT', @mi) unless @mi.nil?
    end
end
mi=(mi) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 395
def mi=(mi)
  @mi = case mi
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end
mpr(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 320
def mpr(raw = false)
  if raw
    @mpr ||= @pr
  else
    if @ms == 'changed'
      mpr = get_key('PRIVILEGE_REQUIRED_CHANGED', @mpr) unless @mpr.nil?
    else
      mpr = get_key('PRIVILEGE_REQUIRED', @mpr) unless @mpr.nil?
      end
    end
end
mpr=(mpr) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 305
def mpr=(mpr)
  @mpr = case mpr
         when 'none', 'N'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:none]
         when 'low', 'L'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:low]
         when 'high', 'H'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:high]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end
ms(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 360
def ms(raw = false)
  if raw
    @ms ||= @sc
  else
    if @ms.nil?
      ms = ::Cvss3::Metrics::SCOPE_KEY[@sc.to_sym] unless @sc.nil?
    else
      ms = ::Cvss3::Metrics::SCOPE_KEY[@ms.to_sym] unless @ms.nil?
    end
  end
end
ms=(ms) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 332
def ms=(ms)
  @ms = case ms
        when 'changed', 'C'
          'changed'
        when 'unchanged', 'U'
          'unchanged'
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end

  if @ms == 'changed'
    @mpr = case get_key('PRIVILEGE_REQUIRED', mpr(true)).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', mpr(true)) : get_key('PRIVILEGE_REQUIRED', mpr(true))
           when 'none', 'N',
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:none]
           when 'low', 'L'
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:low]
           when 'high', 'H'
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:high]
           else
             raise 'Bad Argument'
    end
  else
    self.mpr = get_key('PRIVILEGE_REQUIRED', mpr(true)).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', mpr(true)) : get_key('PRIVILEGE_REQUIRED', mpr(true))
   end
end
mui(raw = false) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 297
def mui(raw = false)
  if raw
    @mui ||= @ui
  else
    mui = get_key('USER_INTERACTION', @mui) unless @mui.nil?
    end
end
mui=(mui) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 284
def mui=(mui)
  @mui = case mui
         when 'none', 'N'
           ::Cvss3::Metrics::USER_INTERACTION[:none]
         when 'required', 'R'
           ::Cvss3::Metrics::USER_INTERACTION[:required]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end
parse(vector) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 30
def parse(vector)
  string = vector.split('/')
  len = string.length

  init

  @originalkey = vector

  string.each do |section|
    tmp = section.split(':')
    send(VECTORS[tmp[0].downcase].to_sym, tmp[1])
  end
end
pr=(pr) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 128
def pr=(pr)
  @pr = case pr
        when 'none', 'N'
          ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:high]
        else
          raise 'Bad Argument'
    end
end
rc=(rc) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 473
def rc=(rc)
  @rc = case rc
        when 'unknown', 'U' then ::Cvss3::Metrics::REPORT_CONFIDENCE[:unknown]
        when 'reasonable', 'R' then ::Cvss3::Metrics::REPORT_CONFIDENCE[:reasonable]
        when 'confirmed', 'C' then ::Cvss3::Metrics::REPORT_CONFIDENCE[:confirmed]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::REPORT_CONFIDENCE[:not_defined]
        else
          raise 'Bad Argument'
  end
 end
rl=(rl) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 457
def rl=(rl)
  @rl = case rl
        when 'official-fix', 'O' then ::Cvss3::Metrics::REMEDIATION_LEVEL[:official]
        when 'temporary-fix', 'T', 'TF' then ::Cvss3::Metrics::REMEDIATION_LEVEL[:temporary]
        when 'workaround', 'W' then ::Cvss3::Metrics::REMEDIATION_LEVEL[:workaround]
        when 'unavailable', 'U' then ::Cvss3::Metrics::REMEDIATION_LEVEL[:unavailable]
        when 'not defined', 'ND', 'X' then ::Cvss3::Metrics::REMEDIATION_LEVEL[:not_defined]
        else
          raise 'Bad Argument'
  end
end
sc=(sc) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 158
def sc=(sc)
  @sc = case sc
        when 'changed', 'C'
          'changed'
        when 'unchanged', 'U'
          'unchanged'
        else
          raise 'Bad Argument'
    end

  if @sc == 'changed'
    tmp = case get_key('PRIVILEGE_REQUIRED', @pr).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', @pr) : get_key('PRIVILEGE_REQUIRED', @pr)
          when 'none', 'N',
                              ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:none]
          when 'low', 'L'
            ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:low]
          when 'high', 'H'
            ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:high]
          end
    @pr = tmp unless tmp.nil?
  else
    self.pr = get_key('PRIVILEGE_REQUIRED', @pr).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', @pr) : get_key('PRIVILEGE_REQUIRED', @pr)
   end
end
set_key() click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 44
def set_key
  @key = format('AV:%s/AC:%s/PR:%s/UI:%s/C:%s/I:%s/A:%s', av, ac, pr, ui, ci, ii, ai)

  @key += format('/E:%s', ex) unless @ex.nil?
  @key += format('/RL:%s', rl) unless @rl.nil?
  @key += format('/RC:%s', rc) unless @rc.nil?

  @key += format('/CR:%s', cr) unless @cr.nil?
  @key += format('/IR:%s', ir) unless @ir.nil?
  @key += format('/AR:%s', ar) unless @ar.nil?

  @key += format('/MAV:%s', mav) unless @mav.nil?
  @key += format('/MAC:%s', mac) unless @mac.nil?
  @key += format('/MPR:%s', mpr) unless @mpr.nil?
  @key += format('/MUI:%s', mui) unless @mui.nil?
  @key += format('/MS:%s', ms) unless @ms.nil?

  @key += format('/MC:%s', mc) unless @mc.nil?
  @key += format('/MI:%s', mi) unless @mi.nil?
  @key += format('/MA:%s', ma) unless @ma.nil?
end
ui=(ui) click to toggle source
# File lib/cvss_rating/cvss3_vectors.rb, line 113
def ui=(ui)
  @ui = case ui
        when 'none', 'N'
          ::Cvss3::Metrics::USER_INTERACTION[:none]
        when 'required', 'R'
          ::Cvss3::Metrics::USER_INTERACTION[:required]
        else
          raise 'Bad Argument'
    end
end