Skip to content

fix: OpenSSL 4.0 — use ASN1_STRING accessors instead of direct struct member access#61

Open
jonasbn wants to merge 8 commits into
masterfrom
fix/openssl-4-opaque-asn1
Open

fix: OpenSSL 4.0 — use ASN1_STRING accessors instead of direct struct member access#61
jonasbn wants to merge 8 commits into
masterfrom
fix/openssl-4-opaque-asn1

Conversation

@jonasbn

@jonasbn jonasbn commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • OpenSSL 4.0 made struct asn1_string_st (backing type for ASN1_BMPSTRING, ASN1_UTF8STRING, ASN1_OCTET_STRING, ASN1_BIT_STRING) opaque, breaking direct ->data/->length access in print_attribute() — Debian bug #1138300, closes OpenSSL 4.0 compatibility: print_attribute uses direct ASN1_STRING struct member access #57, closes Build failure with OpenSSL 4.0 #60.
  • Added a compat macro ASN1_STRING_get0_data in the existing #if OPENSSL_VERSION_NUMBER < 0x10100000L block so the replacement is unconditional — no per-call #ifdef required.
  • Replaced all 10 direct member dereferences across the four ASN.1 string case branches with ASN1_STRING_length() and ASN1_STRING_get0_data().
  • Also replaced the BUF_MEM*/BIO_get_mem_ptr() pattern in print_attribs() with BIO_get_mem_data(), the documented accessor that avoids opaque struct access.
  • Fixed const qualifier warnings on X509_ATTRIBUTE_get0_object() and X509_ATTRIBUTE_get0_type() return values (OpenSSL 4.0 tightened these to return const pointers).

Commits

  • compat: add ASN1_STRING_get0_data macro for OpenSSL < 1.1.0
  • fix: use ASN1_STRING accessor API in print_attribute for OpenSSL 4.0 compat
  • fix: replace BUF_MEM direct access with BIO_get_mem_data in print_attribs
  • style: cast BIO_set_close return to void for consistency
  • fix: use CONST_ASN1_OBJECT and CONST_ASN1_TYPE for X509_ATTRIBUTE accessors

Test plan

🤖 Generated with Claude Code

jonasbn and others added 4 commits June 16, 2026 20:58
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…compat

Direct ->data and ->length member access on ASN1_BMPSTRING, ASN1_UTF8STRING,
ASN1_OCTET_STRING, and ASN1_BIT_STRING fails to compile under OpenSSL 4.0,
which made struct asn1_string_st opaque. Replace with ASN1_STRING_length()
and ASN1_STRING_get0_data() throughout print_attribute(). A compat macro
maps ASN1_STRING_get0_data to ASN1_STRING_data for OpenSSL < 1.1.0.

Fixes: #60
…ribs

Avoids BUF_MEM struct member dereference, which may become opaque in future
OpenSSL releases. BIO_get_mem_data() is the documented accessor for memory
BIOs and works across all supported OpenSSL versions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 19:08

Copilot AI left a comment

Copy link
Copy Markdown

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 XS OpenSSL integration to be compatible with OpenSSL 4.0’s move to opaque ASN.1/BIO-related structs by switching from direct struct member access to documented accessor APIs.

Changes:

  • Added a compatibility macro for ASN1_STRING_get0_data() on OpenSSL < 1.1.0 so call sites can be unconditional.
  • Replaced ->data/->length accesses in print_attribute() with ASN1_STRING_get0_data() and ASN1_STRING_length().
  • Replaced BIO_get_mem_ptr()/BUF_MEM access with BIO_get_mem_data() in print_attribs().
Comments suppressed due to low confidence (1)

PKCS12.xs:668

  • In the BMPSTRING branch, *attribute is resized to length bytes but then populated via strncpy() without guaranteeing NUL-termination. The resulting buffer can be read with strlen() later (e.g., when storing into the hash), which risks reading past the allocation. Allocate length + 1 and explicitly terminate.
    if(*attribute != NULL) {
      Renew(*attribute, length, char);
      strncpy(*attribute, value, length);
    } else {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PKCS12.xs Outdated
Comment thread PKCS12.xs Outdated
Comment on lines +693 to +694
Renew(*attribute, (size_t)length * 4, char);
get_hex(*attribute, av->value.octet_string->data, length);
get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length);
Comment thread PKCS12.xs Outdated
Comment on lines +694 to +696
get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length);
} else {
hex_prin(out, av->value.octet_string->data, length);
hex_prin(out, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length);
Comment thread PKCS12.xs Outdated
Comment on lines +706 to +707
Renew(*attribute, (size_t)length * 4, char);
get_hex(*attribute, av->value.bit_string->data, length);
get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length);
Comment thread PKCS12.xs Outdated
Comment on lines +707 to +709
get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length);
} else {
hex_prin(out, av->value.bit_string->data, length);
hex_prin(out, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length);
Comment thread PKCS12.xs Outdated
Comment on lines 820 to 821
if((hv_store(bag_hv, attr_key, (I32)attr_key_len, newSVpvn(attribute_value, strlen(attribute_value)), 0)) == NULL)
croak("unable to add MAC to the hash");
jonasbn and others added 4 commits June 19, 2026 14:16
…ssages

- Update get_hex() and hex_prin() signatures to accept const unsigned char *,
  eliminating the const-cast away from ASN1_STRING_get0_data() at call sites
- Cast ASN1_STRING_get0_data() to const char * for BIO_printf %s format
  argument to silence -Wformat under -Wall -Werror
- Fix misleading croak messages in hv_store attribute path: was
  "unable to add MAC to the hash", now "unable to store attribute in hash"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure with OpenSSL 4.0 OpenSSL 4.0 compatibility: print_attribute uses direct ASN1_STRING struct member access

2 participants