Skip to content

feat(libSceLibreSsl3): implement the X509 public key, signature NID and extension lookup accessors - #16708

Merged
oneandonlydean merged 10 commits into
boykopovar:mainfrom
Ducengarth:feat/libressl3-x509-accessors
Nov 9, 2026
Merged

oneandonlydean merged 10 commits into
boykopovar:mainfrom
Ducengarth:feat/libressl3-x509-accessors

Conversation

@Ducengarth

@Ducengarth Ducengarth commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement three certificate accessors in libSceLibreSsl3, replacing their parameterless throwing placeholders in AdditionalExports.cpp: X509_get_X509_PUBKEY (yLm956jsJpc), X509_get_signature_nid (QnjD8S6Rgk4) and X509_get_ext_by_NID (BRjfzlGULmU). Source: LibreSSL 4.0.0 at ce488b78, the revision the library's debt file already uses: x509/x509_set.c, asn1/x_x509.c, x509/x509_ext.c, x509/x509_v3.c, objects/obj_dat.c and objects/obj_lib.c.

  • X509_get_X509_PUBKEY returns cert_info->key. The new LibreSsl3CertificateInfo and LibreSsl3Certificate structs follow x509_local.h on LP64 (key at 48, extensions at 72, sig_alg at 8, 104 and 216 bytes), the same layout the existing X509Extensions.cpp and X509Validity.cpp use.
  • X509_get_signature_nid is OBJ_obj2nid(sig_alg->algorithm) with 4.0.0's OBJ_obj2nid:
    • a null or empty object gives NID_undef, even when its nid field is set;
    • otherwise a set nid field is returned;
    • otherwise the objects added with OBJ_create are searched first, then the built-in table.
  • X509_get_ext_by_NID is X509v3_get_ext_by_NID with 4.0.0's OBJ_nid2obj and OBJ_cmp:
    • an unknown NID returns -2 and queues OBJ_R_UNKNOWN_NID;
    • lastpos below -1 starts from 0;
    • extensions are compared by encoded OID only;
    • NID 0 and the built-in objects without an OID match extensions with an empty object, as in 4.0.0.
  • The built-in table is 4.0.0's, not libSceLibreSsl's 2.5.4 one:
    • src/Objects.cpp adds the 100 objects (NIDs 956 to 1055) that 4.0.0's objects.txt and obj_mac.num define after 2.5.4. Examples are acmeIdentifier and RSA-SHA3-256; 13 of them have no OID.
    • It reuses the parent's 2.5.4 table for the rest. 4.0.0 changes or removes none of those entries.
    • The search order is 4.0.0's obj_objs: the parent's 2.5.4 order with the 87 new OIDs merged in by length and bytes, ties by NID.
    • The search is the BSD bsearch loop. OID 1.3 is shared by NIDs 379 and 676, and for it the search gives 676.
  • I generated the 100 entries with a script that follows objects.pl and obj_dat.pl. Run on 2.5.4's objects.txt and obj_mac.num, the same script reproduces libSceLibreSsl's existing ObjectTable.cpp exactly: all 949 entries, their encodings and the 890-entry order.
  • libSceLibreSsl gains two helpers over its added-object table, LibreSslAddedObjectsExist_nid_no_patch and LibreSslAddedObjectByNid_nid_no_patch. They let the lookup follow 4.0.0's added checks.
  • Inputs that 4.0.0 dereferences or overflows throw:
    • a null certificate, certificate info or signature algorithm;
    • a null extension array, extension or extension object;
    • null object data where it is compared;
    • a lastpos of INT_MAX;
    • once objects are added, a negative length or one of 2048 or more, which overflows added_obj_hash's length << 20.
  • An unknown NID returns -2 before lastpos is incremented, so INT_MAX with an unknown NID still returns -2.

The forwarded 2.5.4 OBJ_create numbers added objects from 956, where 4.0.0 starts at 1056. Those NIDs belong to 4.0.0 built-in objects, so X509_get_ext_by_NID finds an added object by NID only from 1056. This is recorded in docs/dev/debt/libSceLibreSsl3.md, and the export inventory is updated (108 exports, 99 named).

OBJ_obj2nid, OBJ_nid2sn and OBJ_sn2nid stay forwarded to libSceLibreSsl's 2.5.4 versions; OBJ_obj2nid still throws there (#14115 implements it). So X509_get_signature_nid can return 1050 for an OID that the forwarded functions do not know. Moving those exports to the 4.0.0 table belongs in its own pull request.

No title's trace or disassembly was used, and nothing was measured on a PS5.

pr_overlap reports no pull request with the same exports or new files. It could not compare 40 pull requests that conflict with main and share AdditionalExports.cpp, CMakeLists.txt, include/Api.hpp or the debt file. I checked their diffs by hand: none adds these three exports, OBJ_nid2obj, an object lookup or the parent helpers. Line conflicts to expect:

  • Most open libSceLibreSsl3 pull requests edit the export inventory count in the debt file and the neighbouring lines of CMakeLists.txt and Api.hpp.

I will merge main into this one as needed.

Tested

