-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmark recommendations to threats in report (#8)
- Loading branch information
Showing
12 changed files
with
140 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Crisp.Core.Models; | ||
using System.Text; | ||
|
||
namespace Crisp.Core.Helpers; | ||
|
||
public static class MarkdownReportHelper | ||
{ | ||
public static string GenerateThreatModelPropertiesSection(ThreatModel threatModel, | ||
IDictionary<string, IEnumerable<SecurityBenchmark>>? benchmarks) | ||
{ | ||
var section = new StringBuilder(); | ||
var index = 1; | ||
foreach (var threat in threatModel.Threats) | ||
{ | ||
if (index > 1) | ||
{ | ||
section.AppendLine(); | ||
} | ||
section.AppendLine("---"); | ||
section.AppendLine($"**Threat #:** {index} "); | ||
section.AppendLine(threat.Description.Trim()); | ||
if (threatModel.AddResourcesRecommendations) | ||
{ | ||
var resourcesRecommendations = GenerateResourcesRecommendationsForThreat(threat, benchmarks); | ||
if (!string.IsNullOrEmpty(resourcesRecommendations)) | ||
{ | ||
section.AppendLine(resourcesRecommendations); | ||
} | ||
} | ||
index++; | ||
} | ||
return section.ToString().TrimEnd(Environment.NewLine.ToCharArray()); | ||
} | ||
|
||
public static string GenerateResourcesRecommendationsForThreat(Recommendation threat, | ||
IDictionary<string, IEnumerable<SecurityBenchmark>>? benchmarks) | ||
{ | ||
if (threat.BenchmarkIds is null || !threat.BenchmarkIds.Any() || benchmarks is null) | ||
{ | ||
return ""; | ||
} | ||
|
||
var section = new StringBuilder(); | ||
section.AppendLine(); | ||
section.AppendLine($"**Recommendations for resources:**"); | ||
section.AppendLine(); | ||
foreach (var resourceName in benchmarks.Keys) | ||
{ | ||
var resourceBenchmarks = benchmarks[resourceName]; | ||
if (resourceBenchmarks is null) | ||
{ | ||
continue; | ||
} | ||
section.AppendLine($"**{resourceName}:**"); | ||
section.AppendLine(); | ||
var index = 1; | ||
foreach (var benchmarkId in threat.BenchmarkIds) | ||
{ | ||
var benchmark = resourceBenchmarks.FirstOrDefault(b => b.Id == benchmarkId); | ||
if (benchmark is null) | ||
{ | ||
continue; | ||
} | ||
section.AppendLine($"**Recommendation #:** {index}"); | ||
section.AppendLine(); | ||
section.AppendLine(benchmark.Description); | ||
section.AppendLine(); | ||
index++; | ||
} | ||
} | ||
section.AppendLine(); | ||
|
||
return section.ToString(); | ||
} | ||
|
||
public static string GenerateDataflowAttributeSection(ThreatModel threatModel) | ||
{ | ||
var section = new StringBuilder(); | ||
foreach (var a in threatModel.DataflowAttributes) | ||
{ | ||
section.AppendLine($"| {a.Number.Trim()} | {a.Transport.Trim()} | {a.DataClassification.Trim()} | {a.Authentication.Trim()} | {a.Authorization.Trim()} | {a.Notes.Trim()} |"); | ||
} | ||
return section.ToString().TrimEnd(Environment.NewLine.ToCharArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters