feat(libSceLibreSsl3): read and write keys in DER and PKCS#8 #19535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19535"
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 MarrasFederico on 2026-11-13T13:52:02Z.
What
libSceLibreSsl3can now read and write RSA and EC keys in DER and PKCS#8. The new exports are:d2i_PUBKEY;d2i_PrivateKey_bio;d2i_PKCS8_PRIV_KEY_INFOandd2i_PKCS8_PRIV_KEY_INFO_bio;i2d_PKCS8_PRIV_KEY_INFO;PKCS8_PRIV_KEY_INFO_free;EVP_PKCS82PKEYandEVP_PKEY2PKCS8.These keys use the native
EVP_PKEYfrom #17528 and #19487, so the guest can release them withEVP_PKEY_free.RSA_newandRSA_set0_*, and assigned with the nativeRsaAsn1Method.EC_KEYfrom the parent library. P-256 and P-384 are supported; other curves fail with an error.EVP_PKEY_freereleases both kinds.PKCS8_PRIV_KEY_INFO. The type is opaque in LibreSSL 4.0.0, which defines it only inx509_local.h.LibreSsl3Pkcs8PrivKeyInfolayout (version,pkeyalg,pkey,attributes), built from the module's ASN.1 types.[0]attributes are validated and stored as raw bytes rather than asSTACK_OF(X509_ATTRIBUTE).i2dwrites them back andPKCS8_PRIV_KEY_INFO_freereleases them._biofunctions read exactly one definite-length DER object, guided by its TLV header, asasn1_d2i_read_biodoes. The content is read in chunks (16 KiB, doubling up to 1 MiB), so memory grows only with the bytes the BIO delivers. Bytes after that object stay in the BIO.d2i_PrivateKey_bio. It followsd2i_AutoPrivateKeyina_pkey.c:ASN1_item_d2i, theEVP_R_*codes fromEVP_PKCS82PKEY, and theX509_R_*/EC_R_*codes on the public key paths.d2i_RSA_PUBKEYandd2i_RSAPublicKey_bioreturn a bareRSA*.RSA_freein this module still forwards tolibSceLibreSsl, which uses a different RSA layout, so the guest could not free a native RSA returned by these functions.PEM_read_RSAPrivateKey,PEM_read_bio_PUBKEYandPEM_write_bio_PrivateKeywait for the PEM layer.Export.cpphas 15 stubs. The additional-export table has 56 rows, 52 named and 4 known only by NID, matchingAdditionalExports.cpp.Source: LibreSSL 4.0.0 at
ce488b78e0bd994780569df718596b9776ff681a:asn1/x_pubkey.c,asn1/p8_pkey.c,evp/evp_pkey.c,asn1/a_pkey.candasn1/asn1_item.c.KeyDer.cppcarries their notices and a "Derived from" line.Tested
Ubuntu 26.04.1, GCC 15.2.0, Release,
BUILD_TESTING=ON. Also built on Windows (MSYS2 UCRT64, GCC 16.2), wherectest -R libressl3passes.The new test
guest_libressl3_key_derfrees every object only through public exports (EVP_PKEY_free,PKCS8_PRIV_KEY_INFO_free,BIO_free,free). It covers:[0]attributes kept across a round trip;*ppadvancement and*outreplacement;Results:
ctest -R libressl3: 70 of 70 pass at28e5d37a7d(after merging#194873ede9bc1ae).d2i_PUBKEYstubbed again, the test stops withd2i_PUBKEY_nid_postfix not implemented.EVP_PKEY_freeneeds that method to release the key.tools/check_conventions.py --base upstream/main: reports 1 warning ([debt-length]atdocs/dev/debt/libSceLibreSsl3.md:28, 1778 characters; 0 errors).python3 core/libs/tests/test_public_headers.py --audit-only: 413 libraries, 34548 exports verified.git diff --check upstream/main...HEAD: clean.Overlap: no open PR implements these exports. #19508 reads PEM keys in the parent
libSceLibreSsl, not here.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)