Skip to content

Commit

Permalink
Merge pull request #4 from Jakobu5/master
Browse files Browse the repository at this point in the history
Added CVSS 3.1 Severity Rating Scale
  • Loading branch information
mkoppmann committed Oct 1, 2019
2 parents 5afd1b6 + be44eae commit 9d799f1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
68 changes: 68 additions & 0 deletions src/Cvss.elm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ type AvailabilityImpact
| AHigh


type Severity
= SLow
| SMedium
| SHigh
| SCritical
| SNone



-- CVSSV3 CALCULATION

Expand Down Expand Up @@ -387,6 +395,25 @@ toStringAvailabilityImpact a =
"A:H"


toStringSeverity : Severity -> String
toStringSeverity severity =
case severity of
SNone ->
"None"

SLow ->
"Low"

SMedium ->
"Medium"

SHigh ->
"High"

SCritical ->
"Critical"



-- Random generators

Expand Down Expand Up @@ -456,3 +483,44 @@ randomIntegrityImpact =
randomAvailabilityImpact : Random.Generator AvailabilityImpact
randomAvailabilityImpact =
Random.uniform ANone [ ALow, AHigh ]


toSeverityVector : Vector -> Severity
toSeverityVector vector =
let
score =
calculateBaseScore vector
in
if 0.1 <= score && score <= 3.9 then
SLow

else if 4.0 <= score && score <= 6.9 then
SMedium

else if 7.0 <= score && score <= 8.9 then
SHigh

else if 9.0 <= score && score <= 10.0 then
SCritical

else
SNone


toColorSeverity : Severity -> String
toColorSeverity severity =
case severity of
SNone ->
"#000000"

SLow ->
"#ffff00"

SMedium ->
"#ff6600"

SHigh ->
"#ff0000"

SCritical ->
"#660000"
14 changes: 12 additions & 2 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,18 @@ view model =
, button [ onClick CalculateVectorAgain ] [ text "Generate another vector" ]
, button [ onClick NewRandomVector ] [ text "Get random vector" ]
]
, div [] <| viewVector model.vector
, small []
, div
[ style "color" <| toColorSeverity <| toSeverityVector model.vector
]
<|
viewVector model.vector
, div
[ style "color" <| toColorSeverity <| toSeverityVector model.vector
]
[ text "Severity Rating: "
, text <| toStringSeverity <| toSeverityVector model.vector
]
, Html.small []
[ a [ href "https://github.com/mkoppmann/wtcvss" ] [ text "Source Code" ]
]
]
Expand Down

0 comments on commit 9d799f1

Please sign in to comment.