Repository navigation
Store ASN1_INTEGER as value bytes in every build - #12172
Open
julek-wolfssl wants to merge 1 commit into
Open
julek-wolfssl wants to merge 1 commit into
julek-wolfssl wants to merge 1 commit into
Conversation
As in OpenSSL, data holds the big-endian magnitude, length its size and type the sign. Encoders add the tag, length, pad and two's complement. This replaces the WOLFSSL_QT/WOLFSSL_HAPROXY serial code. It also fixes the missing pad for high-bit serials and an overflow in a2i on allocation failure. ChangeLog: in builds without WOLFSSL_QT or WOLFSSL_HAPROXY, ASN1_INTEGER data no longer holds the DER tag, length and pad. Use i2d_ASN1_INTEGER() for DER. The sign is only read from type. d2i_ASN1_INTEGER() rejects non-minimal DER and i2a_ASN1_INTEGER() prints the sign. The basic constraints pathlen holds its value in data. Tests that built DER in data, or set the sign in negative or pathlen in length, now use value bytes and type.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The path-length check discards valid positive constraints above LONG_MAX, causing BASIC_CONSTRAINTS round-trips to lose the constraint.
1 open issue
What changed in this PR
This PR unifies wolfSSL’s OpenSSL-compatible ASN1_INTEGER representation across builds: data stores the magnitude, length counts value bytes, and type carries the sign.
Changes:
- Centralizes integer conversion and encoding, including sign handling, DER padding, and minimal-encoding checks.
- Migrates X.509, OCSP, CRL, and timestamp consumers to value-byte storage and fixes allocation-failure handling.
- Updates tests and adds coverage for value layouts, high-bit serials, and leading-zero normalization.
| File | Description |
|---|---|
wolfssl/wolfcrypt/asn_public.h |
Documents the unified integer representation. |
wolfssl/internal.h |
Declares the shared magnitude constructor. |
wolfcrypt/src/asn.c |
Removes the obsolete negative-bignum build requirement. |
tests/api/test_x509.c |
Updates serial and path-length test setup. |
tests/api/test_ossl_x509.h |
Registers the serial-layout test. |
tests/api/test_ossl_x509.c |
Tests serial value bytes and DER padding. |
tests/api/test_ossl_x509_ext.c |
Updates basic-constraints value assertions. |
tests/api/test_ossl_tsp.c |
Updates timestamp serial and nonce expectations. |
tests/api/test_ossl_asn1.h |
Registers the integer-layout test. |
tests/api/test_ossl_asn1.c |
Tests conversions, signs, layouts, and DER minimality. |
tests/api.c |
Adds OCSP high-bit and CRL leading-zero tests. |
src/x509.c |
Migrates serials and basic-constraints path lengths. |
src/ssl_tsp.c |
Reads timestamp integers as unsigned value bytes. |
src/ssl_asn1.c |
Implements unified storage, conversion, and encoding. |
src/ocsp.c |
Uses the shared constructor for serial integers. |
src/crl.c |
Normalizes revoked serials and shares integer construction. |
Review effort: Balanced
Comment on lines
+2219
to
+2220
| if ((object->pathlen != NULL) && | ||
| (wolfSSL_ASN1_INTEGER_get(object->pathlen) >= 0)) { |
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.

ASN1_INTEGER now uses the same layout as OpenSSL in all builds, replacing the separate WOLFSSL_QT/WOLFSSL_HAPROXY serial code.
dataholds the big-endian magnitude,lengthits size, andtypethe sign. Encoders add the tag, length, pad and two's complement.This also fixes two bugs: the missing pad for serials with the high bit set, and an overflow in a2i on allocation failure.
Behavior changes in builds without WOLFSSL_QT or WOLFSSL_HAPROXY:
datano longer holds the DER tag, length and pad. Usei2d_ASN1_INTEGER()to get DER.type.d2i_ASN1_INTEGER()rejects non-minimal DER.i2a_ASN1_INTEGER()prints the sign.data.Tests that built DER in
data, or set the sign innegativeor the pathlen inlength, now use value bytes andtype.