Ensure SSL_CERT_DIR messages are always shown and check for existing value#28
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
WalkthroughThis pull request enhances certificate generation logging with improved OpenSSL SSL_CERT_DIR validation on Unix platforms. It adds two new EventSource events to log directory configuration status, refactors event listener initialization in the dev-certs tool, and strengthens the Unix certificate manager's validation logic for environment variable handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Shared/CertificateGeneration/UnixCertificateManager.cs`:
- Around line 362-382: The comparison uses prettyCertDir (which may contain
"$HOME" or "~") and performs a case-insensitive compare; fix by first expanding
environment variables and tilde in prettyCertDir (e.g., use
Environment.ExpandEnvironmentVariables and replace a leading "~" with HOME) to
produce the real path, then call Path.GetFullPath on that expanded path (update
certDirFullPath to the expanded/full path), and in the isCertDirIncluded lambda
compare using case-sensitive comparison (StringComparison.Ordinal) when checking
Path.GetFullPath(dir) against certDirFullPath; update code in
UnixCertificateManager where prettyCertDir, certDirFullPath and
isCertDirIncluded are used.
🧹 Nitpick comments (1)
src/Shared/CertificateGeneration/UnixCertificateManager.cs (1)
994-1007: Consider using arecordor auto-properties for brevity.This private class could be simplified using modern C# features while maintaining immutability.
♻️ Optional simplification using record
- private sealed class NssDb - { - 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; - } + private sealed record NssDb(string Path, bool IsFirefox);
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Shared/CertificateGeneration/CertificateManager.cssrc/Shared/CertificateGeneration/UnixCertificateManager.cssrc/Tools/dotnet-dev-certs/src/Program.cs
🧰 Additional context used
🧬 Code graph analysis (1)
src/Tools/dotnet-dev-certs/src/Program.cs (1)
src/Shared/CommandLineUtils/CommandLine/CommandOption.cs (1)
HasValue(93-96)
🔇 Additional comments (3)
src/Shared/CertificateGeneration/CertificateManager.cs (1)
1302-1320: LGTM!The new events are well-designed:
- Event 113 at
Verboselevel correctly logs when the directory is already configured (informational)- Event 114 at
LogAlwayslevel ensures users always see the guidance to append to an existingSSL_CERT_DIR- The shell example in event 114 (
export {1}=\"{0}:${1}\") correctly uses${1}as shell variable expansion to preserve the existing valuesrc/Tools/dotnet-dev-certs/src/Program.cs (2)
127-135: LGTM!The event listener initialization change correctly ensures that
EventLevel.LogAlwaysevents (including the new SSL_CERT_DIR guidance messages) are always captured and displayed to users, even when--verboseis not specified. This aligns well with the PR objective to ensure SSL_CERT_DIR messages are always shown.
139-141: No functional change - formatting only.The
||operator moved to the previous line is a stylistic change with no impact on behavior.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| 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); | ||
| } | ||
| catch | ||
| { | ||
| // Ignore invalid directory entries in SSL_CERT_DIR | ||
| return false; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Bug: Using display string prettyCertDir instead of actual path for comparison.
prettyCertDir may contain the literal string $HOME (from lines 354-356) which Path.GetFullPath won't expand. This causes incorrect path comparisons.
Additionally, StringComparison.OrdinalIgnoreCase is used on line 375, but Unix/Linux filesystems are case-sensitive, which could cause false matches.
🐛 Proposed fix
if (!string.IsNullOrEmpty(existingSslCertDir))
{
var existingDirs = existingSslCertDir.Split(Path.PathSeparator);
- var certDirFullPath = Path.GetFullPath(prettyCertDir);
+ var certDirFullPath = Path.GetFullPath(certDir);
var isCertDirIncluded = existingDirs.Any(dir =>
{
if (string.IsNullOrWhiteSpace(dir))
{
return false;
}
try
{
- return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase);
+ return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.Ordinal);
}
catch
{
// Ignore invalid directory entries in SSL_CERT_DIR
return false;
}
});🤖 Prompt for AI Agents
In `@src/Shared/CertificateGeneration/UnixCertificateManager.cs` around lines 362
- 382, The comparison uses prettyCertDir (which may contain "$HOME" or "~") and
performs a case-insensitive compare; fix by first expanding environment
variables and tilde in prettyCertDir (e.g., use
Environment.ExpandEnvironmentVariables and replace a leading "~" with HOME) to
produce the real path, then call Path.GetFullPath on that expanded path (update
certDirFullPath to the expanded/full path), and in the isCertDirIncluded lambda
compare using case-sensitive comparison (StringComparison.Ordinal) when checking
Path.GetFullPath(dir) against certDirFullPath; update code in
UnixCertificateManager where prettyCertDir, certDirFullPath and
isCertDirIncluded are used.
Benchmark PR from agentic-review-benchmarks#3
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.