Repository navigation
feat(libSceLibreSsl3): decode basicConstraints, extendedKeyUsage and privateKeyUsagePeriod in X509V3_EXT_d2i - #26421
Conversation
…privateKeyUsagePeriod in X509V3_EXT_d2i
X509V3_EXT_d2i threw NotImplemented for three common extensions that
LibreSSL 4.0.0 decodes. They now follow their templates:
- basicConstraints: SEQUENCE { ca BOOLEAN OPTIONAL, pathlen INTEGER
OPTIONAL } into the 16-byte BASIC_CONSTRAINTS of x509v3.h; ca takes
the content byte as it is;
- extendedKeyUsage: SEQUENCE OF OBJECT into a stack of ASN1_OBJECT;
- privateKeyUsagePeriod: SEQUENCE { [0] GeneralizedTime OPTIONAL,
[1] GeneralizedTime OPTIONAL } into PKEY_USAGE_PERIOD.
Refusals queue the errors of tasn_dec.c. X509V3_get_d2i and
X509_CRL_get_ext_d2i use the same table.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
Built libSceLibreSsl3 and ran guest_libressl3_x509v3_ext_d2i_tests on Linux (x86-64, GCC 11): passes. New decoder surface, so no meaningful main control.
The debt fragment is appropriately precise about the LibreSSL 4.0.0 tasn_dec.c provenance and the known divergences (indefinite length / constructed time throw; >8-byte length refused where LibreSSL reads up to 126; Field=/Type= error data not queued). Good that it also flags the missing *_free exports so callers know they must release the parts themselves. Verified the three decoders are wired as throwing methods 87/126/84 in the export table.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d23fd217f5:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl3_x509v3_ext_d2i_testsbuilt cleanly. - CTest (
guest_libressl3_x509v3_ext_d2i):1/1 Test #4828: guest_libressl3_x509v3_ext_d2i ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibreSsl3/src/X509V3ExtD2i.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4828: guest_libressl3_x509v3_ext_d2i ...Subprocess aborted***Exception: 0.49 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified memory safety and RAII cleanup across NewBasicConstraints, NewExtendedKeyUsage, and NewUsagePeriod, ensuring all allocations and partial stack elements are freed on error paths without leaks.
- Verified exact LibreSSL ASN.1 error reason codes (58, 65, 102, 106, 132, 148, 149, 155, 159, 168, 216, 231) for malformed tags, lengths, primitive/constructed mismatches, and EOC in definite forms.
- Verified LP64 and LLP64 portability and ABI struct layouts for BasicConstraintsValue and UsagePeriodValue, both static_asserted to 16 bytes with 8-byte member offsets.
- Verified correct handling of all optional field permutations: absent/present ca (tested across all 256 boolean byte values), absent/present pathLength, and independent absence/presence of notBefore and notAfter.
- Verified strict AGENTS.md compliance: zero disallowed comments in implementation code, valid technical debt fragment added in docs/dev/debt/changes/, and unsupported BER indefinite-length/constructed forms explicitly throwing via NotImplemented_nid_no_patch.
Looks Good To Me
What
Resubmission of #25363, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit
d23fd217f5f; the reviews and the discussion are on #25363.X509V3_EXT_d2iinlibSceLibreSsl3threwNotImplementedfor three common extensions that LibreSSL 4.0.0 decodes:basicConstraints(NID 87),extendedKeyUsage(126) andprivateKeyUsagePeriod(84).X509V3_get_d2iandX509_CRL_get_ext_d2igo through the same table and get them too.Each follows its template (4.0.0,
ce488b78) and the generic sequence decoder oftasn_dec.c:basicConstraints(x509_bcons.c)SEQUENCE { ca BOOLEAN OPTIONAL, pathlen INTEGER OPTIONAL }BASIC_CONSTRAINTS { int ca; ASN1_INTEGER *pathlen; }ofx509v3.hextendedKeyUsage(x509_extku.c)SEQUENCE OF OBJECTSTACK_OF(ASN1_OBJECT)privateKeyUsagePeriod(x509_pku.c)SEQUENCE { notBefore [0] GeneralizedTime OPTIONAL, notAfter [1] GeneralizedTime OPTIONAL }PKEY_USAGE_PERIODPoints taken from the source rather than from the RFC:
careceives the content byte of the BOOLEAN as it is:ffgives 255 and01gives 1. An absentcais 0.pathlenornotAftershould be is an error, not an absence.SEQUENCE OFis an empty stack, and the "constructed" bit of aSEQUENCE OFis not checked (10 00is accepted), as inasn1_template_stack_of_d2i.X509V3_EXT_d2idoes not check the cursor).00 00where a field should start in a definite-length sequence isASN1_R_UNEXPECTED_EOC.ERR_R_NESTED_ASN1_ERRORentries included; theField=/Type=data is not kept.The parts are allocated with the helpers the file already uses (
d2i_ASN1_INTEGER, the object and GeneralizedTime decoders,sk_new/sk_push), soASN1_INTEGER_free,ASN1_OBJECT_freeandsk_pop_freerelease them.Left as it was (in the debt fragment):
[0]/[1]time still throw; the source decodes them;BASIC_CONSTRAINTS_free,EXTENDED_KEY_USAGE_freeorPKEY_USAGE_PERIOD_free: a caller reads the public fields and releases the parts itself;subjectAltName,certificatePolicies, ...) are unchanged.Tested
Windows 11, MinGW GCC 15.2. Not tested on a console.
Vectors. A throwaway P-256 certificate made with OpenSSL 3.2.4:
with
basicConstraints = critical,CA:TRUE,pathlen:3andextendedKeyUsage = serverAuth,clientAuth,codeSigning,1.2.3.4.5. Its extension values (30060101FF020103and the four-usage list) decode to whatopenssl x509 -textprints; a second certificate withCA:FALSEgives3000.The test (
guest_libressl3_x509v3_ext_d2i), four new functions:cawith each of the 256 content bytes;pathlenzero, positive, negative and large; usage lists that are empty, with one and several OIDs, with an OID outside the table; both times, one, none;00 00;X509V3_EXT_conf_niddecodes back.With
X509V3ExtD2i.cppfrommainthe test stops on theNotImplementedexception of its first call; with the change it passes, andguest_libressl3_x509v3_ext_conf_nidandguest_libressl3_x509_crlstill pass.Negative controls. 61 mutations of the three decoders, each rebuilt and run on its own, all make the test fail: optional fields made mandatory and the reverse, the value stored for
ca, each tag and class, each check removed, each error code changed, a release forgotten on each failure path, and the three table lines.python tools/check_conventions.py --base origin/mainandpython core/libs/tests/test_public_headers.py --audit-onlypass.python tools/debt_fold.py --checkfails on this branch for the reason it fails onmaintoday (twolibkernel_sysfragments, which #25313 and #25318 address); on a copy without those two fragments it passes.Not verified. The expected queues come from reading the source, not from running a LibreSSL 4.0.0 binary.
Overlap (
python tools/pr_overlap.py --branch feat/libressl3-x509v3-ext-d2i-basic-decoders):X509V3ExtD2i.cppelsewhere (fix(libSceLibreSsl3): decode constructed strings in X509V3_EXT_d2i #24677, constructed strings, and fix(libSceLibreSsl3): copy X509V3_EXT_d2i extension guest pointer safely #22890, the guest pointer of the export); the tool merges them with this branch without a conflict.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)