Skip to content
Snippets Groups Projects
Verified Commit 99493aac authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

added calculation for highest vulnerability score

parent f8674231
No related branches found
No related tags found
1 merge request!2dependency check
...@@ -7,6 +7,29 @@ import kotlinx.serialization.json.* ...@@ -7,6 +7,29 @@ import kotlinx.serialization.json.*
import java.io.IOException import java.io.IOException
import java.nio.file.Path import java.nio.file.Path
class OrtTask {
}
fun getHighestScore(results: Array<AdvisorResult>): Double {
var highestScore = 0.0
results.forEach { res ->
res.vulnerabilities?.forEach { vul ->
vul.references?.forEach { ref ->
if (ref != null) {
if (ref.scoringSystem?.contains("cvss") == true) {
val score = ref.severity?.toDouble() ?: 0.0
if (highestScore < score) {
highestScore = score
}
}
}
}
}
}
return highestScore
}
fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> { fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> {
val resFile = resultPath.toFile() val resFile = resultPath.toFile()
...@@ -14,6 +37,7 @@ fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> { ...@@ -14,6 +37,7 @@ fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> {
val results = mutableListOf<AdvisorResult>() val results = mutableListOf<AdvisorResult>()
val resString = resFile.readText() val resString = resFile.readText()
val json = Json { ignoreUnknownKeys = true } val json = Json { ignoreUnknownKeys = true }
val rawJson = json.decodeFromString<Ort>(resString) val rawJson = json.decodeFromString<Ort>(resString)
rawJson.advisor?.results?.advisorResults?.forEach { (key, value) -> rawJson.advisor?.results?.advisorResults?.forEach { (key, value) ->
if (value is JsonArray) { if (value is JsonArray) {
...@@ -26,8 +50,8 @@ fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> { ...@@ -26,8 +50,8 @@ fun getOrtResultsFromFile(resultPath: Path): Array<AdvisorResult> {
} }
put("identifier", key) put("identifier", key)
} }
val advisorResult = json.decodeFromJsonElement<AdvisorResult>(flat) val advisorResult = json.decodeFromJsonElement<AdvisorResult>(flat)
println(advisorResult)
results.add(advisorResult) results.add(advisorResult)
} }
} }
......
package de.fraunhofer.iem.dataprovider package de.fraunhofer.iem.dataprovider
import de.fraunhofer.iem.dataprovider.taskManager.tasks.ort.getHighestScore
import de.fraunhofer.iem.dataprovider.taskManager.tasks.ort.getOrtResultsFromFile import de.fraunhofer.iem.dataprovider.taskManager.tasks.ort.getOrtResultsFromFile
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.nio.file.Paths import java.nio.file.Paths
...@@ -14,6 +15,8 @@ class ParseOrtAdvisorResult { ...@@ -14,6 +15,8 @@ class ParseOrtAdvisorResult {
assert(res[0].identifier == "first" && res[1].identifier == "second") assert(res[0].identifier == "first" && res[1].identifier == "second")
assert(res[0].vulnerabilities?.get(0)?.id == "CVE-2021-45105") assert(res[0].vulnerabilities?.get(0)?.id == "CVE-2021-45105")
assert(res[0].vulnerabilities?.get(0)?.references?.get(0)?.severity == "6.6") assert(res[0].vulnerabilities?.get(0)?.references?.get(0)?.severity == "6.6")
assert(getHighestScore(res) == 8.6)
} }
......
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
{ {
"url": "https://access.redhat.com/hydra/rest/securitydata/cve/CVE-2021-44832.json", "url": "https://access.redhat.com/hydra/rest/securitydata/cve/CVE-2021-44832.json",
"scoring_system": "cvssv3", "scoring_system": "cvssv3",
"severity": "6.6" "severity": "8.6"
}, },
{ {
"url": "https://cert-portal.siemens.com/productcert/pdf/ssa-784507.pdf", "url": "https://cert-portal.siemens.com/productcert/pdf/ssa-784507.pdf",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.