feat(libSceLibreSsl3): implement RSA_free and d2i_RSAPublicKey_bio #22804
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22804"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Callimann8 on 2026-11-18T10:10:11Z.
Requested by Carlos · project thread
What
Implements
RSA_freeandd2i_RSAPublicKey_bionatively in libSceLibreSsl3, following LibreSSL 4.0.0 atce488b78e0bd(rsa_lib.c,x_all.c,tasn_dec.c,asn1_lib.c,a_int.c,x_bignum.c).RSA_freewas forwarded to libSceLibreSsl, so every key made by this module's ownRSA_newor handed out byEVP_PKEY_get1_RSAreached the 2.5.4 free and threw on its null method. It is now exported from libSceLibreSsl3. A key whose method pointer is set still goes to libSceLibreSsl'sRSA_free, because only that library'sRSA_newsets one; keys from this module, which leave it null, are freed by the existing nativeFreeRsa. The method and reference count are at the same offsets in both layouts, and the test checks that withstatic_assert.RSA_freeis removed so the NID is exported once;libressl3_import_bindingnow also checks thatRSA_freebinds to libSceLibreSsl3.d2i_RSAPublicKey_bioreads one object with the readerd2i_PrivateKey_bioalready uses (now shared throughReadDerObjectFromBio_nid_no_patch) and decodesRSAPublicKeyasASN1_item_d2idoes: an existing*rsais freed once an object has been read and is left null on a decode failure, BER identifiers and lengths inside the SEQUENCE are accepted, integers followc2i_ASN1_INTEGER_cbs(negative values, minimal-encoding check), and the error reasons are queued in upstream order.d2i_RSA_PUBKEY/d2i_RSAPublicKey_bioandPEM_read_RSAPrivateKeyentries whose closing condition was nativeRSA_free, and drops the same reason from the PEM keys entry. The inventory fragment's pending-export count goes from 11 to 10 and the parent alias count from 386 to 385.d2i_RSA_PUBKEYandPEM_read_RSAPrivateKeystay stubs; they are separate follow-ups.Tested
Linux (Ubuntu 24.04, GCC 13.3, Release), all libraries built. The new
guest_libressl3_rsa_public_key_biotest tracks every heap block and checks:EVP_PKEY_get1_RSAfollowed byRSA_freeandEVP_PKEY_free, the case that used to throw;d2i_PUBKEYof the same key, plus a 512-bit OpenSSL key read from the same BIO;*rsacleared on decode failure, and left untouched when the BIO read fails;Making
RSA_freealways free natively, or changing one queued reason, makes the test fail. All 179 LibreSSL tests (ctest -R libressl) pass on currentmain.tools/check_conventions.py --base origin/mainreports no errors (one existing length warning on the inventory entry). Not tested on a console.Overlap: no open PR implements either function. #17299 and #17303 rename the
RSA_freealias line inParentExports.cppthat this PR deletes, so whichever merges second resolves a one-line conflict. TheOCSP_cert_to_idPR changes the same pending-export count line inlibressl3-20171-inventory.md; whichever merges second lowers it by one more.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T10:22:07Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
365ab09411:tools/check_conventions.pypassed.guest_libressl3_rsa_public_key_bio_tests,libressl3_import_binding_testsbuilt cleanly.libressl3_import_binding,guest_libressl3_rsa_public_key_bio):core/libs/prx/libSceLibreSsl3/Export.cpp,core/libs/prx/libSceLibreSsl3/ParentExports.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/include/PkeyState.hpp,core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp,core/libs/prx/libSceLibreSsl3/src/RsaCrypto.cpp,core/libs/prx/libSceLibreSsl3/src/RsaPublicKeyBio.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me