From 20b800a3bdd9b0022b0e1870364980068c3d4adf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 26 Oct 2022 09:56:38 -0500 Subject: tweak auth --- src/slskd/Network/API/Hubs/NetworkHub.cs | 2 +- src/slskd/Network/NetworkService.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/slskd/Network/API/Hubs/NetworkHub.cs b/src/slskd/Network/API/Hubs/NetworkHub.cs index e654f795..298dd9ec 100644 --- a/src/slskd/Network/API/Hubs/NetworkHub.cs +++ b/src/slskd/Network/API/Hubs/NetworkHub.cs @@ -66,7 +66,7 @@ namespace slskd.Network public bool Login(string agent, string challengeResponse) { - if (Network.TryValidateAuthenticationChallengeResponse(Context.ConnectionId, agent, challengeResponse)) + if (Network.TryValidateAuthenticationCredential(Context.ConnectionId, agent, challengeResponse)) { var remoteIp = Context.Features.Get().RemoteIpAddress.ToString(); var record = new Agent { Name = agent, ConnectedAt = DateTime.UtcNow, IPAddress = remoteIp }; diff --git a/src/slskd/Network/NetworkService.cs b/src/slskd/Network/NetworkService.cs index 0a3079ae..100d9448 100644 --- a/src/slskd/Network/NetworkService.cs +++ b/src/slskd/Network/NetworkService.cs @@ -187,9 +187,9 @@ namespace slskd.Network /// /// The ID of the agent connection. /// The agent name. - /// The challenge response provided by the agent. + /// The response credential. /// A value indicating whether the response is valid. - bool TryValidateAuthenticationChallengeResponse(string connectionId, string agentName, string challengeResponse); + bool TryValidateAuthenticationCredential(string connectionId, string agentName, string credential); /// /// Attempts to validate the file stream response credential associated with the specified . @@ -257,7 +257,7 @@ namespace slskd.Network var token = Cryptography.Random.GetBytes(32).ToBase62(); // this token is only valid for this connection id for a short time this is important to prevent replay-type attacks. - MemoryCache.Set(GetAuthTokenCacheKey(connectionId), token, TimeSpan.FromMinutes(1)); + MemoryCache.Set(GetAuthTokenCacheKey(connectionId), token, TimeSpan.FromSeconds(10)); Log.Debug("Cached auth token {Token} for ID {Id}", token, connectionId); return token; } @@ -532,9 +532,9 @@ namespace slskd.Network /// /// The ID of the agent connection. /// The agent name. - /// The challenge response provided by the agent. + /// The response credential. /// A value indicating whether the response is valid. - public bool TryValidateAuthenticationChallengeResponse(string connectionId, string agentName, string challengeResponse) + public bool TryValidateAuthenticationCredential(string connectionId, string agentName, string credential) { if (!MemoryCache.TryGetValue(GetAuthTokenCacheKey(connectionId), out var challengeToken)) { @@ -552,7 +552,7 @@ namespace slskd.Network var tokenBytes = ((string)challengeToken).FromBase62(); var expectedResponse = Aes.Encrypt(tokenBytes, key).ToBase62(); - return expectedResponse == challengeResponse; + return expectedResponse == credential; } /// -- cgit v1.2.3