Windows 11, MinGW-w64 GCC (WinLibs), Release build. No title or homebrew, and not built on Linux or macOS.

  • guest_libressl3_x509_accessors (new) passes:
    • Public key: the key pointer, a null key, and null certificate or certificate info, with the other fields poisoned.
    • Every built-in object:
      • Each of the 884 parent objects with an OID is found by its encoding, with 379 giving 676.
      • Each of the 87 new OIDs is found from the test's own dotted strings, encoded by the test.
    • Unknown objects: longer, shorter and altered OIDs, an empty object with its nid field set, negative lengths, null data and lengths that overflow the comparison.
    • Added objects:
      • an added OID is found, and an added copy of sha256WithRSAEncryption wins over the built-in one;
      • built-in OIDs are still found while added objects exist;
      • the hash-overflow lengths throw only while added objects exist;
      • OBJ_cleanup restores the built-in results.
    • Extension search: first and later matches, lastpos from INT_MIN to past the end, duplicates, NID 0 and name-only NIDs on an empty object, comparison by data only, and negative, zero and short counts.
    • Unknown NIDs: -1, INT_MIN, INT_MAX, every hole in the table and 1056 return -2 and queue exactly one OBJ_R_UNKNOWN_NID each.
    • Added NIDs: an added object numbered below 1056 does not shadow the built-in object, and the object numbered 1056 is found by NID until OBJ_cleanup.
  • Three deliberate bugs make the test fail:
    • leaving the 87 new objects out of the search;
    • skipping the added objects;
    • the earlier check that let the hash-overflow lengths through.
  • All 104 guest_libressl* and guest_crypto_memcmp tests pass.
  • After merging main f6ed718 into this branch, all 107 guest_libressl* and guest_crypto_memcmp tests pass, guest_libressl3_x509_accessors among them. The conflicts were the export inventory count and its table in the debt file, and the neighbouring test registration in CMakeLists.txt.
  • tools/check_test_registration.py passes.
  • objdump -p on libSceLibreSsl3.prx lists the three exports and no mbedtls_* symbol.
  • python3 tools/check_conventions.py --base upstream/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

…nd extension lookup accessors

Implement X509_get_X509_PUBKEY, X509_get_signature_nid and
X509_get_ext_by_NID after LibreSSL 4.0.0 x509_set.c, x_x509.c, x509_ext.c
and x509_v3.c. The object lookups follow 4.0.0 OBJ_obj2nid and
OBJ_nid2obj over libSceLibreSsl's 2.5.4 object table plus the 100 objects
4.0.0 adds, searched with a BSD bsearch, and consult the objects added
through the forwarded OBJ_create first, as 4.0.0 does. libSceLibreSsl
gains two helpers that expose its added-object table. Record the
unverified console behaviour and the NID overlap of added objects as
debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 15591 docs/dev/debt/libSceLibreSsl3.md L80
PR 15737 core/libs/prx/libSceLibreSsl3/include/Api.hpp L65
PR 15831 docs/dev/debt/libSceLibreSsl3.md L80
PR 16535 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp L452-457
docs/dev/debt/libSceLibreSsl3.md L193-194
PR 16654 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L31
PR 16690 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L31
PR 16742 docs/dev/debt/libSceLibreSsl3.md L80
PR 17067 docs/dev/debt/libSceLibreSsl3.md L132-133
PR 17235 core/libs/prx/libSceLibreSsl3/include/Api.hpp L316
docs/dev/debt/libSceLibreSsl3.md L80, L107
X509_get_ext_by_NID
PR 17236 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp L452-459
docs/dev/debt/libSceLibreSsl3.md L80, L193-194
PR 17237 docs/dev/debt/libSceLibreSsl3.md L80
PR 17239 core/libs/prx/libSceLibreSsl3/include/Api.hpp L400 X509_get_X509_PUBKEY
PR 17240 core/libs/prx/libSceLibreSsl3/include/Api.hpp L342
docs/dev/debt/libSceLibreSsl3.md L80, L132
X509_get_signature_nid
PR 17241 docs/dev/debt/libSceLibreSsl3.md L80
PR 17243 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp L203-210
core/libs/prx/libSceLibreSsl3/include/Api.hpp L315-316
docs/dev/debt/libSceLibreSsl3.md L80, L106-107
PR 17249 docs/dev/debt/libSceLibreSsl3.md L80
PR 17250 docs/dev/debt/libSceLibreSsl3.md L80
PR 17528 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp L285-292
core/libs/prx/libSceLibreSsl3/include/Api.hpp L341-342
docs/dev/debt/libSceLibreSsl3.md L80, L131-132

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.

Pull request Shared files not compared
PR 11176 core/libs/prx/libSceLibreSsl/include/ObjectTable.hpp
core/libs/prx/libSceLibreSsl/src/ObjectCreate.cpp
PR 12315 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 14212 docs/dev/debt/libSceLibreSsl3.md
PR 14465 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15163 core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15514 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15544 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15616 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15618 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15620 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15622 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15623 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15625 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15627 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15628 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15629 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16529 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16543 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16586 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16589 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16819 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16848 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16918 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16977 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16979 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16980 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16981 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16996 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17124 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17544 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17621 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17622 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17626 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md

@JJenkx

JJenkx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 63b7e20b10, merged onto main c32f751139 (dd0841e77a, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_libressl3_x509_accessors passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Progress report (f6ed718 → 9d9353e)

📈 System libraries: 35.11% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libSceLibreSsl3 X509_get_X509_PUBKEY_nid_postfix
libSceLibreSsl3 X509_get_ext_by_NID_nid_postfix
libSceLibreSsl3 X509_get_signature_nid_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 509/680 (74.85%) 512/680 (75.29%) +0.44%

…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 7, 2026
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 8, 2026
Ducengarth and others added 2 commits November 8, 2026 14:33
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 8, 2026
Ducengarth and others added 2 commits November 8, 2026 16:35
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 8, 2026
…/libressl3-x509-accessors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 8, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 9, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 9, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 9, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 9, 2026
@oneandonlydean
oneandonlydean merged commit ea0a5cd into boykopovar:main Nov 9, 2026
11 checks passed
@Ducengarth
Ducengarth deleted the feat/libressl3-x509-accessors branch November 26, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants