Skip to content

OpenSSL 4.1 compatibility - #137288

Merged
vcsjones merged 5 commits into
dotnet:mainfrom
vcsjones:ossl41-compat
Nov 17, 2026
Merged

vcsjones merged 5 commits into
dotnet:mainfrom
vcsjones:ossl41-compat

Conversation

@vcsjones

@vcsjones vcsjones commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

This makes a couple of fixes that addresses .NET compatibility with OpenSSL 4.1.

  1. X509_check_hostname now requires opting in to using the subject of the certificate - only the Subject Alternative Name extension is considered. This is not quite as simple as "pass a flag" - it's explained in comments for posterity.
  2. OpenSSL reports X509_V_ERR_DUPLICATE_EXTENSION for certificates with duplicate extensions. .NET today does not error for this, and nor do we have a good way to map it. We also ignore it for macOS currently. We can error for duplicate extensions if we want to, but that would 1) be something that can't be back ported and 2) needs to change for macOS as well, so it should be done separately from this pull request, if at all.

Fixes #137209

@vcsjones vcsjones added this to the 12.0.0 milestone Nov 10, 2026
@vcsjones
vcsjones requested review from bartonjs and a balanced review from Copilot November 10, 2026 21:45
@vcsjones vcsjones self-assigned this Nov 10, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new ignored-error path lacks regression coverage confirming that duplicate noncritical extensions are accepted on OpenSSL 4.1 while independent errors, such as expiration, are still reported.

1 open issue
What changed in this PR

This PR preserves existing .NET certificate-validation behavior when using OpenSSL 4.1.

Changes:

  • Restores hostname common-name fallback when no DNS Subject Alternative Name exists, including IP-literal compatibility checks.
  • Ignores OpenSSL’s duplicate-extension error while retaining other chain-validation errors.
  • Adds OpenSSL 4.x error definitions and expands chain-error storage to 128 bits.
File Description
src/​native/​libs/​System.Security.Cryptography.Native/​opensslshim.h Adds the OpenSSL 4.1 version constant.
src/​native/​libs/​System.Security.Cryptography.Native/​openssl.c Centralizes hostname checks and restores conditional subject fallback.
src/​libraries/​System.Security.Cryptography/​src/​System/​Security/​Cryptography/​X509Certificates/​OpenSslX509ChainProcessor.cs Suppresses duplicate-extension errors and expands error storage.
src/​libraries/​Common/​src/​Interop/​Unix/​System.Security.Cryptography.Native/​Interop.X509.cs Adds OpenSSL 4.x verification codes and renames the 3.x code definitions.

Review effort: Balanced

Parenthesize the complete cast expressions so direct member access
applies to the typed pointers returned by the stack accessors.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

@vcsjones
vcsjones merged commit 014646c into dotnet:main Nov 17, 2026
71 of 73 checks passed
@vcsjones

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@vcsjones

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@vcsjones backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 014646c4ceb68fe5b705f27db6a431c7227a718a

Auto-merging src/native/libs/System.Security.Cryptography.Native/openssl.c
CONFLICT (content): Merge conflict in src/native/libs/System.Security.Cryptography.Native/openssl.c
Auto-merging src/native/libs/System.Security.Cryptography.Native/opensslshim.h
error: could not apply 014646c4ceb... OpenSSL 4.1 compatibility
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Restore subject name matching with OpenSSL 4.1
Using index info to reconstruct a base tree...
M	src/native/libs/System.Security.Cryptography.Native/openssl.c
M	src/native/libs/System.Security.Cryptography.Native/opensslshim.h
Falling back to patching base and 3-way merge...
Auto-merging src/native/libs/System.Security.Cryptography.Native/openssl.c
CONFLICT (content): Merge conflict in src/native/libs/System.Security.Cryptography.Native/openssl.c
Auto-merging src/native/libs/System.Security.Cryptography.Native/opensslshim.h
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Restore subject name matching with OpenSSL 4.1
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@github-actions

Copy link
Copy Markdown
Contributor

@vcsjones backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 014646c4ceb68fe5b705f27db6a431c7227a718a

Auto-merging src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs
Auto-merging src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs
CONFLICT (content): Merge conflict in src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs
Auto-merging src/native/libs/System.Security.Cryptography.Native/openssl.c
CONFLICT (content): Merge conflict in src/native/libs/System.Security.Cryptography.Native/openssl.c
Auto-merging src/native/libs/System.Security.Cryptography.Native/opensslshim.h
error: could not apply 014646c4ceb... OpenSSL 4.1 compatibility
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Restore subject name matching with OpenSSL 4.1
Using index info to reconstruct a base tree...
M	src/native/libs/System.Security.Cryptography.Native/openssl.c
M	src/native/libs/System.Security.Cryptography.Native/opensslshim.h
Falling back to patching base and 3-way merge...
Auto-merging src/native/libs/System.Security.Cryptography.Native/openssl.c
CONFLICT (content): Merge conflict in src/native/libs/System.Security.Cryptography.Native/openssl.c
Auto-merging src/native/libs/System.Security.Cryptography.Native/opensslshim.h
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Restore subject name matching with OpenSSL 4.1
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X509Certificates.Tests.HostnameMatchTests tests fail against OpenSSL 4.1

3 participants