From e8e7b9238b4cfb596fd6872010add7714877fcd0 Mon Sep 17 00:00:00 2001 From: Klaus Fischer <klaus.fischer@eloware.com> Date: Tue, 1 Nov 2022 12:32:12 +0100 Subject: [PATCH] Implemented 5.2, 5.3 --- FitConnect/Services/Models/v1/Api/Problems.cs | 13 ++++++ FitConnect/Subscriber.cs | 44 +++++++++++++++---- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/FitConnect/Services/Models/v1/Api/Problems.cs b/FitConnect/Services/Models/v1/Api/Problems.cs index b423f6a4..f868d873 100644 --- a/FitConnect/Services/Models/v1/Api/Problems.cs +++ b/FitConnect/Services/Models/v1/Api/Problems.cs @@ -19,6 +19,7 @@ public class Problems { public const string TitleEncryptionIssue = "Entschlüsselungs-Fehler"; public const string DetailEncryptionIssueMetadata = "Die Entschlüsselung des Metadatensatzes ist fehlgeschlagen."; public const string DetailEncryptionIssueData = "Der Fachdatensatz konnte nicht entschlüsselt werden."; + public const string DetailEncryptionIssueAttachment = "Die Anlage {0} konnte nicht entschlüsselt werden."; public const string TitleMissingData = "Fachdatensatz fehlt"; public const string DetailMissingData = "Der Fachdatensatz fehlt."; @@ -44,6 +45,9 @@ public class Problems { public const string DetailServiceMismatch = "Die Verwaltungsleistung in Submission und Metadatensatz stimmen nicht überein."; + public const string TitleAttachmentMissing = "Fehlerhafte Anlagen-Liste"; + public const string DetailAttachmentMissing = "Die Anlage {0} konnte nicht geladen werden."; + public const string TitleAttachmentsMismatch = "Fehlerhafte Anlagen-Liste"; public const string DetailAttachmentsMismatch = "Die Liste der Anlagen in Submission und Event-Log stimmt nicht überein."; @@ -167,6 +171,15 @@ public class Problems { } + public Problems(ProblemTypeEnum problemType, string title, string detail, + string problemInstance) : this(problemType, detail) { + this.title = title ?? problemType switch { + ProblemTypeEnum.InvalidEventLog => TitleEventLogInconsistent, + _ => problemType.ToString() + }; + + this.instance = problemInstance; + } public Problems(ProblemTypeEnum problemType, string title, string detail, ProblemInstanceEnum problemInstance) : this(problemType, detail) { this.title = title ?? problemType switch { diff --git a/FitConnect/Subscriber.cs b/FitConnect/Subscriber.cs index 61eb9668..7786c168 100644 --- a/FitConnect/Subscriber.cs +++ b/FitConnect/Subscriber.cs @@ -406,14 +406,42 @@ public class Subscriber : FitConnectClient, private List<Attachment> DownloadAttachments(Submission submission) { var attachments = new List<Attachment>(); foreach (var id in submission.AttachmentIds) { - var encryptedAttachment = SubmissionService.GetAttachment(submission.Id, id); - var (_, content, hash) = Encryption.Decrypt(encryptedAttachment); - var attachmentMeta = - submission.Metadata?.ContentStructure.Attachments.First(a => a.AttachmentId == id); - - if (attachmentMeta != null) - attachments.Add(new Attachment(id, attachmentMeta, content, - encryptedAttachment.Split('.').Last())); + string encryptedAttachment; + try { + encryptedAttachment = SubmissionService.GetAttachment(submission.Id, id); + } + catch (Exception e) { + var problem = new Problems(Problems.ProblemTypeEnum.MissingAttachments, + Problems.TitleAttachmentMissing, + string.Format(Problems.DetailAttachmentMissing, id), + $"attachment:{id}"); + + RejectSubmission(submission, problem); + throw new SecurityEventException(problem, e); + } + + try { + var (_, content, hash) = Encryption.Decrypt(encryptedAttachment); + var attachmentMeta = + submission.Metadata?.ContentStructure.Attachments.First(a => + a.AttachmentId == id); + + if (attachmentMeta != null) + attachments.Add(new Attachment(id, attachmentMeta, content, + encryptedAttachment.Split('.').Last())); + + } + catch (Exception e) { + var problem = new Problems( + Problems.ProblemTypeEnum.EncryptionIssue, + Problems.TitleEncryptionIssue, + string.Format(Problems.DetailEncryptionIssueAttachment, id), + "attachment:{id}" + ); + + RejectSubmission(submission, problem); + throw new SecurityEventException(problem, e); + } } return attachments; -- GitLab