diff --git a/features/support/env.rb b/features/support/env.rb index 7f55fd1b7..d3ac761bf 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -64,8 +64,6 @@ BeforeAll do $api_key = 'a35a2a72bd230ac0aa0f52715bbdc6aa' - Maze.config.enforce_bugsnag_integrity = false - if Maze.config.os&.downcase == 'macos' # The default macOS Crash Reporter "#{app_name} quit unexpectedly" alert grabs focus which can cause tests to flake. # This option, which appears to have been introduced in macOS 10.11, displays a notification instead of the alert. diff --git a/src/BugsnagUnity/Delivery.cs b/src/BugsnagUnity/Delivery.cs index 2057f387f..55b8601fd 100644 --- a/src/BugsnagUnity/Delivery.cs +++ b/src/BugsnagUnity/Delivery.cs @@ -9,6 +9,7 @@ using BugsnagUnity.Payload; using UnityEngine; using UnityEngine.Networking; +using System.Security.Cryptography; namespace BugsnagUnity { @@ -187,6 +188,8 @@ IEnumerator PushToServer(IPayload payload) { req.SetRequestHeader("Content-Type", "application/json"); req.SetRequestHeader("Bugsnag-Sent-At", DateTimeOffset.Now.ToString("o", CultureInfo.InvariantCulture)); + req.SetRequestHeader("Bugsnag-Integrity", "sha1 " + Hash(body)); + foreach (var header in payload.Headers) { req.SetRequestHeader(header.Key, header.Value); @@ -278,6 +281,20 @@ private byte[] PrepareEventBodySimple(IPayload payload) return serialisedPayload; } + private string Hash(byte[] input) + { + using (SHA1Managed sha1 = new SHA1Managed()) + { + var hash = sha1.ComputeHash(input); + var sb = new StringBuilder(hash.Length * 2); + foreach (byte b in hash) + { + sb.Append(b.ToString("x2")); + } + return sb.ToString(); + } + } + private bool TruncateBreadcrumbs(Dictionary @event, int bytesToRemove) { var breadcrumbsList = (@event[EVENT_KEY_BREADCRUMBS] as Dictionary[]).ToList();