diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-10-22 12:13:04 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-10-22 12:13:04 -0500 |
| commit | 1d927e49a93ad24ba6dbc91f30f185212775ff30 (patch) | |
| tree | b737ee4a2e83f2451175337d96835548c025cffc /src | |
| parent | 1e27fdb2e5de7de63fdabcd2b36607658edd2bf7 (diff) | |
| download | slskd-1d927e49a93ad24ba6dbc91f30f185212775ff30.tar.gz | |
update routes, provide credentials in rest calls
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Network/NetworkClient.cs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/slskd/Network/NetworkClient.cs b/src/slskd/Network/NetworkClient.cs index 1c2515d2..6a2a374d 100644 --- a/src/slskd/Network/NetworkClient.cs +++ b/src/slskd/Network/NetworkClient.cs @@ -134,9 +134,10 @@ namespace slskd.Network var stream = new FileStream(temp, FileMode.Open, FileAccess.Read); - using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v0/network/shares/{token}"); + using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v0/network/shares/{OptionsMonitor.CurrentValue.InstanceName}/{token}"); using var content = new MultipartFormDataContent { + { new StringContent(ComputeCredential(token)), "credential" }, { new StringContent(Shares.LocalHost.Shares.ToJson()), "shares" }, { new StreamContent(stream), "database", "shares" }, }; @@ -154,9 +155,19 @@ namespace slskd.Network Log.Information("Upload shares succeeded"); } - private async Task HandleFileRequest(string filename, Guid id) + private string ComputeCredential(Guid token) { - Log.Information("Network controller requested file {Filename} with ID {Id}", filename, id); + var options = OptionsMonitor.CurrentValue; + + var key = options.Network.Controller.Secret.FromBase62(); + var tokenBytes = token.ToString().FromBase62(); + + return Aes.Encrypt(tokenBytes, key).ToBase62(); + } + + private async Task HandleFileRequest(string filename, Guid token) + { + Log.Information("Network controller requested file {Filename} with ID {Id}", filename, token); try { @@ -171,15 +182,16 @@ namespace slskd.Network } using var stream = new FileStream(localFileInfo.FullName, FileMode.Open, FileAccess.Read); - using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v0/network/files/{id}"); + using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v0/network/files/{OptionsMonitor.CurrentValue.InstanceName}/{token}"); using var content = new MultipartFormDataContent { + { new StringContent(ComputeCredential(token)), "credential" }, { new StreamContent(stream), "file", filename }, }; request.Content = content; - Log.Information("Beginning upload of file {Filename} with ID {Id}", filename, id); + Log.Information("Beginning upload of file {Filename} with ID {Id}", filename, token); var response = await CreateHttpClient().SendAsync(request); if (!response.IsSuccessStatusCode) @@ -196,7 +208,7 @@ namespace slskd.Network Log.Error(ex, "Failed to handle file request: {Message}", ex.Message); // report the failure to the controller. this avoids a failure due to timeout. - await HubConnection.InvokeAsync(nameof(NetworkHub.NotifyUploadFailed), id); + await HubConnection.InvokeAsync(nameof(NetworkHub.NotifyUploadFailed), token); } } |
