feat(libSceLibreSsl): read PEM private keys #19508
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19508"
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 LeandroLP23 on 2026-11-13T12:43:15Z.
What
Reads PEM private keys in
libSceLibreSsl, following LibreSSL 2.5.4, the version its debt entries follow.PEM reader.
ReadPemRecordused to stop withNotImplementedright after the-----BEGINline. It is now a full port of pem_lib.c'sPEM_read_bio:-----END <name>-----check;EVP_DecodeUpdate/Final/Blockrules and tables;check_pemwith theANY PRIVATE KEYrules and the old certificate and PKCS#7 aliases,pem_check_suffix,PEM_bytes_read_bio(which skips non-matching records), andPEM_get_EVP_CIPHER_INFO;PemBuffergrowth and the 254-byteBIO_getslines are kept.Keys:
PEM_read_bio_PrivateKey(pem_pkey.c):PRIVATE KEYgoes through PKCS#8PrivateKeyInfoandEVP_PKCS82PKEYto RSA;RSA PRIVATE KEYgoes throughd2i_PrivateKey→old_rsa_priv_decode→RSAPrivateKey(rsa_asn1.c, d2i_pr.c), with its fallback to PKCS#8 and its reuse of*x.PEM_read_RSAPrivateKey(pem_all.c) reads through a FILE BIO, thenpkey_get_rsa, and replaces*rsa.RSAPrivateKeydecoder lives inRsa.cppnext toDecodeRsaPublicKey, reusing its DER helpers. Like 2.5.4'sBIGNUM_it, it ignores the sign of the eight numbers, and the version goes throughlong_c2i.libSceLibreSsl3forwards itsPEM_read_bio_PrivateKeyhere with ajmp, so it gets the same behaviour.Errors, pushed with 2.5.4's library and reason codes:
NO_START_LINE,BAD_END_LINE,BAD_BASE64_DECODE,NOT_PROC_TYPE,NOT_ENCRYPTED,SHORT_HEADER,NOT_DEK_INFO, andERR_R_ASN1_LIB;UNSUPPORTED_ALGORITHM,UNSUPPORTED_PRIVATE_KEY_ALGORITHMandPRIVATE_KEY_DECODE_ERROR;ERR_R_RSA_LIB.A bad base64 character returns NULL with no error queued, as 2.5.4 does (
B64_NOT_BASE64(0xFF)is false, soDecodeBlockfails andbl == 0takesgoto err).Still throws, recorded in the libSceLibreSsl debt:
Proc-Type: 4,ENCRYPTEDandENCRYPTED PRIVATE KEY), since no PEM cipher is modelled;PEM_read_bio_X509,PEM_read_bio_X509_AUXandPEM_read_X509now read the whole record and throw atd2i_X509, which #13266 implements.tasn_dec.c's decode errors and the error-data strings are not queued, as in the existingd2i_RSA_PUBKEY.Licences. Each ported file carries LibreSSL's notice verbatim and a
Derived from LibreSSL 2.5.4 (openbsd 2e2c612066aa993717528a0249c15c51128d61cb) …line naming its sources and revisions:PemReadBioX509.cpp:pem/pem_lib.c1.44 andevp/encode.c1.24;PemPrivateKey.cpp:pem/pem_pkey.c1.22,asn1/d2i_pr.c1.15 andevp/evp_pkey.c1.19;PemX509.cpp:pem/pem_all.c1.17, wherePEM_read_RSAPrivateKeylives;Rsa.cpp:rsa/rsa_asn1.c1.13.Tested
The RSA test keys and the test certificate were freshly generated for these tests with OpenSSL and belong to nobody.
Windows 11, MinGW GCC 15.2 Release, rebased on
main0294cba8dc.guest_libressl_pem_private_key, with RSA keys from OpenSSL:RSA_signwith SHA-256 reproduces OpenSSL's signature, andRSA_verifyaccepts it;EVP_PKEY** xandRSA**;DH PRIVATE KEYrecord before the key are skipped, and a lowercase label and an empty header are accepted;RSA PRIVATE KEYworks;GuestLibreSslBio'sPEM_read_X509case now writes a full certificate record. A file holding only a BEGIN line now givesBAD_END_LINEinstead of throwing.libSceLibreSslandlibSceLibreSsl3tests pass.*xfree, the PKCS#8 fallback;tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchlists no pull request with the same exports.CMakeLists.txtlines.BIO_printf, the others are SSL, X509_STORE and BIO work.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)