Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ο»Ώusing System.Text.Json;
using Bit.IntegrationTestCommon.Factories;
using Bit.Sso.IntegrationTest.Utilities;
using Bit.Test.Common.Helpers;
using Xunit;

namespace Bit.Sso.IntegrationTest.Endpoints;

public class SsoConfigurationTests : IClassFixture<SsoApplicationFactory>
{
private readonly SsoApplicationFactory _factory;

public SsoConfigurationTests(SsoApplicationFactory factory)
{
_factory = factory;
}

[Fact]
public async Task WellKnownEndpoint_Success()
{
var context = await _factory.Server.GetAsync("/.well-known/openid-configuration");

using var body = await AssertHelper.AssertResponseTypeIs<JsonDocument>(context);
var endpointRoot = body.RootElement;

// WARNING: Edits to this file should NOT just be made to "get the test to work" they should be made when intentional
// changes were made to this endpoint and proper testing will take place to ensure clients are backwards compatible
// or loss of functionality is properly noted.
await using var fs = File.OpenRead("openid-configuration.json");
using var knownConfiguration = await JsonSerializer.DeserializeAsync<JsonDocument>(fs);
var knownConfigurationRoot = knownConfiguration!.RootElement;

AssertHelper.AssertEqualJson(endpointRoot, knownConfigurationRoot);
}
}
107 changes: 107 additions & 0 deletions bitwarden_license/test/Sso.IntegrationTest/openid-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"issuer": "http://localhost",
"jwks_uri": "http://localhost:51822/.well-known/openid-configuration/jwks",
"authorization_endpoint": "http://localhost:51822/connect/authorize",
"token_endpoint": "http://localhost:51822/connect/token",
"userinfo_endpoint": "http://localhost:51822/connect/userinfo",
"end_session_endpoint": "http://localhost:51822/connect/endsession",
"check_session_iframe": "http://localhost/connect/checksession",
"revocation_endpoint": "http://localhost:51822/connect/revocation",
"introspection_endpoint": "http://localhost:51822/connect/introspect",
"device_authorization_endpoint": "http://localhost:51822/connect/deviceauthorization",
"backchannel_authentication_endpoint": "http://localhost:51822/connect/ciba",
"pushed_authorization_request_endpoint": "http://localhost:51822/connect/par",
"require_pushed_authorization_requests": false,
"frontchannel_logout_supported": true,
"frontchannel_logout_session_supported": true,
"backchannel_logout_supported": true,
"backchannel_logout_session_supported": true,
"scopes_supported": [
"openid",
"profile",
"offline_access"
],
"claims_supported": [
"sub",
"name",
"family_name",
"given_name",
"middle_name",
"nickname",
"preferred_username",
"profile",
"picture",
"website",
"gender",
"birthdate",
"zoneinfo",
"locale",
"updated_at"
],
"grant_types_supported": [
"authorization_code",
"client_credentials",
"refresh_token",
"implicit",
"urn:ietf:params:oauth:grant-type:device_code",
"urn:openid:params:grant-type:ciba"
],
"response_types_supported": [
"code",
"token",
"id_token",
"id_token token",
"code id_token",
"code token",
"code id_token token"
],
"response_modes_supported": [
"form_post",
"query",
"fragment"
],
"token_endpoint_auth_methods_supported": [
"client_secret_basic",
"client_secret_post"
],
"id_token_signing_alg_values_supported": ["RS256"],
"userinfo_signing_alg_values_supported": ["RS256"],
"introspection_signing_alg_values_supported": ["RS256"],
"subject_types_supported": ["public"],
"code_challenge_methods_supported": [
"plain",
"S256"
],
"request_parameter_supported": true,
"request_object_signing_alg_values_supported": [
"RS256",
"RS384",
"RS512",
"PS256",
"PS384",
"PS512",
"ES256",
"ES384",
"ES512"
],
"prompt_values_supported": [
"none",
"login",
"consent",
"select_account"
],
"authorization_response_iss_parameter_supported": true,
"backchannel_token_delivery_modes_supported": ["poll"],
"backchannel_user_code_parameter_supported": true,
"dpop_signing_alg_values_supported": [
"RS256",
"RS384",
"RS512",
"PS256",
"PS384",
"PS512",
"ES256",
"ES384",
"ES512"
]
}
2 changes: 1 addition & 1 deletion src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="SendGrid" Version="9.29.3" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="Duende.IdentityServer" Version="7.2.4" />
<PackageReference Include="Duende.IdentityServer" Version="7.4.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Braintree" Version="5.36.0" />
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Utilities/CoreHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
private static readonly long _baseDateTicks = new DateTime(1900, 1, 1).Ticks;
private static readonly DateTime _epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static readonly DateTime _max = new DateTime(9999, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static readonly Random _random = new Random();

Check warning on line 35 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

Make sure that using this pseudorandom number generator is safe here.
private static readonly string RealConnectingIp = "X-Connecting-IP";
private static readonly Regex _whiteSpaceRegex = new Regex(@"\s+");
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
Expand Down Expand Up @@ -119,7 +119,7 @@
{
// Clean possible garbage characters from thumbprint copy/paste
// ref http://stackoverflow.com/questions/8448147/problems-with-x509store-certificates-find-findbythumbprint
return Regex.Replace(thumbprint, @"[^\da-fA-F]", string.Empty).ToUpper();

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (MsSqlMigratorUtility, ./util, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Setup, ./util, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (EventsProcessor, ./src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Scim, ./bitwarden_license/src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Icons, ./src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Billing, ./src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Api, ./src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Notifications, ./src, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (SeederApi, ./util, linux/amd64,linux/arm64, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check warning on line 122 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Admin, ./src, true, true)

The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.CleanCertificateThumbprint(string)' with a call to 'string.ToUpper(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)
}

public static X509Certificate2? GetCertificate(string thumbprint)
Expand Down Expand Up @@ -248,7 +248,7 @@
if (byteSize < characters.Length)
{
throw new ArgumentException(
string.Format("{0} may contain no more than {1} characters.", nameof(characters), byteSize),

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (MsSqlMigratorUtility, ./util, true)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Setup, ./util, true)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Billing, ./src, true)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Api, ./src, true)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 251 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Admin, ./src, true, true)

The behavior of 'string.Format(string, object, object)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.SecureRandomString(int, string)' with a call to 'string.Format(IFormatProvider, string, params object[])'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
nameof(characters));
}

