From c0a6cf3f2e5e49314d93749194ebf5ca37796b9a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 2 Oct 2022 15:25:03 -0500 Subject: add a command to generate api keys --- src/slskd/Program.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 8dbf39ff..2d41ee93 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -207,6 +207,9 @@ namespace slskd [Argument('g', "generate-cert", "generate X509 certificate and password for HTTPs")] private static bool GenerateCertificate { get; set; } + [Argument('k', "generate-api-key", "generate a random API key")] + private static bool GenerateApiKey { get; set; } + [Argument('n', "no-logo", "suppress logo on startup")] private static bool NoLogo { get; set; } @@ -263,6 +266,12 @@ namespace slskd return; } + if (GenerateApiKey) + { + Log.Information($"API Key: {Cryptography.Random.GetBytes(32).ToBase62String()}"); + return; + } + // the application isn't being run in command mode. derive the application directory value // and defaults that are dependent upon it AppDirectory ??= DefaultAppDirectory; @@ -945,8 +954,8 @@ namespace slskd var cert = X509.Generate(subject: AppName, password, X509KeyStorageFlags.Exportable); IOFile.WriteAllBytes(filename, cert.Export(X509ContentType.Pkcs12, password)); - Log.Information($"Password: {password}"); Log.Information($"Certificate exported to {filename}"); + Log.Information($"Password: {password}"); } private static void PrintCommandLineArguments(Type targetType) -- cgit v1.2.3