aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-12-17 16:38:28 -0600
committerJP Dillingham <jp@dillingham.me>2023-12-17 16:38:28 -0600
commit6916575a936c47a936e547ba6a9ee486703e16aa (patch)
tree29e7e27d4daf4a445f3b7367386e43c4035f45b8 /src/slskd/Program.cs
parentf37b99eb40e30475b228235341b74b5055db3ecd (diff)
downloadslskd-6916575a936c47a936e547ba6a9ee486703e16aa.tar.gz
pad jwt keys to 32 characters
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index ca991e3c..b17ba6aa 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -627,7 +627,16 @@ namespace slskd
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(DataDirectory, "misc", ".DataProtection-Keys")));
- var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(OptionsAtStartup.Web.Authentication.Jwt.Key));
+ var adjustedJwtKey = OptionsAtStartup.Web.Authentication.Jwt.Key;
+
+ // the JWT key must be at least 256 bits in length, due to the HMACSHA256 algorithm being used for signing.
+ if (adjustedJwtKey.Length < 32)
+ {
+ adjustedJwtKey = adjustedJwtKey.PadRight(32, ' ');
+ Log.Warning("The configured JWT signing key is less than the required 32 characters and has been padded with spaces to make up the difference. The minimum length will be raised from 16 to 32 in a future release, and this will become an error.");
+ }
+
+ var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(adjustedJwtKey));
services.AddSingleton(jwtSigningKey);
services.AddSingleton<ISecurityService, SecurityService>();