Skip to content

Conversation

@vcsjones
Copy link
Member

@vcsjones vcsjones commented Dec 26, 2025

OpenSSL marked a few methods that could return const as requiring const. Add const qualifiers where needed.

If we fix this now, we can keep scouting against openssl's main branch.

Fixes vcsjones/runtime-ci#9.

OpenSSL marked a few methods that could return const as requiring const. Add const qualifiers where needed.
Copilot AI review requested due to automatic review settings December 26, 2025 17:16
if (x509)
{
X509_PUBKEY* pubkey = X509_get_X509_PUBKEY(x509);
const X509_PUBKEY* pubkey = X509_get_X509_PUBKEY(x509);
Copy link
Member Author

@vcsjones vcsjones Dec 26, 2025

Choose a reason for hiding this comment

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

This is only used by X509_PUBKEY_get0_param below, which already has the parameter qualified as const, so we can just mark our variable as const and it will still work for the call.

Okay, that is not true with OpenSSL 1.1.x. We are going to have to discard the qualifiers.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the System.Security.Cryptography.Native bindings to be compatible with OpenSSL 4.0-dev by adding const qualifiers to function signatures and local variables where OpenSSL now requires them.

Key Changes:

  • Updated CryptoNative_GetX509PublicKeyBytes return type to return const ASN1_BIT_STRING*
  • Added const qualifiers to local X509_PUBKEY* variables in two functions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/native/libs/System.Security.Cryptography.Native/openssl.h Updated function signature for CryptoNative_GetX509PublicKeyBytes to return const pointer
src/native/libs/System.Security.Cryptography.Native/openssl.c Added const qualifiers to function implementation and local variables to match OpenSSL 4.0-dev API requirements

the public key.
*/
ASN1_BIT_STRING* CryptoNative_GetX509PublicKeyBytes(X509* x509)
const ASN1_BIT_STRING* CryptoNative_GetX509PublicKeyBytes(X509* x509)
Copy link
Member Author

Choose a reason for hiding this comment

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

This interior pointer is later fed in to CryptoNative_GetAsn1StringBytes which does not modify the structure. So while the const is "erased" across the p/invoke boundary, the uses of the interior pointer do not violate the const requirement.

@dotnet-policy-service
Copy link
Contributor

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

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.

Build Failure for run 20505620371

1 participant