Repository navigation
ext/openssl: ciphers, digests, keys, sign/verify, x509, CSR, seal/open, SPKAC, PKCS#7/#12 over libcrypto - #236
Merged
Merged
Conversation
…ibcrypto, plus OPENSSL_* constants
…and x509_parse over libcrypto (#211, slice 1)
…SR, seal/open, SPKAC, PKCS#7 and PKCS#12 entry points (#211)
Adds openssl_cms_sign / verify / encrypt / decrypt / read (DER, S/MIME, PEM) and the OPENSSL_CMS_* constants, then re-checks the whole openssl surface against php: where php returns a value or false/-1 WITHOUT a warning this build now returns exactly that; where php emits a warning and carries on, this build throws a ValueError (project rule). php parity (no warning in php, same answer here): - openssl_cms_read returns false for every input and leaves the out-parameter untouched. - openssl_cms_verify: unreadable input / junk message -> false; once the message parses, $pk7 is created empty (it receives the CMS PEM only when a signers file is requested too, as in php), $content is filled even by a failed verification, signers are written only on success. - cms/pkcs7 encrypt|decrypt with a missing or junk input, pkcs7_verify (-1), x509_verify / x509_checkpurpose (-1), x509_check_private_key, pkey_derive, pkey_get_public of a private PEM, pkey_get_private / csr_get_* of junk, public_encrypt of too much data, decrypt of an AEAD message without a tag, pbkdf2 with iterations < 1: all answer false / -1 silently. Throws where php warns (ValueError instead of warning + false): - unknown cipher / digest / signature algorithm / curve / DN field / encoding / cipher id - unusable certificate, private key, public key, CSR or SPKAC argument; a private key object where a public key is wanted; a public key object where a private key is wanted - unreadable input file (cms/pkcs7 sign), unreadable CA path (checkpurpose, *_verify) - cms_sign with OPENSSL_CMS_DETACHED and S/MIME encoding - IV / tag problems on encrypt, OPENSSL_DONT_ZERO_PAD_KEY with a wrong key length - openssl_pkey_new EC without curve_name; csr_sign with a key that does not match the CA Known gaps: openssl.cnf-driven options (config, req_extensions, x509_extensions, CSR extra attributes) throw instead of being parsed; openssl_pkey_new(DH) without p/g returns false where php generates default parameters. Refs #211
…on has (codesign is 3.2+)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ext/openssl goes from 4/64 to about 85 % of functions (#211,
docs/builtins.md: 1058 of 2135 functions overall). Everything runs on the libcrypto every binary already links, through the existing FFI mechanism (#[Library('crypto'), Symbol(..)]insrc/Runtime/Crypto.php). Keys and certificates cross function boundaries as PEM text, so no libcrypto pointer outlives a call.openssl_encrypt/decrypt(CBC, CTR, GCM, CCM, OCB, chacha20-poly1305; tag, aad, RAW_DATA, ZERO_PADDING),cipher_iv_length,cipher_key_length,digest,pbkdf2,random_pseudo_bytes,error_string;get_cipher_methods/get_md_methodsenumerate the real registry.pkey_new(RSA, EC, DSA, DH, Ed25519, X25519, X448, Ed448),pkey_get_private/public,pkey_export(_to_file),pkey_get_details,pkey_derive,dh_compute_key.sign,verify,public_encrypt,private_decrypt,private_encrypt,public_decrypt.OpenSSLCertificate,x509_read,x509_parse,x509_export(_to_file),x509_verify,x509_check_private_key,x509_checkpurpose, fingerprint on objects.OpenSSLCertificateSigningRequest,csr_*,spki_*,seal/open,get_curve_names,get_cert_locations.cms_sign/verify/encrypt/decrypt/readin DER, S/MIME and PEM, allOPENSSL_CMS_*constants.pkcs7_sign/verify/encrypt/decrypt/read,pkcs12_export(_to_file)/read.OPENSSL_*,PKCS7_*,X509_PURPOSE_*constants.Refs #211 (not closed:
openssl.cnf-driven options remain). Repro for #235 included.Behaviour notes
openssl.cnf-driven options (config,req_extensions,x509_extensions, extra CSR attributes throw); DHpkey_newwithout p/g returns false (php generates defaults).openssl_private_decryptof random junk depends on OpenSSL implicit RSA rejection (version-dependent).openssl_pkcs12_readleaks the extra-cert objects (markedponytail:).Linux / OpenSSL versions
Needs OpenSSL >= 3.0 for:
EVP_CIPHER_get_{iv_length,key_length,block_size,flags},EVP_PKEY_get_{bits,base_id,bn_param,octet_string_param,utf8_string_param},PEM_read_bio_Parameters. Everything else exists in 1.1.1 and 3.x (RSA/EC keygen, DSA paramgen and padding useEVP_PKEY_CTX_ctrl). Fine for Debian 12 and Alpine 3.18+. The stdlib resolves every referenced symbol at link time, so this applies to every binary.Verification
bash tests/aot/run.sh -j 0on macOS arm64 atf734d5aa: passed 1880, failed 0, total 1882.