Add OpenSSL compat: BIO_get_new_index, i2d_PUBKEY_bio, OpenSSL_version - #11020
Add OpenSSL compat: BIO_get_new_index, i2d_PUBKEY_bio, OpenSSL_version#11020julek-wolfssl wants to merge 10 commits into
Conversation
wolfSSL_OpenSSL_version() was declared with either an int or a void parameter list depending on OPENSSL_VERSION_NUMBER. That macro does not evaluate the same way in the library and in the application: with OPENSSL_COEXIST the library additionally pulls in the real OpenSSL headers and gets their version number, while an application that turns coexist off gets wolfSSL's default. The two builds then disagreed on the argument list and the selector read garbage, so OpenSSL_version() always hit the default case. Give the function a single unconditional signature. Also match the test guards for wolfSSL_i2d_PUBKEY_bio and wolfSSL_OpenSSL_version to the guards on their implementations.
The Linux kernel build compiles with -Werror=date-time, so OPENSSL_BUILT_ON broke libwolfssl.ko.
There was a problem hiding this comment.
Pull request overview
This PR extends wolfSSL’s OpenSSL-compat layer by adding missing APIs used by OpenSSL-compatible applications: BIO_get_new_index(), i2d_PUBKEY_bio(), and fuller OpenSSL_version(type) selector handling.
Changes:
- Add
wolfSSL_BIO_get_new_index()plusBIO_TYPE_STARTmapping for allocating custom BIO method type IDs. - Add
wolfSSL_i2d_PUBKEY_bio()to write DER-encoded public keys to a BIO, plus unit test coverage. - Standardize
wolfSSL_OpenSSL_version(int type)and implement selector-based strings forOPENSSL_*constants, with tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wolfssl/ssl.h | Adds BIO type range macros, declares wolfSSL_BIO_get_new_index, adds wolfSSL_i2d_PUBKEY_bio, and standardizes wolfSSL_OpenSSL_version(int). |
| wolfssl/openssl/ssl.h | Maps i2d_PUBKEY_bio and simplifies OpenSSL_version(x) mapping to always pass the selector. |
| wolfssl/openssl/opensslv.h | Defines OPENSSL_* selector constants (0–5) when missing. |
| wolfssl/openssl/bio.h | Exposes BIO_TYPE_START and maps BIO_get_new_index to wolfSSL. |
| wolfcrypt/src/evp_pk.c | Implements wolfSSL_i2d_PUBKEY_bio() for writing DER public keys to a BIO. |
| src/ssl.c | Implements selector-based wolfSSL_OpenSSL_version(int type) and avoids signature dependence on OPENSSL_VERSION_NUMBER. |
| src/bio.c | Implements wolfSSL_BIO_get_new_index() using a static counter (needs thread-safety fix per review comment). |
| tests/api/test_ossl_bio.h | Adds declaration and registration for the new BIO index test. |
| tests/api/test_ossl_bio.c | Adds BIO_get_new_index() API test for uniqueness and range. |
| tests/api.c | Adds i2d_PUBKEY_bio round-trip tests and expands OpenSSL_version(type) selector tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
retest this please |
| return "compiler: information not available"; | ||
| case OPENSSL_BUILT_ON: | ||
| /* Kernel module builds compile with -Werror=date-time. */ | ||
| #if defined(HAVE_REPRODUCIBLE_BUILD) || defined(WOLFSSL_LINUXKM) |
There was a problem hiding this comment.
This is nice, but perhaps we should have another new gate like WOLFSSL_OPENSSL_BUILT_ON_DATE or a way to disable it beside the reproducible build option?
| WOLFSSL_MSG("BIO type index space exhausted"); | ||
| return -1; | ||
| } | ||
| bio_type_idx++; |
There was a problem hiding this comment.
This is not thread safe. Should it use the atomic?
| return WOLFSSL_FAILURE; | ||
| } | ||
|
|
||
| der = (byte*)XMALLOC((size_t)derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
There was a problem hiding this comment.
Consider passing bio->heap as the hint since we have it? Don't forgot the free too
| * @return WOLFSSL_SUCCESS on success. | ||
| * @return WOLFSSL_FAILURE on failure. | ||
| */ | ||
| int wolfSSL_i2d_PUBKEY_bio(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key) |
There was a problem hiding this comment.
Should the "key" be const? const WOLFSSL_EVP_PKEY* key
| idx = bio_type_idx; | ||
| if (idx > WOLFSSL_BIO_TYPE_MAX) { | ||
| WOLFSSL_MSG("BIO type index space exhausted"); | ||
| return -1; |
There was a problem hiding this comment.
Should this be WOLFSSL_FATAL_ERROR?
| idx3 = BIO_get_new_index(); | ||
|
|
||
| ExpectIntGE(idx1, BIO_TYPE_START); | ||
| ExpectIntLE(idx1, WOLFSSL_BIO_TYPE_MAX); |
There was a problem hiding this comment.
Should this be BIO_TYPE_MASK? Should we add a helper WOLFSSL_BIO_TYPE_MASK add a BIO_TYPE_MASK compat alias in wolfssl/openssl/bio.h?
- wolfSSL_BIO_get_new_index: claim the index atomically when atomics are available (zero-initialized count), with a plain-increment fallback; return WOLFSSL_FATAL_ERROR on exhaustion. - wolfSSL_i2d_PUBKEY_bio: make key const and use bio->heap for the temp buffer alloc/free. - OpenSSL_version: add WOLFSSL_OPENSSL_NO_BUILD_DATE to drop the build date without the full reproducible-build option. - Add BIO_TYPE_MASK compat alias and use it in the test.
Description
As part of the continuous integration of OpenSSL to wolfSSL, this adds a few missing functions needed for OpenSSL-compat APIs:
BIO_get_new_index()(unique custom BIO type IDs, 128–255),i2d_PUBKEY_bio()(write public-key DER to a BIO), andOpenSSL_version(type)handling for the six standardOPENSSL_*selector constants (plus unknown → version string). Headers/macros updated underOPENSSL_EXTRA/!NO_BIOas appropriate.Originally authored by @Roy-Carter in #10294, which was closed. Re-opening from julek-wolfssl with the same branch and follow-up fixes applied.
Testing
Ran
./tests/unit.testwith-~BIO_get_new_index,-~OpenSSL_version, and-~i2d_PUBKEY_bio(substring filters). All passed.Checklist