Commit 52cf2e7f authored by Nadim Kobeissi's avatar Nadim Kobeissi 💎

More meaningful attack summary

parent 9b98a547
Pipeline #621 passed with stages
in 2 minutes and 19 seconds
......@@ -103,9 +103,9 @@ func InfoMessageColor(m string, t string, analysisCount int) {
}
func infoVerifyResultSummary(
mutated string, summary string, oResults []QueryOptionResult,
mutatedInfo string, summary string, oResults []QueryOptionResult,
) string {
mutatedIntro := ""
intro := ""
optionsSummary := ""
for _, oResult := range oResults {
if !oResult.Resolved {
......@@ -122,19 +122,18 @@ func infoVerifyResultSummary(
optionsSummary, " - ", oResult.Summary,
)
}
if len(mutated) > 0 {
mutatedIntro = "When:"
if len(mutatedInfo) > 0 {
intro = "When:"
}
if colorOutputSupport() {
return fmt.Sprintf("%s%s\n %s\n%s",
aurora.Italic(mutatedIntro).String(),
aurora.BrightYellow(mutated).Italic().String(),
aurora.Italic(intro).String(), mutatedInfo,
aurora.BgRed(summary).White().Italic().Bold().String(),
aurora.Red(optionsSummary).Italic().String(),
)
}
return fmt.Sprintf("%s%s\n %s\n%s",
mutatedIntro, mutated, summary, optionsSummary,
intro, mutatedInfo, summary, optionsSummary,
)
}
......@@ -214,3 +213,43 @@ func infoOutputText(revealed Value) string {
return outputText
}
}
func infoQueryMutatedValues(valKnowledgeMap KnowledgeMap, valPrincipalState PrincipalState) string {
mutatedInfo := ""
for i, a := range valPrincipalState.BeforeRewrite {
if valueEquivalentValues(a, valKnowledgeMap.Assigned[i], false) {
continue
}
pc := prettyConstant(valPrincipalState.Constants[i])
pa := prettyValue(valPrincipalState.Assigned[i])
if colorOutputSupport() {
if valPrincipalState.Mutated[i] {
mutatedInfo = fmt.Sprintf("%s\n %s%s%s %s",
mutatedInfo,
aurora.BrightYellow(pc).Italic().Underline().String(),
aurora.BrightYellow(" → ").Italic().Underline().String(),
aurora.BrightYellow(pa).Italic().Underline().String(),
aurora.Red("(mutated by attacker)").Italic().String(),
)
} else {
mutatedInfo = fmt.Sprintf("%s\n %s%s%s",
mutatedInfo,
aurora.BrightYellow(pc).Italic().String(),
aurora.BrightYellow(" → ").Italic().String(),
aurora.BrightYellow(pa).Italic().String(),
)
}
} else {
if valPrincipalState.Mutated[i] {
mutatedInfo = fmt.Sprintf("%s\n %s%s%s %s",
mutatedInfo, pc, " → ", pa, "(mutated by attacker)",
)
} else {
mutatedInfo = fmt.Sprintf("%s\n %s%s%s",
mutatedInfo, pc, " → ", pa,
)
}
}
}
return mutatedInfo
}
......@@ -44,7 +44,7 @@ func queryConfidentiality(
if ii < 0 {
return result
}
mutatedInfo := queryGetMutatedInfo(valKnowledgeMap, valAttackerState.PrincipalState[ii])
mutatedInfo := infoQueryMutatedValues(valKnowledgeMap, valAttackerState.PrincipalState[ii])
result.Resolved = true
result.Summary = infoVerifyResultSummary(mutatedInfo, fmt.Sprintf(
"%s (%s) is obtained by Attacker.",
......@@ -81,7 +81,7 @@ func queryAuthentication(
continue
}
result.Resolved = true
mutatedInfo := queryGetMutatedInfo(valKnowledgeMap, valPrincipalState)
mutatedInfo := infoQueryMutatedValues(valKnowledgeMap, valPrincipalState)
result = queryPrecondition(result, valPrincipalState)
b := valPrincipalState.BeforeRewrite[index]
return queryAuthenticationHandlePass(result, c, b, mutatedInfo, sender, valPrincipalState)
......@@ -184,7 +184,7 @@ func queryFreshness(
if freshnessFound {
return result, nil
}
mutatedInfo := queryGetMutatedInfo(valKnowledgeMap, valPrincipalState)
mutatedInfo := infoQueryMutatedValues(valKnowledgeMap, valPrincipalState)
resolved, _ := valueResolveConstant(query.Constants[0], valPrincipalState)
result.Resolved = true
result.Summary = infoVerifyResultSummary(mutatedInfo, fmt.Sprintf(
......@@ -234,7 +234,7 @@ func queryUnlinkability(
}
}
if len(noFreshness) > 0 {
mutatedInfo := queryGetMutatedInfo(valKnowledgeMap, valPrincipalState)
mutatedInfo := infoQueryMutatedValues(valKnowledgeMap, valPrincipalState)
resolved, _ := valueResolveConstant(noFreshness[0], valPrincipalState)
result.Resolved = true
result.Summary = infoVerifyResultSummary(mutatedInfo, fmt.Sprintf(
......@@ -276,7 +276,7 @@ func queryUnlinkability(
if !obtainable {
continue
}
mutatedInfo := queryGetMutatedInfo(valKnowledgeMap, valPrincipalState)
mutatedInfo := infoQueryMutatedValues(valKnowledgeMap, valPrincipalState)
result.Resolved = true
result.Summary = infoVerifyResultSummary(mutatedInfo, fmt.Sprintf(
"%s and %s %s (%s), %s.",
......@@ -336,18 +336,3 @@ func queryPrecondition(
}
return result
}
func queryGetMutatedInfo(valKnowledgeMap KnowledgeMap, valPrincipalState PrincipalState) string {
mutatedInfo := ""
for i, a := range valPrincipalState.BeforeRewrite {
if valueEquivalentValues(a, valKnowledgeMap.Assigned[i], false) {
continue
}
mutatedInfo = fmt.Sprintf("%s\n %s%s → %s",
mutatedInfo, " ",
prettyConstant(valPrincipalState.Constants[i]),
prettyValue(valPrincipalState.Assigned[i]),
)
}
return mutatedInfo
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment