Skip to content

openssl compat: fix ASN1_STRING_{length,get0_data} for ASN1_INTEGER#10089

Merged
douzzer merged 2 commits intowolfSSL:masterfrom
julek-wolfssl:openvpn-master
Mar 31, 2026
Merged

openssl compat: fix ASN1_STRING_{length,get0_data} for ASN1_INTEGER#10089
douzzer merged 2 commits intowolfSSL:masterfrom
julek-wolfssl:openvpn-master

Conversation

@julek-wolfssl
Copy link
Copy Markdown
Member

In OpenSSL, ASN1_INTEGER is typedef'd to ASN1_STRING (same struct), so
calling ASN1_STRING_length() / ASN1_STRING_get0_data() on an
ASN1_INTEGER* is valid and well-defined. wolfSSL has them as distinct,
incompatible structs. This fixes the openvpn master failures introduced in
OpenVPN/openvpn#1003

In OpenSSL, ASN1_INTEGER is typedef'd to ASN1_STRING (same struct), so
calling ASN1_STRING_length() / ASN1_STRING_get0_data() on an
ASN1_INTEGER* is valid and well-defined. wolfSSL has them as distinct,
incompatible structs. This fixes the openvpn master failures introduced in
OpenVPN/openvpn#1003
Copilot AI review requested due to automatic review settings March 27, 2026 16:21
Copy link
Copy Markdown
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

Improves OpenSSL-compatibility for ASN1_INTEGER by allowing ASN1_STRING_length() / ASN1_STRING_get0_data() call sites (common in OpenSSL-based consumers like OpenVPN) to work correctly with wolfSSL’s distinct WOLFSSL_ASN1_INTEGER type.

Changes:

  • Add wolfSSL_ASN1_INTEGER_get_length() and wolfSSL_ASN1_INTEGER_get0_data() APIs.
  • Implement the new INTEGER helpers in src/ssl_asn1.c (attempting to strip DER tag/length when present).
  • Override ASN1_STRING_length() / ASN1_STRING_get0_data() in the OpenSSL compatibility header using C11 _Generic dispatch for INTEGER.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
wolfssl/ssl.h Declares new INTEGER helper APIs to support compat dispatch.
wolfssl/openssl/ssl.h Adds C11 _Generic macros to route ASN1_STRING_length/get0_data calls to INTEGER-aware helpers.
src/ssl_asn1.c Implements INTEGER length/data helpers that attempt to return raw value octets (DER header stripped when detected).

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

Comment thread src/ssl_asn1.c
Comment thread src/ssl_asn1.c
Comment thread wolfssl/openssl/ssl.h Outdated
Comment thread wolfssl/openssl/ssl.h Outdated
Comment thread wolfssl/openssl/ssl.h Outdated
Comment thread wolfssl/openssl/ssl.h
Comment thread src/ssl_asn1.c
@lealem47
Copy link
Copy Markdown
Contributor

lealem47 commented Mar 27, 2026

Jenkins retest this please.

lealem47
lealem47 previously approved these changes Mar 27, 2026
@lealem47 lealem47 assigned wolfSSL-Bot and unassigned lealem47 Mar 27, 2026
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #10089

Scan targets checked: src, src-bugs, src-compliance
Findings: 1

High (1)

Incorrect GetLength return value check makes DER-stripping logic dead code

File: src/ssl_asn1.c:1017-1021 and 1041-1045
Function: wolfSSL_ASN1_INTEGER_get_length / wolfSSL_ASN1_INTEGER_get0_data
Category: Logic errors

Both wolfSSL_ASN1_INTEGER_get_length and wolfSSL_ASN1_INTEGER_get0_data check GetLength(ai->data, &idx, &len, (word32)ai->length) > 0 to determine if the DER tag/length header was successfully parsed. However, wolfSSL's GetLength function returns 0 on success (storing the decoded length in the *len output parameter) and returns negative error codes on failure. It does not return positive values. Because the check is > 0 instead of >= 0, the condition is never true on a successful parse, making the entire DER-header-stripping branch unreachable dead code. Both functions will always fall through to the fallback path that returns ai->length or ai->data unchanged, completely defeating the stated purpose of the PR (stripping the DER header from ASN1_INTEGER data for OpenSSL compatibility).

if (GetLength(ai->data, &idx, &len, (word32)ai->length) > 0 &&
        idx + (word32)len == (word32)ai->length) {
    return len;
}

Recommendation: Change > 0 to >= 0 in both functions:

if (GetLength(ai->data, &idx, &len, (word32)ai->length) >= 0 &&
        idx + (word32)len == (word32)ai->length) {

This review was generated automatically by Fenrir. Findings are non-blocking.

@padelsbach
Copy link
Copy Markdown
Contributor

@julek-wolfssl, I'm following this PR because I believe it solves the issues in CI. Any thoughts on the Fenrir comments?

@douzzer douzzer added For This Release Release version 5.9.1 Staged Staged for merge pending final test results and review labels Mar 30, 2026
Copy link
Copy Markdown
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

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

Thanks @julek-wolfssl !

@douzzer douzzer merged commit adf70b1 into wolfSSL:master Mar 31, 2026
494 of 496 checks passed
@julek-wolfssl
Copy link
Copy Markdown
Member Author

@padelsbach comment reasoning was flawed but conclusion is correct. Addressed in #10109.

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

Labels

For This Release Release version 5.9.1 Staged Staged for merge pending final test results and review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants