From 8987f7dd18b9f6500601dd9ae89fd1ddadcebee8 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sat, 25 Sep 2021 08:36:41 -0700 Subject: [PATCH] Reset server verification token when switching servers. --- Agent/Services/AgentSocket.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Agent/Services/AgentSocket.cs b/Agent/Services/AgentSocket.cs index f61544a1..ca10a1c4 100644 --- a/Agent/Services/AgentSocket.cs +++ b/Agent/Services/AgentSocket.cs @@ -42,7 +42,7 @@ namespace Remotely.Agent.Services private bool IsServerVerified; public AgentSocket(ConfigService configService, - Uninstaller uninstaller, + Uninstaller uninstaller, ScriptExecutor scriptExecutor, ChatClientService chatService, IAppLauncher appLauncher, @@ -101,7 +101,10 @@ namespace Remotely.Agent.Services return; } - await CheckForServerMigration(); + if (await CheckForServerMigration()) + { + return; + } HeartbeatTimer?.Dispose(); HeartbeatTimer = new System.Timers.Timer(TimeSpan.FromMinutes(5).TotalMilliseconds); @@ -152,7 +155,7 @@ namespace Remotely.Agent.Services } } - private async Task CheckForServerMigration() + private async Task CheckForServerMigration() { var serverUrl = await _hubConnection.InvokeAsync("GetServerUrl"); @@ -161,8 +164,12 @@ namespace Remotely.Agent.Services serverUri.Host != savedUri.Host) { _connectionInfo.Host = serverUrl.Trim().TrimEnd('/'); + _connectionInfo.ServerVerificationToken = null; _configService.SaveConnectionInfo(_connectionInfo); + await _hubConnection.DisposeAsync(); + return true; } + return false; } private async void HeartbeatTimer_Elapsed(object sender, ElapsedEventArgs e) {