Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guidance when connecting to a SQL Server using untrusted cetrificate #15210

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -136,6 +136,12 @@ private async Task ValidateConnectionAsync(DbConnectionValidatorContext validati
S["The provided connection string is invalid or server is unreachable."]));
break;

case DbConnectionValidatorResult.InvalidCertificate:
errors.Add(new ModelError(
nameof(TenantViewModel.ConnectionString),
S["The security certificate on the server is from a non-trusted source (the certificate issuing authority isn't listed as a trusted authority in Trusted Root Certification Authorities on the client machine). In a development environment, you have the option to use the '{0}' parameter in your connection string to bypass the validation performed by the certificate authority.", "TrustServerCertificate=True"]));
break;

case DbConnectionValidatorResult.DocumentTableFound:
if (validationContext.DatabaseProvider == DatabaseProviderValue.Sqlite)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ public enum DbConnectionValidatorResult
/// <summary>
/// Unsupported database provider.
/// </summary>
UnsupportedProvider
UnsupportedProvider,

/// <summary>
/// The connection was valid but the SSL certificate invalid. The a certificate
/// is from a non-trusted source (the certificate issuing authority isn't listed as a
/// trusted authority in Trusted Root Certification Authorities on the client machine).
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
InvalidCertificate,
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ connection is SqliteConnection sqliteConnection &&
{
_logger.LogWarning(ex, "Unable to validate connection string.");

if (ex is SqlException sqlException
&& sqlException.InnerException?.Message == "The certificate chain was issued by an authority that is not trusted.")
{
return DbConnectionValidatorResult.InvalidCertificate;
}

return DbConnectionValidatorResult.InvalidConnection;
}

Expand Down
3 changes: 3 additions & 0 deletions src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ private async Task<string> SetupInternalAsync(SetupContext context)
case DbConnectionValidatorResult.InvalidConnection:
context.Errors.Add(string.Empty, S["The provided connection string is invalid or server is unreachable."]);
break;
case DbConnectionValidatorResult.InvalidCertificate:
context.Errors.Add(string.Empty, S["The security certificate on the server is from a non-trusted source (the certificate issuing authority isn't listed as a trusted authority in Trusted Root Certification Authorities on the client machine). In a development environment, you have the option to use the '{0}' parameter in your connection string to bypass the validation performed by the certificate authority.", "TrustServerCertificate=True"]);
break;
case DbConnectionValidatorResult.DocumentTableFound:
context.Errors.Add(string.Empty, S["The provided database, table prefix and schema are already in use."]);
break;
Expand Down
Loading