aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-08 13:30:10 -0600
committerGitHub <noreply@github.com>2023-01-08 13:30:10 -0600
commitbbbde98f571dc7cd7a0ed35ef7846cc177372920 (patch)
treed711d033bf604444519f98d9854b67d412efcacf /src/slskd/Program.cs
parent9bb9c17312742adb65b37fe84bd64e7267defcd8 (diff)
parent5133ac9eabc1ddf195002807f97a95ad0ab8d9a0 (diff)
downloadslskd-bbbde98f571dc7cd7a0ed35ef7846cc177372920.tar.gz
Merge branch 'master' into relay-docs
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index d0b670a2..66773cb5 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -243,7 +243,17 @@ namespace slskd
// populate the properties above so that we can override the default config file if needed, and to
// check if the application is being run in command mode (run task and quit).
EnvironmentVariables.Populate(prefix: EnvironmentVariablePrefix);
+
+ try
+ {
Arguments.Populate(clearExistingValues: false);
+ }
+ catch (Exception ex)
+ {
+ // this is pretty hacky, but i don't have a good way of trapping errors that bubble up here.
+ Log.Error($"Invalid command line input: {ex.Message.Replace(". See inner exception for details.", string.Empty)}");
+ return;
+ }
// if a user has used one of the arguments above, perform the requested task, then quit
if (ShowVersion)
@@ -283,6 +293,12 @@ namespace slskd
if (GenerateSecret > 0)
{
+ if (GenerateSecret < 16 || GenerateSecret > 255)
+ {
+ Log.Error("Invalid command line input: secret length must be between 16 and 255, inclusive");
+ return;
+ }
+
Log.Information(Cryptography.Random.GetBytes(GenerateSecret).ToBase62());
return;
}
@@ -671,7 +687,7 @@ namespace slskd
}
catch
{
- // the token either isn't a valid API key. use the provided value and let the
+ // the token either isn't a valid API key. use the provided value and let the
// rest of the auth middleware figure out whether it is valid
context.Token = token;
}
@@ -696,6 +712,12 @@ namespace slskd
policy.RequireAuthenticatedUser();
});
+ options.AddPolicy(AuthPolicy.ApiKeyOnly, policy =>
+ {
+ policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+
options.AddPolicy(AuthPolicy.JwtOnly, policy =>
{
policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);