-
Notifications
You must be signed in to change notification settings - Fork 0
Ensure SSL_CERT_DIR messages are always shown and check for existing value #3
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
base: claude_claude_vs_qodo_base_ensure_ssl_cert_dir_messages_are_always_shown_and_check_for_existing_value_pr3
Are you sure you want to change the base?
Changes from all commits
fade7c7
60be2ab
9fd206b
35584d7
c8ce09d
07d6e09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -355,14 +355,57 @@ protected override TrustLevel TrustCertificateCore(X509Certificate2 certificate) | |
| ? Path.Combine("$HOME", certDir[homeDirectoryWithSlash.Length..]) | ||
| : certDir; | ||
|
|
||
| if (TryGetOpenSslDirectory(out var openSslDir)) | ||
| var hasValidSslCertDir = false; | ||
|
|
||
| // Check if SSL_CERT_DIR is already set and if certDir is already included | ||
|
Comment on lines
+358
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Bug: Line 408 uses Extended reasoning...What the bug isIn The specific code path that triggers itConsider this scenario:
Why existing code does not prevent itThe check at lines 333-344 correctly detects the partial failure state and logs it, but it intentionally does not return early when there has been partial success (to allow for the SSL_CERT_DIR messaging). This is by design -- the method is supposed to continue and return ImpactWhen trust partially fails (e.g., NSS DB trust for Firefox fails, but OpenSSL and dotnet trust succeed) AND the certificate directory is already in How to fixChange line 408 from: sawTrustFailure = !hasValidSslCertDir;to: sawTrustFailure |= !hasValidSslCertDir;The |
||
| var existingSslCertDir = Environment.GetEnvironmentVariable(OpenSslCertificateDirectoryVariableName); | ||
| if (!string.IsNullOrEmpty(existingSslCertDir)) | ||
| { | ||
| var existingDirs = existingSslCertDir.Split(Path.PathSeparator); | ||
| var certDirFullPath = Path.GetFullPath(prettyCertDir); | ||
| var isCertDirIncluded = existingDirs.Any(dir => | ||
| { | ||
| if (string.IsNullOrWhiteSpace(dir)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase); | ||
|
Comment on lines
+365
to
+375
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Extended reasoning...Bug 1:
|
||
| } | ||
| catch | ||
| { | ||
| // Ignore invalid directory entries in SSL_CERT_DIR | ||
| return false; | ||
| } | ||
| }); | ||
|
|
||
| if (isCertDirIncluded) | ||
| { | ||
| // The certificate directory is already in SSL_CERT_DIR, no action needed | ||
| Log.UnixOpenSslCertificateDirectoryAlreadyConfigured(prettyCertDir, OpenSslCertificateDirectoryVariableName); | ||
| hasValidSslCertDir = true; | ||
| } | ||
| else | ||
| { | ||
| // SSL_CERT_DIR is set but doesn't include our directory - suggest appending | ||
| Log.UnixSuggestAppendingToEnvironmentVariable(prettyCertDir, OpenSslCertificateDirectoryVariableName); | ||
| hasValidSslCertDir = false; | ||
| } | ||
| } | ||
| else if (TryGetOpenSslDirectory(out var openSslDir)) | ||
| { | ||
| Log.UnixSuggestSettingEnvironmentVariable(prettyCertDir, Path.Combine(openSslDir, "certs"), OpenSslCertificateDirectoryVariableName); | ||
| hasValidSslCertDir = false; | ||
| } | ||
| else | ||
| { | ||
| Log.UnixSuggestSettingEnvironmentVariableWithoutExample(prettyCertDir, OpenSslCertificateDirectoryVariableName); | ||
| hasValidSslCertDir = false; | ||
| } | ||
|
|
||
| sawTrustFailure = !hasValidSslCertDir; | ||
| } | ||
|
|
||
| return sawTrustFailure | ||
|
|
@@ -948,9 +991,18 @@ private static bool TryRehashOpenSslCertificates(string certificateDirectory) | |
| return true; | ||
| } | ||
|
|
||
| private sealed class NssDb(string path, bool isFirefox) | ||
| private sealed class NssDb | ||
| { | ||
| public string Path => path; | ||
| public bool IsFirefox => isFirefox; | ||
| private readonly string _path; | ||
| private readonly bool _isFirefox; | ||
|
|
||
| public NssDb(string path, bool isFirefox) | ||
| { | ||
| _path = path; | ||
| _isFirefox = isFirefox; | ||
| } | ||
|
|
||
| public string Path => _path; | ||
| public bool IsFirefox => _isFirefox; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,16 +124,20 @@ public static int Main(string[] args) | |
| { | ||
| var reporter = new ConsoleReporter(PhysicalConsole.Singleton, verbose.HasValue(), quiet.HasValue()); | ||
|
|
||
| var listener = new ReporterEventListener(reporter); | ||
| if (verbose.HasValue()) | ||
| { | ||
| var listener = new ReporterEventListener(reporter); | ||
| listener.EnableEvents(CertificateManager.Log, System.Diagnostics.Tracing.EventLevel.Verbose); | ||
| } | ||
| else | ||
| { | ||
| listener.EnableEvents(CertificateManager.Log, System.Diagnostics.Tracing.EventLevel.LogAlways); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Extended reasoning...The BugOn line 134 of How EventSource Filtering WorksThe if ((int)m_level != 0) {
if ((int)m_level < (int)level) return false;
}When Step-by-Step Proof
ImpactThe Git History Confirms the RegressionCommit 60be2ab ("Use critical for log level filter") correctly changed FixChange listener.EnableEvents(CertificateManager.Log, System.Diagnostics.Tracing.EventLevel.Critical);This enables only |
||
| } | ||
|
|
||
| if (checkJsonOutput.HasValue()) | ||
| { | ||
| if (exportPath.HasValue() || trust?.HasValue() == true || format.HasValue() || noPassword.HasValue() || check.HasValue() || clean.HasValue() || | ||
| (!import.HasValue() && password.HasValue()) || | ||
| (!import.HasValue() && password.HasValue()) || | ||
| (import.HasValue() && !password.HasValue())) | ||
| { | ||
| reporter.Error(InvalidUsageErrorMessage); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 Pre-existing bug: Event 111 (
UnixSuggestSettingEnvironmentVariableWithoutExample) message uses{2}placeholder but the method only accepts 2 parameters (certDir={0},envVarName={1}), so{2}has no corresponding argument. This will cause aFormatExceptionat runtime whenstring.FormatinReporterEventListener.OnEventWrittentries to resolve{2}with only 2 payload items. The fix is to change{2}to{1}in the message string. This is a pre-existing issue not introduced by this PR, but it is directly adjacent to the modified Event 110.Extended reasoning...
What the bug is
Event 111 (
UnixSuggestSettingEnvironmentVariableWithoutExample) inCertificateManager.cshas a message string that references placeholder{2}:The method only has two parameters:
certDir(index 0) andenvVarName(index 1). There is no parameter at index 2.How it manifests at runtime
In
ReporterEventListener.OnEventWritten(ReporterEventListener.cs:33), the event message is formatted using:When Event 111 fires,
string.Formatreceives a format string containing{2}but only a 2-element payload array (indices 0 and 1). This causes aFormatExceptionto be thrown at runtime.Step-by-step proof
dotnet dev-certs https --truston Linux without--verbose.SSL_CERT_DIRis not set.TryGetOpenSslDirectoryreturns false (e.g., OpenSSL is not installed or returns an unexpected format).elsebranch inUnixCertificateManager.TrustCertificateCore, callingLog.UnixSuggestSettingEnvironmentVariableWithoutExample(prettyCertDir, OpenSslCertificateDirectoryVariableName).ReporterEventListenerreceives Event 111 withPayload = [prettyCertDir, "SSL_CERT_DIR"](2 items).string.Formattries to resolve{2}in the message but there is no index 2 in the payload array.FormatExceptionis thrown, crashing the event listener.Why existing code does not prevent it
The
EventSourceinfrastructure does not validate that format string placeholders match method parameter counts at compile time. The mismatch is only caught at runtime when the message is actually formatted. Previously this event was only delivered when--verbosewas passed (the old code only created the listener in verbose mode), making this harder to hit. With this PR now enabling event listening in non-verbose mode atEventLevel.LogAlways, Event 111 (which isLogAlwayslevel) will always be delivered to the listener, making this crash more likely to be exercised.Impact
When a user trusts a dev certificate on Linux and
TryGetOpenSslDirectoryfails, the tool will crash with aFormatExceptioninstead of showing a helpful message about settingSSL_CERT_DIR.Fix
Change
{2}to{1}in the Event 111 message string, sinceenvVarNameis the second parameter (index 1). Compare with the sibling Event 110, where{2}correctly maps to the third parameterenvVarName(which is the third of three parameters in that method).