Repository navigation
[gRPC] Use typed API to read certificate DNS names - #69237
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The typed SAN implementation and focused tests address the reviewed behavior without unresolved issues.
Pull request overview
Replaces localized SAN text parsing with typed DER decoding for reliable DNS identity extraction.
Changes:
- Uses
X509SubjectAlternativeNameExtension.EnumerateDnsNames(). - Adds focused certificate tests for filtering, ordering, and delimiter-containing names.
File summaries
| File | Description |
|---|---|
src/Grpc/JsonTranscoding/test/Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests/X509CertificateHelpersTests.cs |
Adds focused certificate coverage. |
src/Grpc/JsonTranscoding/src/Shared/X509CertificateHelpers.cs |
Implements structured SAN DNS extraction. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Youssef1313
reviewed
Sep 15, 2026
DeagleGross
reviewed
Sep 16, 2026
DeagleGross
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #69169
Overview
gRPC JSON transcoding currently derives AuthContext SAN identities by parsing the human-readable output of
X509Extension.Format(). That text varies by OS and culture, and validdNSNamevalues containing formatter-like delimiters can be split or truncated. This change replaces the heuristic with structured DER decoding and adds focused certificate coverage; it changes no public API.Design
None. The affected helper is internal, so no public API or API review is involved.
The implementation uses the framework-provided
X509SubjectAlternativeNameExtensionrather than maintaining a platform-specific parser. This preserves the existing contract—return onlydNSNameentries in encoded order—while making extraction independent of localized display text. Malformed SAN DER continues to surface as an explicit decoding failure rather than being treated as an absent DNS identity and falling back to the certificate common name.Implementation
The removed code called
Format(false), inferred each platform's localized identifier/delimiter/separator from a synthetic extension, then split formatted strings. The replacement delegates DER validation and GeneralName filtering to the X509 API designed for SAN data.Certificate-level tests create real self-signed certificates with DER-encoded SAN extensions and cover these behavior classes:
first.example, DNS Name=second.example) is preserved intact;first.example, DNS:second.example) is preserved intact;CryptographicExceptioninstead of silently enabling common-name fallback.Outcome
Before the fix, the two delimiter-sensitive rows failed independently: the Windows-shaped value became two identities, while the Linux-shaped value was truncated. After the fix, all focused certificate tests pass (5/5), the shipping assembly builds with zero warnings and errors, and the complete JsonTranscoding unit suite passes (305/305).
The canonical
src\Grpc\build.cmd -test -noRestorepath was attempted after generating required JavaScript assets and initializing required submodules, but its framework ref-pack packaging step requireswix.exe, which is unavailable in this environment. Validation therefore built the actual JsonTranscoding assembly and test project against the installed SDK framework with project-reference rebuilding disabled.