Expand Down Expand Up @@ -335,14 +335,14 @@
}
else
{
return size.ToString("0 Bytes"); // Byte

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (MsSqlMigratorUtility, ./util, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Setup, ./util, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (EventsProcessor, ./src, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Billing, ./src, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Api, ./src, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Notifications, ./src, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 338 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Admin, ./src, true, true)

The behavior of 'long.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'long.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
}

// Divide by 1024 to get fractional value
readable = (readable / 1024);

// Return formatted number with suffix
return readable.ToString("0.## ") + suffix;

Check warning on line 345 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (EventsProcessor, ./src, true)

The behavior of 'double.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'double.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 345 in src/Core/Utilities/CoreHelpers.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Notifications, ./src, true)

The behavior of 'double.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'CoreHelpers.ReadableBytesSize(long)' with a call to 'double.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
}

/// <summary>
Expand Down Expand Up @@ -680,6 +680,11 @@
public static Dictionary<string, object> AdjustIdentityServerConfig(Dictionary<string, object> configDict,
string publicServiceUri, string internalServiceUri)
{
// Remove metadata for endpoints/features we don't support
configDict.Remove("revocation_endpoint_auth_methods_supported");
configDict.Remove("introspection_endpoint_auth_methods_supported");
configDict.Remove("backchannel_authentication_request_signing_alg_values_supported");

var dictReplace = new Dictionary<string, object>();
foreach (var item in configDict)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ await ssoConfigRepository.CreateAsync(new SsoConfig
new Claim("organizationId", organization.Id.ToString()),
new Claim(JwtClaimTypes.SessionId, "SOMETHING"),
new Claim(JwtClaimTypes.AuthenticationMethod, "external"),
new Claim(JwtClaimTypes.AuthenticationTime, DateTime.UtcNow.AddMinutes(-1).ToEpochTime().ToString())
new Claim(JwtClaimTypes.AuthenticationTime, new DateTimeOffset(DateTime.UtcNow.AddMinutes(-1)).ToUnixTimeSeconds().ToString())
}, "Duende.IdentityServer", JwtClaimTypes.Name, JwtClaimTypes.Role));

authorizationCode.Subject = subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ await ssoConfigRepository.CreateAsync(new SsoConfig
new Claim("organizationId", organization.Id.ToString()),
new Claim(JwtClaimTypes.SessionId, "SOMETHING"),
new Claim(JwtClaimTypes.AuthenticationMethod, "external"),
new Claim(JwtClaimTypes.AuthenticationTime, DateTime.UtcNow.AddMinutes(-1).ToEpochTime().ToString())
new Claim(JwtClaimTypes.AuthenticationTime, new DateTimeOffset(DateTime.UtcNow.AddMinutes(-1)).ToUnixTimeSeconds().ToString())
], "Duende.IdentityServer", JwtClaimTypes.Name, JwtClaimTypes.Role));

authorizationCode.Subject = subject;
Expand Down
5 changes: 1 addition & 4 deletions test/Identity.IntegrationTest/openid-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@
"PS512",
"ES256",
"ES384",
"ES512",
"HS256",
"HS384",
"HS512"
"ES512"
],
"prompt_values_supported": ["none", "login", "consent", "select_account"],
"authorization_response_iss_parameter_supported": true,
Expand Down
Loading