From ee2133c0c277a3e3e9e6685df4e7870c07b74974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Tue, 29 Jun 2021 09:44:16 +0200 Subject: [PATCH] SEBWIN-494: Fixed issue with sensitive proctoring data. --- .../JitsiMeet/index.html | 89 +++++----- .../ProctoringControl.cs | 50 +++++- .../ProctoringController.cs | 12 +- .../SafeExamBrowser.Proctoring.csproj | 7 +- SafeExamBrowser.Proctoring/Zoom/index.html | 155 +++++++++--------- SafeExamBrowser.Proctoring/packages.config | 1 + 6 files changed, 187 insertions(+), 127 deletions(-) diff --git a/SafeExamBrowser.Proctoring/JitsiMeet/index.html b/SafeExamBrowser.Proctoring/JitsiMeet/index.html index c2d9faa5..7b59f836 100644 --- a/SafeExamBrowser.Proctoring/JitsiMeet/index.html +++ b/SafeExamBrowser.Proctoring/JitsiMeet/index.html @@ -6,46 +6,59 @@
\ No newline at end of file diff --git a/SafeExamBrowser.Proctoring/ProctoringControl.cs b/SafeExamBrowser.Proctoring/ProctoringControl.cs index 5c54f947..d5eef703 100644 --- a/SafeExamBrowser.Proctoring/ProctoringControl.cs +++ b/SafeExamBrowser.Proctoring/ProctoringControl.cs @@ -8,7 +8,9 @@ using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.Wpf; +using Newtonsoft.Json.Linq; using SafeExamBrowser.Logging.Contracts; +using SafeExamBrowser.Settings.Proctoring; using SafeExamBrowser.UserInterface.Contracts.Proctoring; using SafeExamBrowser.UserInterface.Contracts.Proctoring.Events; @@ -17,12 +19,15 @@ namespace SafeExamBrowser.Proctoring internal class ProctoringControl : WebView2, IProctoringControl { private readonly ILogger logger; + private readonly ProctoringSettings settings; public event FullScreenChangedEventHandler FullScreenChanged; - internal ProctoringControl(ILogger logger) + internal ProctoringControl(ILogger logger, ProctoringSettings settings) { this.logger = logger; + this.settings = settings; + CoreWebView2InitializationCompleted += ProctoringControl_CoreWebView2InitializationCompleted; } @@ -35,6 +40,7 @@ namespace SafeExamBrowser.Proctoring CoreWebView2.Settings.IsStatusBarEnabled = false; CoreWebView2.ContainsFullScreenElementChanged += CoreWebView2_ContainsFullScreenElementChanged; CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested; + CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived; logger.Info("Successfully initialized."); } else @@ -61,5 +67,47 @@ namespace SafeExamBrowser.Proctoring logger.Info($"Denied access to {e.PermissionKind}."); } } + + private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) + { + var message = e.TryGetWebMessageAsString(); + + logger.Debug($"Received web message '{message}'."); + + switch (message) + { + case "credentials": + SendCredentials(); + break; + } + } + + private void SendCredentials() + { + var message = new JObject(); + var credentials = new JObject(); + + if (settings.JitsiMeet.Enabled) + { + credentials.Add(new JProperty("domain", settings.JitsiMeet.ServerUrl)); + credentials.Add(new JProperty("roomName", settings.JitsiMeet.RoomName)); + credentials.Add(new JProperty("subject", settings.JitsiMeet.ShowMeetingName ? settings.JitsiMeet.Subject : "")); + credentials.Add(new JProperty("token", settings.JitsiMeet.Token)); + } + else if (settings.Zoom.Enabled) + { + credentials.Add(new JProperty("apiKey", settings.Zoom.ApiKey)); + credentials.Add(new JProperty("apiSecret", settings.Zoom.ApiSecret)); + credentials.Add(new JProperty("meetingNumber", settings.Zoom.MeetingNumber)); + credentials.Add(new JProperty("password", settings.Zoom.Password)); + credentials.Add(new JProperty("signature", settings.Zoom.Signature)); + credentials.Add(new JProperty("userName", settings.Zoom.UserName)); + } + + message.Add("credentials", credentials); + logger.Debug("Sending credentials to proctoring client."); + + CoreWebView2.PostWebMessageAsJson(message.ToString()); + } } } diff --git a/SafeExamBrowser.Proctoring/ProctoringController.cs b/SafeExamBrowser.Proctoring/ProctoringController.cs index f73ab60e..f9ba3953 100644 --- a/SafeExamBrowser.Proctoring/ProctoringController.cs +++ b/SafeExamBrowser.Proctoring/ProctoringController.cs @@ -169,7 +169,7 @@ namespace SafeExamBrowser.Proctoring filePath = Path.Combine(appConfig.TemporaryDirectory, $"{Path.GetRandomFileName()}_index.html"); fileSystem.Save(content, filePath); - control = new ProctoringControl(logger.CloneFor(nameof(ProctoringControl))); + control = new ProctoringControl(logger.CloneFor(nameof(ProctoringControl)), settings); control.CreationProperties = new CoreWebView2CreationProperties { UserDataFolder = appConfig.TemporaryDirectory }; control.EnsureCoreWebView2Async().ContinueWith(_ => { @@ -253,10 +253,6 @@ namespace SafeExamBrowser.Proctoring html = html.Replace("%%_ALLOW_TILE_VIEW", settings.JitsiMeet.AllowTileView ? "tileview" : ""); html = html.Replace("'%_AUDIO_MUTED_%'", settings.JitsiMeet.AudioMuted && settings.WindowVisibility != WindowVisibility.Hidden ? "true" : "false"); html = html.Replace("'%_AUDIO_ONLY_%'", settings.JitsiMeet.AudioOnly ? "true" : "false"); - html = html.Replace("%%_SUBJECT_%%", settings.JitsiMeet.ShowMeetingName ? settings.JitsiMeet.Subject : " "); - html = html.Replace("%%_DOMAIN_%%", settings.JitsiMeet.ServerUrl); - html = html.Replace("%%_ROOM_NAME_%%", settings.JitsiMeet.RoomName); - html = html.Replace("%%_TOKEN_%%", settings.JitsiMeet.Token); html = html.Replace("'%_VIDEO_MUTED_%'", settings.JitsiMeet.VideoMuted && settings.WindowVisibility != WindowVisibility.Hidden ? "true" : "false"); } else if (settings.Zoom.Enabled) @@ -264,13 +260,7 @@ namespace SafeExamBrowser.Proctoring html = html.Replace("'%_ALLOW_CHAT_%'", settings.Zoom.AllowChat ? "true" : "false"); html = html.Replace("'%_ALLOW_CLOSED_CAPTIONS_%'", settings.Zoom.AllowClosedCaptions ? "true" : "false"); html = html.Replace("'%_ALLOW_RAISE_HAND_%'", settings.Zoom.AllowRaiseHand ? "true" : "false"); - html = html.Replace("%%_API_KEY_%%", settings.Zoom.ApiKey); - html = html.Replace("%%_API_SECRET_%%", settings.Zoom.ApiSecret); html = html.Replace("'%_AUDIO_MUTED_%'", settings.Zoom.AudioMuted && settings.WindowVisibility != WindowVisibility.Hidden ? "true" : "false"); - html = html.Replace("%%_MEETING_NUMBER_%%", settings.Zoom.MeetingNumber); - html = html.Replace("%%_PASSWORD_%%", settings.Zoom.Password); - html = html.Replace("%%_SIGNATURE_%%", settings.Zoom.Signature); - html = html.Replace("%%_USER_NAME_%%", settings.Zoom.UserName); html = html.Replace("'%_VIDEO_MUTED_%'", settings.Zoom.VideoMuted && settings.WindowVisibility != WindowVisibility.Hidden ? "true" : "false"); } diff --git a/SafeExamBrowser.Proctoring/SafeExamBrowser.Proctoring.csproj b/SafeExamBrowser.Proctoring/SafeExamBrowser.Proctoring.csproj index 881e78db..1e5fcffc 100644 --- a/SafeExamBrowser.Proctoring/SafeExamBrowser.Proctoring.csproj +++ b/SafeExamBrowser.Proctoring/SafeExamBrowser.Proctoring.csproj @@ -61,6 +61,9 @@ ..\packages\Microsoft.Web.WebView2.1.0.864.35\lib\net45\Microsoft.Web.WebView2.Wpf.dll + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + @@ -116,7 +119,9 @@ - + + Designer + diff --git a/SafeExamBrowser.Proctoring/Zoom/index.html b/SafeExamBrowser.Proctoring/Zoom/index.html index f55cb6f5..f4cb08bd 100644 --- a/SafeExamBrowser.Proctoring/Zoom/index.html +++ b/SafeExamBrowser.Proctoring/Zoom/index.html @@ -14,19 +14,9 @@ \ No newline at end of file diff --git a/SafeExamBrowser.Proctoring/packages.config b/SafeExamBrowser.Proctoring/packages.config index fc7a59ae..f66f5440 100644 --- a/SafeExamBrowser.Proctoring/packages.config +++ b/SafeExamBrowser.Proctoring/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file