Skip to content
Snippets Groups Projects
Commit f00ec999 authored by Klaus Fischer's avatar Klaus Fischer
Browse files

Implemented 3.12, 5.2

parent eeacc200
No related branches found
No related tags found
1 merge request!24AutoReject planning#594
...@@ -13,6 +13,7 @@ public class Problems { ...@@ -13,6 +13,7 @@ public class Problems {
public const string TitleAuthenticationTagInvalid = "Authentication-Tag ungültig"; public const string TitleAuthenticationTagInvalid = "Authentication-Tag ungültig";
public const string DetailAuthenticationTagMissing = "Das Event 'submit-submission' enthält keine Authentication-Tags."; public const string DetailAuthenticationTagMissing = "Das Event 'submit-submission' enthält keine Authentication-Tags.";
public const string DetailAuthenticationMetadataInvalid = "Das Authentication-Tag des Metadatensatzes ist ungültig."; public const string DetailAuthenticationMetadataInvalid = "Das Authentication-Tag des Metadatensatzes ist ungültig.";
public const string DetailAuthenticationAttachmentInvalid = "Das Authentication-Tag der Anlage {attachmentId} ist ungültig.";
public const string TitleEncryptionIssue = "Entschlüsselungs-Fehler"; public const string TitleEncryptionIssue = "Entschlüsselungs-Fehler";
public const string DetailEncryptionIssue = "Die Entschlüsselung des Metadatensatzes ist fehlgeschlagen."; public const string DetailEncryptionIssue = "Die Entschlüsselung des Metadatensatzes ist fehlgeschlagen.";
...@@ -78,7 +79,7 @@ public class Problems { ...@@ -78,7 +79,7 @@ public class Problems {
switch (problemType) { switch (problemType) {
case ProblemTypeEnum.MissingAttachments: case ProblemTypeEnum.MissingAttachments:
type += "missing-attachment"; type += "missing-attachment";
title = TitleEventLogInconsistent; title = TitleAttachmentsMismatch;
instance = "submission"; instance = "submission";
break; break;
case ProblemTypeEnum.AttachmentMismatch: case ProblemTypeEnum.AttachmentMismatch:
...@@ -178,7 +179,7 @@ public class Problems { ...@@ -178,7 +179,7 @@ public class Problems {
ProblemTypeEnum.AttachmentMismatch, ProblemTypeEnum.AttachmentMismatch,
"Fehlerhafte Anlagen-Liste", "Fehlerhafte Anlagen-Liste",
"Die Liste der Anlagen in Submission und Event-Log stimmt nicht überein.", "Die Liste der Anlagen in Submission und Event-Log stimmt nicht überein.",
ProblemInstanceEnum.Submission); ProblemInstanceEnum.Metadata);
public static readonly Problems EncryptionIssue = public static readonly Problems EncryptionIssue =
new Problems( new Problems(
......
...@@ -216,6 +216,8 @@ public class Subscriber : FitConnectClient, ...@@ -216,6 +216,8 @@ public class Subscriber : FitConnectClient,
? null ? null
: (JsonConvert.DeserializeObject(jsonString) as JObject)?["$schema"]?.ToString(); : (JsonConvert.DeserializeObject(jsonString) as JObject)?["$schema"]?.ToString();
#region Check Submission and Reject if needed
private void CheckDataSchema(string dataSchema, Submission submission) { private void CheckDataSchema(string dataSchema, Submission submission) {
var dataSchemaObject = JsonSchema.FromUrlAsync(dataSchema).Result; var dataSchemaObject = JsonSchema.FromUrlAsync(dataSchema).Result;
var jSchema = JSchema.Parse(dataSchemaObject.ToJson()); var jSchema = JSchema.Parse(dataSchemaObject.ToJson());
...@@ -229,7 +231,6 @@ public class Subscriber : FitConnectClient, ...@@ -229,7 +231,6 @@ public class Subscriber : FitConnectClient,
} }
} }
#region Check Submission and Reject if needed
private void VerifyDataHash(Submission submission, string dataString) { private void VerifyDataHash(Submission submission, string dataString) {
if (submission.Metadata?.ContentStructure.Data.Hash.Content == if (submission.Metadata?.ContentStructure.Data.Hash.Content ==
...@@ -310,16 +311,28 @@ public class Subscriber : FitConnectClient, ...@@ -310,16 +311,28 @@ public class Subscriber : FitConnectClient,
private void CheckAttachments(Submission submission, private void CheckAttachments(Submission submission,
Dictionary<string, string> attachmentSignatures) { Dictionary<string, string> attachmentSignatures) {
if (submission?.Attachments != null) { if (submission?.Attachments != null) {
if (submission.Attachments.Count != attachmentSignatures.Count) { // SuccessCriteria:3.12
RejectSubmission(submission, Problems.AttachmentsMismatch); if (submission.Attachments.Count != attachmentSignatures.Count ||
throw new ArgumentException("Attachment count mismatch"); !submission.Attachments.TrueForAll(a => attachmentSignatures.ContainsKey(a.Id))) {
var problem = new Problems(Problems.ProblemTypeEnum.AttachmentMismatch,
Problems.DetailAttachmentsMismatch);
RejectSubmission(submission, problem);
throw new SecurityEventException(problem);
} }
// SuccessCriteria:5.2
var problems = new List<Problems>();
foreach (var attachment in submission.Attachments) { foreach (var attachment in submission.Attachments) {
if (attachmentSignatures?[attachment.Id] != if (attachmentSignatures?[attachment.Id] !=
attachment.AttachmentAuthentication) { attachment.AttachmentAuthentication) {
RejectSubmission(submission, Problems.IncorrectAuthenticationTag); var problem = new Problems(Problems.ProblemTypeEnum.IncorrectAuthenticationTag,
throw new AggregateException("Attachment signature mismatch"); Problems.DetailAuthenticationAttachmentInvalid);
problems.Add(problem);
}
if (problems.Count > 0) {
RejectSubmission(submission, problems.ToArray());
throw new SecurityEventException(problems.ToArray());
} }
} }
} }
...@@ -463,6 +476,12 @@ public class SecurityEventException : Exception { ...@@ -463,6 +476,12 @@ public class SecurityEventException : Exception {
Detail = problem.detail; Detail = problem.detail;
} }
public SecurityEventException(Problems[] problem, Exception? innerException = null) : base(
$"{problem[0].title}: {problem[0].detail}", innerException) {
Title = problem.Select(p => p.title).Aggregate((a, b) => a + "\r\n" + b);
Detail = problem.Select(p => p.detail).Aggregate((a, b) => a + "\r\n" + b);
}
public SecurityEventException(string title, string detail, Exception? innerException = null) : public SecurityEventException(string title, string detail, Exception? innerException = null) :
base( base(
$"{title}: {detail}", innerException) { $"{title}: {detail}", innerException) {
......
...@@ -95,8 +95,8 @@ public class SenderTestHappyPath : SenderTestBase { ...@@ -95,8 +95,8 @@ public class SenderTestHappyPath : SenderTestBase {
public string Schema { get; set; } = public string Schema { get; set; } =
"https://git.fitko.de/fit-connect/sdk-dotnet/-/raw/feature/594-auto-reject/simple_schema.json"; "https://git.fitko.de/fit-connect/sdk-dotnet/-/raw/feature/594-auto-reject/simple_schema.json";
public string FirstName { get; set; } public string? FirstName { get; set; }
public string LastName { get; set; } public string? LastName { get; set; }
public int Age { get; set; } public int Age { get; set; }
} }
......
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