Repository navigation
Conversation
PEM_read_bio_PrivateKey, PEM_read_RSAPrivateKey, PEM_read_bio_PUBKEY and PEM_write_bio_PrivateKey threw NotImplemented for every encrypted record and for every cipher passed to the writer. Follow LibreSSL 4.0.0 for both formats: - Proc-Type and DEK-Info records: PEM_get_EVP_CIPHER_INFO, PEM_do_header and EVP_BytesToKey with AES-128/192/256-CBC. - ENCRYPTED PRIVATE KEY records: the X509_SIG, PBES2 and PBKDF2 structures with the tasn_dec.c rules, then PKCS12_pbe_crypt, EVP_PBE_CipherInit and the PBES2 and PBKDF2 key generators with the HMAC digests this port has. - Writing with a cipher: PKCS8_encrypt with PKCS5_pbe2_set. - The pass phrase from the callback, or from u when the callback is null. Ciphers, PBE schemes and digests this port has no primitive for, the terminal prompt and three BER forms still throw; the debt fragment lists them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The PEM readers decrypted AES records only. Add the DES family from LibreSSL 4.0.0: - DEK-Info records in DES-CBC, DES-EDE-CBC and DES-EDE3-CBC. - PBES2 with the DES-CBC and DES-EDE3-CBC OIDs. - PBES1 (PKCS5_PBE_keyivgen): PBE-MD5-DES and PBE-SHA1-DES. - The PKCS#12 schemes PBE-SHA1-3DES and PBE-SHA1-2DES, with PKCS12_key_gen_uni. The blocks are decrypted with mbedtls and the checks of EVP_DecryptFinal_ex are redone on the result, with their errors. The two MD2 schemes now queue EVP_R_UNKNOWN_DIGEST, as 4.0.0 has no MD2, instead of throwing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ted-pem-private-keys
main dropped the file's GuestWritablePreservingErrno wrapper now that GuestWritable_nid_no_patch keeps errno itself; use it for the slot a PEM private key read replaces. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…bressl3-des-pem-private-keys
catminou4
left a comment
There was a problem hiding this comment.
Built libSceLibreSsl3 and ran guest_libressl3_pem_keys_tests on Linux (x86-64, GCC 11): passes (exit 0). Adds DES / Triple-DES PEM private-key decryption on top of the encrypted-PEM base.
This is a middle of the PEM stack (#26409 → #26410 → #26414 → #26425), so merge order matters. I verified the full stack's test on #26425 and this layer's test here; both pass. The shared debt fragment carries the honest caveats forward (LibreSSL 4.0.0 PEM_do_header / EVP_PBE_CipherInit provenance, MD2 schemes queuing EVP_R_UNKNOWN_DIGEST, unsupported ciphers throwing via NotImplemented_nid_no_patch). No made-up success.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c04bd10073:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl3_pem_keys_testsbuilt cleanly. - CTest (
guest_libressl3_pem_keys):1/1 Test #4826: guest_libressl3_pem_keys ......... Passed 2.02 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibreSsl3/src/PemKeys.cpp,core/libs/prx/libSceLibreSsl3/src/PemEncryption.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4826: guest_libressl3_pem_keys .........Subprocess aborted***Exception: 0.26 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Validated PemCipherInfoFromDekInfo_nid_no_patch in PemEncryption.cpp: verifies DEK-Info header bounds, cipher name parsing, and IV bounds check against sizeof(info.iv).
- Verified PemDoHeader_nid_no_patch in PemEncryption.cpp: ensures input length bounds checks against data.size(), checks for INT_MAX overflow before buffer allocation, and guarantees sensitive key and password zeroing via RAII guards.
- Audited PbeCipherInit and PbeCrypt in PemEncryption.cpp: verified DES and 3DES scheme dispatch for PBES1, PBES2, and PKCS#12, verifying correct error reporting via PutError (Pkcs12Library, EvpLibrary) and explicit NotImplemented_nid_no_patch invocation on unimplemented DES encryption.
- Checked PemReadPassword_nid_no_patch in PemEncryption.cpp: verified safe memory access via GuestCopyIn_nid_no_patch, length enforcement against LibreSsl3PemBufferSize (1024 bytes), and proper error signaling when callback returns negative or zero length.
- Verified PemEncryptPkcs8_nid_no_patch and DecryptToPkcs8 in PemEncryption.cpp: verified null checks on cipher and plain buffers, valid d2i_PKCS8_PRIV_KEY_INFO_nid_postfix 64-bit length handling, and correct ASN.1 DER encapsulation.
- Confirmed strict AGENTS.md compliance: upstream BSD/OpenSSL license headers are preserved verbatim, zero prohibited comments are present in source code, and missing/unsupported primitives throw via NotImplemented_nid_no_patch.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: reject empty PKCS#12 salts before key derivation to avoid a modulo-by-zero crash on malformed encrypted key input.
What I ran
- Reviewed prepared diff at head
c04bd10073ef37b515e1928cb8ce2ef794fdf35c; no commands or tests were run. - Read
review/description.md,review/commits.md,review/manifest.json,review/diff.patch, and the implementation ranges incore/libs/prx/libSceLibreSsl3/src/PemEncryption.cppcovering DER parsing, PBE parameter decoding, and DES/PBE key derivation.
Results
| Check | Result | Note |
|---|---|---|
| Patch review | failed | Empty PKCS#12 salt can crash key derivation |
| Tests | not run | Only author-reported results are available |
| Manifest coverage | not run | Full changed-file inventory was not inspected |
Findings
Blocking
core/libs/prx/libSceLibreSsl3/src/PemEncryption.cpp:1768: For a PKCS#12 PBE parameter with an empty salt,saltBlocksis zero, but the later loop evaluatessalt[index % saltLength]while filling the password blocks. This performs modulo by zero; an attacker-controlled encrypted PEM can therefore crash the process. Reject the empty salt before entering this loop (and add a malformed-input regression test).
Non-blocking
None.
Not verified
- The implementation’s remaining paths, test changes, CMake integration, and debt-document changes were not fully read.
files.jsonwas not inspected, so excluded files and complete reviewed-file coverage are not verified.- No build or test was run. Windows/MinGW results and OpenSSL vectors in the description are author-reported; console behavior and LibreSSL error-queue equivalence remain unverified.
To get this to a good state
Reject an empty PKCS#12 salt before key derivation and add a regression test that confirms malformed input fails cleanly rather than crashing. Re-run the relevant PEM test target on the updated head.
|
@MarcZX10 thank you for the read. I checked the blocking point against the code at
This is the arithmetic of the pinned LibreSSL ( No commit follows from this review: there is nothing to change in the code, and I did not add a test for a crash that cannot happen. If you see a path where |
…ted-pem-private-keys # Conflicts: # docs/dev/debt/changes/feat-libressl3-rsa-free-rsapublickey-bio.md
…bressl3-des-pem-private-keys # Conflicts: # docs/dev/debt/changes/feat-libressl3-rsa-free-rsapublickey-bio.md
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The DES-family decryption additions are supported by the inspected implementation and its targeted regression coverage; the review is incomplete because several changed files and most of the large implementation were not read.
What I ran
No build or tests were run. I inspected the prepared diff and selected code ranges with the pinned-head reader.
Results
| Check | Result | Note |
|---|---|---|
| Diff and metadata | passed | Prepared review bundle inspected |
| Targeted code review | not run | Partial source inspection only |
| Build and tests | not run | No commands executed |
Findings
Blocking
None identified in the inspected ranges.
Non-blocking
None.
Not verified
The full implementation in core/libs/prx/libSceLibreSsl3/src/PemEncryption.cpp, including most ASN.1 and PBE handling, was not read. core/libs/prx/libSceLibreSsl3/src/PemKeys.cpp, core/libs/prx/libSceLibreSsl3/tests/PemKeys.cpp, and core/libs/prx/libSceLibreSsl3/CMakeLists.txt were not read. The manifest lists six changed files; the new header and debt fragment were inspected through the diff, and selected portions of the implementation were inspected. The reported Windows test and negative-control results are author-reported, not independently run. Console behavior was not verified.
To get this to a good state
Nothing is required.
|
@ToRaNek, I am closing this resubmission for the same reason the original was set to close: it is real, tested code, but no title we know of loads a password-protected private key from guest memory, and it is a large piece of crypto to review for no game effect today. If you find a title that does, please reopen with that title and it goes to review. |
What
Resubmission of #24953, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit
6c655a608e0; the reviews and the discussion are on #24953.Stacked on #26409 (the first commit here is that PR; only the second one is new).
#26409 made the PEM readers of
libSceLibreSsl3decrypt AES records and left every other cipher throwing. This PR adds the DES family, which is what older tools write by default (openssl rsa -des3,openssl pkcs8 -topk8with its v1 default, PKCS#12 exports). It follows LibreSSL 4.0.0 (ce488b78).DEK-InforecordsDES-CBC(aliasDES),DES-EDE-CBC,DES-EDE3-CBC(aliasDES3), with the lengths ofe_des.cande_des3.cPKCS5_PBE_keyivgen: the digest of password and salt, iterated, first 8 bytes as key and bytes 8 to 16 as IVPKCS12_PBE_keyivgenwithPKCS12_key_gen_uniand the big-endian two-byte password ofOPENSSL_asc2uniThe cipher. No DES
EVP_CIPHERexists in this port, so the blocks are decrypted with mbedtls (mbedtls_des_crypt_cbc,mbedtls_des3_crypt_cbc; the parent library already uses mbedtls DES forDES_ecb_encrypt). The checks thatEVP_DecryptUpdateandEVP_DecryptFinal_exmake are redone on the result, with their errors: a length that is 0 or not a multiple of 8 isEVP_R_WRONG_FINAL_BLOCK_LENGTH; a last byte of 0 or above 8, or padding bytes that differ, isEVP_R_BAD_DECRYPT. The AES path still goes through the parent's EVP functions and is not changed.The two MD2 schemes (PBE-MD2-DES, PBE-MD2-RC2-64) threw
NotImplementedin #26409. Their result does not need a cipher: 4.0.0 has no MD2 (evp_names.chas no such digest), soEVP_PBE_CipherInitfinds the cipher, fails on the digest and queuesEVP_R_UNKNOWN_DIGESTwithoutEVP_R_KEYGEN_FAILURE. They now do that.Still throwing: the ECB, CFB and OFB DES modes (in
DEK-Info, ECB has no IV and the source then salts the key with uninitialised bytes), DESX, RC2, RC4, Camellia and the rest of the 4.0.0 list, the six RC2 and RC4 PBE schemes, and DES in the writer (no DES cipher object is exported, so the writer cannot be asked for it). The debt fragment lists them.Tested
Windows 11, MinGW GCC 15.2. Not tested on a console.
Vectors. 14 records made with OpenSSL 3.2.4 (default and legacy providers) from the EC and RSA keys the test already had; each one decrypts back to its key with
openssl:Three of them (
-des3traditional,-v2 des3, PBE-SHA1-3DES) were already in #26409's test as records that had to throw; they now have to decrypt. The Camellia and RC4 records take their place as the ones that still throw.The test (
guest_libressl3_pem_keys), four new functions:u;DEK-Infovariants for the three ciphers: lower-case IV, text after the IV, another separator, the aliases; short IV, bad digit, missing IV; names that 4.0.0 does not know givePEM_R_UNSUPPORTED_ENCRYPTION, names it knows but this port lacks throw;EVP_R_DECODE_ERRORfor PBES1,PKCS12_R_DECODE_ERRORfor PKCS#12): no parameter, a wrong type, missing and extra fields, wrong tags, end-of-contents octets, a non-minimal integer, 0, negative and 9-byte iteration counts;EVP_R_UNKNOWN_PBE_ALGORITHM;Negative controls. 41 mutations of the new code, each rebuilt and run on its own. 39 make the test fail. They cover the block-length, padding-value and padding-content checks, the key schedule (two-key against three-key), the IV, the aliases, the cipher OIDs, the PBES2 IV rules, the PBES1 digest input, rounds and IV window, the PKCS#12 diversifier, block filling, carry, rounds and password encoding, the scheme table, the MD2 outcome, the parameter decoder and the error pushes.
The two that survive cannot be seen by a test: giving the two-key cipher a 24-byte key (only its first 16 bytes are used, and both derivations produce the same first 16), and dropping the
PKCS12_R_KEY_GEN_ERRORpush (it needs SHA-1 itself to fail).Rest of the library. 89 of the 91
libSceLibreSsl3test targets were rebuilt and pass on the branch. As in #26409, the other two (guest_libressl3_ecdsa_sig_tests,guest_libressl3_rsa_getters_tests) link the graphics driver, which is not built in my tree, so I did not run them.python tools/check_conventions.py --base origin/mainpasses.python tools/debt_fold.py --checkfails on currentmainon another PR's fragment (feat-libwebrtc-rnn-vad.md, fixed by #24945); with that fragment fixed locally it passes on this branch.Not verified. The expected error queues come from reading the source, not from running a LibreSSL 4.0.0 binary.
Overlap (
python tools/pr_overlap.py --branch feat/libressl3-des-pem-private-keys):mainand shareCMakeLists.txtortests/PemKeys.cpp: feat(libSceLibreSsl): implement EC_KEY_get0_private_key and EC_KEY_set_private_key #11146, feat(libSceLibreSsl3): implement numeric object identifier text parsing #12315, feat(libSceLibreSsl3): implement OBJ_obj2txt #17241, feat(libSceLibreSsl3): implement EC_POINT_dup #17621, feat(libSceLibreSsl3): implement EC_POINT_get/set_affine_coordinates_GFp #17622, feat(libSceLibreSsl3): implement ECDSA_do_sign #17626, feat(libSceLibreSsl3): implement RSAPublicKey_dup #19024, feat(libSceLibreSsl3): implement ECDSA_do_sign #21684, feat(libSceLibreSsl3): implement i2d_PUBKEY #21691, feat(libSceLibreSsl3): deep-copy the X509 issuer name #21692, feat(libSceLibreSsl3): encode X509 extensions in X509_add1_ext_i2d #21702, feat(libSceLibreSsl3): implement X509_NAME_add_entry_by_txt #21706, feat(libSceLibreSsl3): implement the QUIC data path #22991 and feat(libSceLibreSsl3): decode X509 certificates from BIO #23573. They are among the ones listed on feat(libSceLibreSsl3): read and write encrypted PEM private keys #26409, where I read each diff: none touches the PEM encryption code. This PR's own commit does not changeCMakeLists.txt.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)