Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Use non-case sensitive string for any ids #3184 (#4234)
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Mar 31, 2020
1 parent 3defc11 commit 88afb8f
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/IdentityServer4/host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static IIdentityServerBuilder AddSigningCredential(this IIdentityServerBu
var ecCert = new X509Certificate2("./keys/identityserver.test.ecdsa.p12", "changeit");
var key = new ECDsaSecurityKey(ecCert.GetECDsaPrivateKey())
{
KeyId = CryptoRandom.CreateUniqueId(16)
KeyId = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)
};

return builder.AddSigningCredential(
Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer4/src/Configuration/CryptoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static RsaSecurityKey CreateRsaSecurityKey(int keySize = 2048)
{
return new RsaSecurityKey(RSA.Create(keySize))
{
KeyId = CryptoRandom.CreateUniqueId(16)
KeyId = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)
};
}

Expand All @@ -38,7 +38,7 @@ public static ECDsaSecurityKey CreateECDsaSecurityKey(string curve = JsonWebKeyE
{
return new ECDsaSecurityKey(ECDsa.Create(GetCurveFromCrvValue(curve)))
{
KeyId = CryptoRandom.CreateUniqueId(16)
KeyId = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static string GenerateSessionStateValue(this ValidatedAuthorizeRequest re

var clientId = request.ClientId;
var sessionId = request.SessionId;
var salt = CryptoRandom.CreateUniqueId(16);
var salt = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex);

var uri = new Uri(request.RedirectUri);
var origin = uri.Scheme + "://" + uri.Host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected Task<IEnumerable<Claim>> CreateClaimsForTokenAsync(BackChannelLogoutMo
new Claim(JwtClaimTypes.Subject, client.SubjectId),
new Claim(JwtClaimTypes.Audience, client.ClientId),
new Claim(JwtClaimTypes.IssuedAt, Clock.UtcNow.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64),
new Claim(JwtClaimTypes.JwtId, CryptoRandom.CreateUniqueId(16)),
new Claim(JwtClaimTypes.JwtId, CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)),
new Claim(JwtClaimTypes.Events, json, IdentityServerConstants.ClaimValueTypes.Json)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DefaultHandleGenerationService : IHandleGenerationService
/// <returns></returns>
public Task<string> GenerateAsync(int length)
{
return Task.FromResult(CryptoRandom.CreateUniqueId(length));
return Task.FromResult(CryptoRandom.CreateUniqueId(length, CryptoRandom.OutputFormat.Hex));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public virtual async Task<Token> CreateAccessTokenAsync(TokenCreationRequest req

if (request.ValidatedRequest.Client.IncludeJwtId)
{
claims.Add(new Claim(JwtClaimTypes.JwtId, CryptoRandom.CreateUniqueId(16)));
claims.Add(new Claim(JwtClaimTypes.JwtId, CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)));
}

if (request.ValidatedRequest.SessionId.IsPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public virtual async Task<string> CreateSessionIdAsync(ClaimsPrincipal principal

if (!properties.Items.ContainsKey(SessionIdKey) || currentSubjectId != newSubjectId)
{
properties.Items[SessionIdKey] = CryptoRandom.CreateUniqueId(16);
properties.Items[SessionIdKey] = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex);
}

IssueSessionIdCookie(properties.Items[SessionIdKey]);
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityServer4/src/Test/TestUserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public TestUser AutoProvisionUser(string provider, string userId, List<Claim> cl
}

// create a new unique subject id
var sub = CryptoRandom.CreateUniqueId();
var sub = CryptoRandom.CreateUniqueId(format: CryptoRandom.OutputFormat.Hex);

// check if a display name is available, otherwise fallback to subject id
var name = filtered.FirstOrDefault(c => c.Type == JwtClaimTypes.Name)?.Value ?? sub;
Expand Down

0 comments on commit 88afb8f

Please sign in to comment.