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

SLVS-1674 Improve CertificateChainValidator logging #5867

Merged
Merged
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
Expand Up @@ -41,16 +41,16 @@ public CertificateChainValidator(ILogger logger)
{
this.logger = logger;
}

[ExcludeFromCodeCoverage] // can't easily unit test X509Chain
public bool ValidateChain(X509Certificate2 primaryCertificate, IEnumerable<X509Certificate2> additionalCertificates)
{
logger.LogVerbose($"[{nameof(CertificateChainValidator)}] Validating certificate: " + primaryCertificate);
logger.LogVerbose("[CertificateChainValidator] Validating certificate: " + primaryCertificate);
using var x509Chain = new X509Chain();

foreach (var additionalCertificate in additionalCertificates)
{
logger.LogVerbose($"[{nameof(CertificateChainValidator)}] Using chain certificate: " + primaryCertificate);
logger.LogVerbose("[CertificateChainValidator] Using chain certificate: " + primaryCertificate);

x509Chain.ChainPolicy.ExtraStore.Add(additionalCertificate);
}
Expand All @@ -59,12 +59,13 @@ public bool ValidateChain(X509Certificate2 primaryCertificate, IEnumerable<X509C

if (!validationResult)
{
logger.WriteLine(SLCoreStrings.CertificateValidator_Failed);
foreach (var x509ChainChainStatus in x509Chain.ChainStatus)
{
logger.LogVerbose($"{x509ChainChainStatus.Status}: {x509ChainChainStatus.StatusInformation}");
logger.WriteLine(SLCoreStrings.CertificateValidator_FailureReasonTemplate, x509ChainChainStatus.Status, x509ChainChainStatus.StatusInformation);
}
}

return validationResult;
}
}
19 changes: 18 additions & 1 deletion src/SLCore/SLCoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/SLCore/SLCoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,10 @@
<data name="UnexpectedServerConnectionType" xml:space="preserve">
<value>Unexpected server connection type</value>
</data>
<data name="CertificateValidator_Failed" xml:space="preserve">
<value>[CertificateChainValidator] Certificate validation failed for the following reason(s):</value>
</data>
<data name="CertificateValidator_FailureReasonTemplate" xml:space="preserve">
<value>[CertificateChainValidator] {0}: {1}</value>
</data>
</root>