diff options
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 24 |
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); |
