Skip to content

Commit 4c5ec38

Browse files
committed
SymmetricSecurityKey needs 32 bytes
- This could also be worked around with an AppContext switch: "Switch.Microsoft.IdentityModel.UnsafeRelaxHmacKeySizeValidation" - See https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki/IDX10720 for more info
1 parent 39ff459 commit 4c5ec38

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Net.Http;
1414
using System.Net.WebSockets;
1515
using System.Security.Claims;
16+
using System.Security.Cryptography;
1617
using System.Security.Principal;
1718
using System.Text;
1819
using System.Threading;
@@ -2762,7 +2763,7 @@ public async Task ConnectionClosedRequestedTriggeredOnAuthExpiration()
27622763
[InlineData(HttpTransportType.WebSockets)]
27632764
public async Task AuthenticationExpirationSetOnAuthenticatedConnectionWithJWT(HttpTransportType transportType)
27642765
{
2765-
SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(Guid.NewGuid().ToByteArray());
2766+
SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(SHA256.HashData(Guid.NewGuid().ToByteArray()));
27662767
JwtSecurityTokenHandler JwtTokenHandler = new JwtSecurityTokenHandler();
27672768

27682769
using var host = CreateHost(services =>
@@ -2924,7 +2925,7 @@ public async Task AuthenticationExpirationSetOnAuthenticatedConnectionWithCookie
29242925
[InlineData(HttpTransportType.WebSockets)]
29252926
public async Task AuthenticationExpirationUsesCorrectScheme(HttpTransportType transportType)
29262927
{
2927-
var SecurityKey = new SymmetricSecurityKey(Guid.NewGuid().ToByteArray());
2928+
var SecurityKey = new SymmetricSecurityKey(SHA256.HashData(Guid.NewGuid().ToByteArray()));
29282929
var JwtTokenHandler = new JwtSecurityTokenHandler();
29292930

29302931
using var host = CreateHost(services =>

src/SignalR/samples/JwtSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace JwtSample
1818
{
1919
public class Startup
2020
{
21-
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(RandomNumberGenerator.GetBytes(16));
21+
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(RandomNumberGenerator.GetBytes(32));
2222
private readonly JwtSecurityTokenHandler JwtTokenHandler = new JwtSecurityTokenHandler();
2323

2424
public void ConfigureServices(IServiceCollection services)

src/SignalR/server/SignalR/test/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IdentityModel.Tokens.Jwt;
66
using System.IO;
77
using System.Security.Claims;
8+
using System.Security.Cryptography;
89
using System.Threading.Tasks;
910
using Microsoft.AspNetCore.Authentication.JwtBearer;
1011
using Microsoft.AspNetCore.Authorization;
@@ -18,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
1819
{
1920
public class Startup
2021
{
21-
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(Guid.NewGuid().ToByteArray());
22+
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(SHA256.HashData(Guid.NewGuid().ToByteArray()));
2223
private readonly JwtSecurityTokenHandler JwtTokenHandler = new JwtSecurityTokenHandler();
2324

2425
public void ConfigureServices(IServiceCollection services)

0 commit comments

Comments
 (0)