Ensure SSL_CERT_DIR messages are always shown and check for existing value#26
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Code Review by Qodo
1. prettyCertDir used for fullpath
|
| ? 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 | ||
| 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); | ||
| } | ||
| 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; | ||
| } |
There was a problem hiding this comment.
1. prettycertdir used for fullpath 📘 Rule violation ✓ Correctness
• The code computes certDirFullPath from prettyCertDir, which may be rewritten to start with $HOME for display purposes. • When prettyCertDir contains $HOME, Path.GetFullPath(prettyCertDir) will not expand $HOME and can resolve to an unrelated path, causing isCertDirIncluded to be computed incorrectly. • This breaks edge-case handling for common home-directory installs and can incorrectly mark trust as failed (sawTrustFailure = !hasValidSslCertDir).
Agent prompt
## Issue description
`Path.GetFullPath(prettyCertDir)` uses a display-friendly `$HOME`-prefixed string to compute `certDirFullPath`, which can mis-resolve paths and incorrectly decide whether `SSL_CERT_DIR` already includes the certificate directory.
## Issue Context
`prettyCertDir` is intended for messaging, but it is used for filesystem comparison (`certDirFullPath`). On Unix, `$HOME` is not expanded by `GetFullPath`, so the comparison can fail even when `SSL_CERT_DIR` is correctly configured.
## Fix Focus Areas
- src/Shared/CertificateGeneration/UnixCertificateManager.cs[354-409]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| sawTrustFailure = !hasValidSslCertDir; | ||
| } |
There was a problem hiding this comment.
2. Trustlevel can be wrong 🐞 Bug ✓ Correctness
• TrustCertificateCore accumulates failures across .NET/OpenSSL/NSS trust steps, but the new SSL_CERT_DIR block overwrites sawTrustFailure based only on the env-var check. • If NSS trust (or .NET trust) failed earlier but SSL_CERT_DIR is configured, the final result may incorrectly become TrustLevel.Full. • This can also create inconsistent output (logging “partially succeeded” but returning Full).
Agent prompt
### Issue description
`TrustCertificateCore` overwrites `sawTrustFailure` based only on the SSL_CERT_DIR check, losing prior failures from other trust mechanisms (e.g., NSS trust failures). This can cause incorrect `TrustLevel.Full` results.
### Issue Context
`sawTrustFailure` is used as the final gate for returning `TrustLevel.Partial` vs `TrustLevel.Full`. It must represent *any* failures encountered across all trust targets.
### Fix Focus Areas
- src/Shared/CertificateGeneration/UnixCertificateManager.cs[346-414]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#3