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>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 6c655a608e:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl3_pem_keys_testsbuilt cleanly. - CTest (
guest_libressl3_pem_keys):1/1 Test #4726: guest_libressl3_pem_keys ......... Passed 5.88 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 #4726: guest_libressl3_pem_keys .........Subprocess aborted***Exception: 0.47 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified DES and 3DES key length and IV length handling in PemEncryption.cpp matches LibreSSL specifications.
- Checked bounds, integer overflows, and buffer allocations in PbeCrypt and DesCbcDecrypt.
- Verified ASN.1 DER decoding and validation in ReadEncryptedKey, ReadAlgorithm, and Pbes2Algorithm.
- Verified password callback invocation and error handling in PemReadPassword_nid_no_patch and PemDoHeader_nid_no_patch.
- Confirmed AGENTS.md compliance regarding comments, upstream attribution, and error code propagation.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head 6c655a608e05f5455c0583c8cc2f5b666cb9975c. I inspected the prepared diff and targeted code through repo_read.py; I did not run build or test commands. The author reports Windows 11/MinGW test results in the PR description; these were not run by me.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Reviewed the DES/PBE paths and PEM integration |
| Build and tests | not run | Author-reported results only |
| Console behavior | not run | No console verification reported |
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read the PR description, commits, diff, manifest, and README, along with targeted ranges of PemEncryption.cpp, PemKeys.cpp, and the PEM test diff. I did not read every added line in the changed files, including all 1,533 added test lines, all 77 added PemKeys.cpp lines, the full 2,136-line PemEncryption.cpp, or the CMake and debt-file additions. Build/test claims and LibreSSL 4.0.0 error-queue equivalence were not independently verified.
To get this to a good state
Nothing is required.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
What
Stacked on #24943 (the first commit here is that PR; only the second one is new).
#24943 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 #24943. 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 #24943'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 #24943, 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 #24943, 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)