feat(libSceLibreSsl3): implement the X509 notBefore, notAfter and signature getters #10491

Merged
alvaroelpob merged 12 commits from upstream-pr/10491 into main 2026-11-06 04:03:11 +00:00
alvaroelpob commented 2026-10-24 03:21:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T03:21:02Z.


What

Implements X509_getm_notBefore, X509_getm_notAfter, X509_get0_notBefore, X509_get0_notAfter and X509_get0_signature in libSceLibreSsl3, which threw and were declared without parameters.

The module is LibreSSL 4.0.0 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's x509_local.h, x509_set.c and x_x509.c:

Export Behaviour
ASN1_TIME* X509_getm_notBefore(const X509*) null if the certificate, cert_info or validity is null, otherwise validity->notBefore
ASN1_TIME* X509_getm_notAfter(const X509*) the same with notAfter
const ASN1_TIME* X509_get0_notBefore(const X509*) X509_getm_notBefore
const ASN1_TIME* X509_get0_notAfter(const X509*) X509_getm_notAfter
void X509_get0_signature(const ASN1_BIT_STRING**, const X509_ALGOR**, const X509*) writes signature and sig_alg through the non-null output pointers

The layouts are 216 bytes for X509 (sig_alg at 8, signature at 16), 104 for X509_CINF (validity, a pointer, at 32) and 16 for X509_VAL (notBefore, notAfter). They were checked with static_asserts and against offsetof from the 4.0.0 headers compiled on x86-64. X509_get0_signature reads the certificate only for the outputs requested, as LibreSSL does: with both outputs null it returns without reading it, and a null certificate throws only when an output is requested, where LibreSSL would dereference it. No export of this module creates a certificate yet, so for now only certificates built by the caller reach these functions.

The debt entry records the source and what is unverified. The pending-export count drops from 84 to 79, and the five names join the exclusion list.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl3_x509_validity test and check_conventions.py run on its own.

  • New guest_libressl3_x509_validity test. The four time getters return null for a null certificate, a null cert_info, a null validity and a null field, and return their own field, not the other one. X509_get0_signature writes null fields, then the signature and algorithm, each through its own output only, accepts both outputs null, also with a null certificate, and throws for a null certificate when either output is requested. The fixtures are the public LibreSsl3X509Validity, LibreSsl3ValidityCertInfo and LibreSsl3ValidityX509.
  • Full ctest -j16 at the last commit: 2005/2006 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • Not tested: Windows, a title.
  • Rebased on main e7e3e9c198, head a2c3fa4587. The branch still merged cleanly, but after #10706 public_headers fails on the merge: the exports kept their (void) stubs in include/Api.hpp and the test redeclared them. a2c3fa4587 (refactor(libSceLibreSsl3): declare the X509 validity exports in the public header) puts the real signatures and their structs in libSceLibreSsl3/include/Api.hpp and drops the test's redeclarations. Full build and ctest -j16: 2202/2203 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 6e775f452a, head 8b44f2b4b1, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Review fixes 82d32bab09, 81d4732676 and 8b44f2b4b1 make X509_get0_signature with both outputs null return without reading the certificate, build the tests on the public structs and update the debt entry; guest_libressl3_x509_validity passes. Full build and ctest -j16: 2268/2269 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 74acfad65b (after #10948), head db1a62489f, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. Full build and ctest -j16: 2431/2432 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 365d7689ca, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep main's names and add this PR's, and the count, 72, matches the stubs in Export.cpp. Full build and ctest -j16: 3157/3157 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main 4939814d79 (after #9535 and #9970), head e1e1ee0426, to resolve the conflicts on the shared Export.cpp, Api.hpp and debt-file lines; both sides are kept. main says 76 pending exports with 74 stubs left, so the count is set to the 69 stubs left in Export.cpp. Full build and ctest -j16: 3538/3538 pass. check_conventions.py --base upstream/main passes.
  • Merged main b11c7bf84f (after #10557), head 5f3d95a631, to resolve the conflicts on the shared CMakeLists.txt, Api.hpp and debt-file lines; both sides are kept, X509_PUBKEY_get0_param stays in the exclusion list, and the count is set to the 68 stubs left in Export.cpp. Full build and ctest -j16: 3883/3883 pass. 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: #10452, #10461, #10490
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992088813 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10491). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T03:21:02Z. --- ### What Implements `X509_getm_notBefore`, `X509_getm_notAfter`, `X509_get0_notBefore`, `X509_get0_notAfter` and `X509_get0_signature` in libSceLibreSsl3, which threw and were declared without parameters. The module is LibreSSL 4.0.0 ([firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, layouts and results follow that release's [`x509_local.h`, `x509_set.c`](https://github.com/libressl/openbsd/tree/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/x509) and [`x_x509.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/asn1/x_x509.c): | Export | Behaviour | |---|---| | `ASN1_TIME* X509_getm_notBefore(const X509*)` | null if the certificate, `cert_info` or `validity` is null, otherwise `validity->notBefore` | | `ASN1_TIME* X509_getm_notAfter(const X509*)` | the same with `notAfter` | | `const ASN1_TIME* X509_get0_notBefore(const X509*)` | `X509_getm_notBefore` | | `const ASN1_TIME* X509_get0_notAfter(const X509*)` | `X509_getm_notAfter` | | `void X509_get0_signature(const ASN1_BIT_STRING**, const X509_ALGOR**, const X509*)` | writes `signature` and `sig_alg` through the non-null output pointers | The layouts are 216 bytes for `X509` (`sig_alg` at 8, `signature` at 16), 104 for `X509_CINF` (`validity`, a pointer, at 32) and 16 for `X509_VAL` (`notBefore`, `notAfter`). They were checked with `static_assert`s and against `offsetof` from the 4.0.0 headers compiled on x86-64. `X509_get0_signature` reads the certificate only for the outputs requested, as LibreSSL does: with both outputs null it returns without reading it, and a null certificate throws only when an output is requested, where LibreSSL would dereference it. No export of this module creates a certificate yet, so for now only certificates built by the caller reach these functions. The debt entry records the source and what is unverified. The pending-export count drops from 84 to 79, and the five names join the exclusion list. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON` on `main` 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its `guest_libressl3_x509_validity` test and `check_conventions.py` run on its own. - New `guest_libressl3_x509_validity` test. The four time getters return null for a null certificate, a null `cert_info`, a null `validity` and a null field, and return their own field, not the other one. `X509_get0_signature` writes null fields, then the signature and algorithm, each through its own output only, accepts both outputs null, also with a null certificate, and throws for a null certificate when either output is requested. The fixtures are the public `LibreSsl3X509Validity`, `LibreSsl3ValidityCertInfo` and `LibreSsl3ValidityX509`. - Full `ctest -j16` at the last commit: 2005/2006 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - Not tested: Windows, a title. - Rebased on `main` e7e3e9c198, head a2c3fa4587. The branch still merged cleanly, but after #10706 `public_headers` fails on the merge: the exports kept their `(void)` stubs in `include/Api.hpp` and the test redeclared them. a2c3fa4587 (`refactor(libSceLibreSsl3): declare the X509 validity exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl3/include/Api.hpp` and drops the test's redeclarations. Full build and `ctest -j16`: 2202/2203 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 6e775f452a, head 8b44f2b4b1, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Review fixes 82d32bab09, 81d4732676 and 8b44f2b4b1 make `X509_get0_signature` with both outputs null return without reading the certificate, build the tests on the public structs and update the debt entry; `guest_libressl3_x509_validity` passes. Full build and `ctest -j16`: 2268/2269 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 74acfad65b (after #10948), head db1a62489f, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. Full build and `ctest -j16`: 2431/2432 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 365d7689ca, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep `main`'s names and add this PR's, and the count, 72, matches the stubs in `Export.cpp`. Full build and `ctest -j16`: 3157/3157 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 4939814d79 (after #9535 and #9970), head e1e1ee0426, to resolve the conflicts on the shared `Export.cpp`, `Api.hpp` and debt-file lines; both sides are kept. `main` says 76 pending exports with 74 stubs left, so the count is set to the 69 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3538/3538 pass. `check_conventions.py --base upstream/main` passes. - Merged `main` b11c7bf84f (after #10557), head 5f3d95a631, to resolve the conflicts on the shared `CMakeLists.txt`, `Api.hpp` and debt-file lines; both sides are kept, `X509_PUBKEY_get0_param` stays in the exclusion list, and the count is set to the 68 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3883/3883 pass. `check_conventions.py --base upstream/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #10452, #10461, #10490 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 03:22:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T03:22:54Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636634603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10491#pullrequestreview-5636634603). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T03:22:54Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-24 12:14:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:14:46Z.

Review: APPROVED


Reviewed head 5a11f928979734bdf574849cbd771c86b892c36a.

I checked the five implementations against the pinned LibreSSL 4.0.0 x509_set.c, x_x509.c, and x509_local.h. The validity getters match the source's null checks and field selection; the get0 getters delegate to their mutable counterparts. X509_get0_signature writes only requested outputs and matches the source's null-certificate dereference behavior via the project's exception convention. The asserted layouts and offsets agree with the pinned structures. I found no blocking correctness issue in this diff.

The PR reports focused getter tests and a 2005/2006 full CTest run, with the remaining failure reproduced on main; I did not reproduce that build or test run locally. Current hosted convention, labels, eligibility, and report checks pass; the Linux, Windows, register-context, relinker, write-watch, and ASan jobs are skipped. The overlap report with #10557 is shared build/export/debt files, not the same exports; coordinate those file edits when composing the changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638202573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10491#pullrequestreview-5638202573). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:14:46Z. **Review:** APPROVED --- Reviewed head `5a11f928979734bdf574849cbd771c86b892c36a`. I checked the five implementations against the pinned LibreSSL 4.0.0 `x509_set.c`, `x_x509.c`, and `x509_local.h`. The validity getters match the source's null checks and field selection; the `get0` getters delegate to their mutable counterparts. `X509_get0_signature` writes only requested outputs and matches the source's null-certificate dereference behavior via the project's exception convention. The asserted layouts and offsets agree with the pinned structures. I found no blocking correctness issue in this diff. The PR reports focused getter tests and a 2005/2006 full CTest run, with the remaining failure reproduced on main; I did not reproduce that build or test run locally. Current hosted convention, labels, eligibility, and report checks pass; the Linux, Windows, register-context, relinker, write-watch, and ASan jobs are skipped. The overlap report with #10557 is shared build/export/debt files, not the same exports; coordinate those file edits when composing the changes.
ahmadmuj commented 2026-10-25 19:22:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T19:22:17Z.

Review: APPROVED


Linux run of 8b44f2b4b1 merged onto main ae7d59258e (clean, tree c8661df2e8). Ubuntu 24.04 on WSL2, GCC 13.3, Release, BUILD_TESTING=ON, built only guest_libressl3_x509_validity_tests.

  • guest_libressl3_x509_validity passes, --repeat until-fail:3.
  • Red controls, each rebuilt and run against the PR's test:
    • the a2c3fa4587 body (throws on any null certificate): aborts at line 108 with null certificate, so the new no-output case is pinned
    • X509_getm_notBefore reading notAfter: fails at line 34
    • X509_get0_signature writing sig_alg into the signature output: fails at line 101
    • X509_get0_notAfter calling the notBefore getter: fails at line 85
    • dropping the cert_info null check: segfaults
  • tools/check_conventions.py --base origin/main passes.

Checked against LibreSSL 4.0.0 (x509_set.c 150-206, x_x509.c 380-388): the getm getters return NULL for a null cert, cert_info or validity, the get0 getters delegate, and X509_get0_signature writes only the non-null outputs, in the same (psig, palg, x) order. The only difference is the throw for a null cert with an output requested, and the debt entry says so.

Layout: I compiled offsetof against the 4.0.0 headers. x509_st has sig_alg at 8 and signature at 16 (size 216), X509_CINF has validity at 32 (size 104), and X509_VAL is 16 bytes, all matching your static_asserts. The same program against 2.5.4 gives the same offsets for those fields (only x509_st's total size differs, 176), so the getters read the right fields either way.

Looks good to me. Not run: a title, or the full suite. AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644857389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10491#pullrequestreview-5644857389). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:22:17Z. **Review:** APPROVED --- Linux run of `8b44f2b4b1` merged onto `main` `ae7d59258e` (clean, tree `c8661df2e8`). Ubuntu 24.04 on WSL2, GCC 13.3, Release, `BUILD_TESTING=ON`, built only `guest_libressl3_x509_validity_tests`. - `guest_libressl3_x509_validity` passes, `--repeat until-fail:3`. - Red controls, each rebuilt and run against the PR's test: - the a2c3fa4587 body (throws on any null certificate): aborts at line 108 with `null certificate`, so the new no-output case is pinned - `X509_getm_notBefore` reading `notAfter`: fails at line 34 - `X509_get0_signature` writing `sig_alg` into the signature output: fails at line 101 - `X509_get0_notAfter` calling the `notBefore` getter: fails at line 85 - dropping the `cert_info` null check: segfaults - `tools/check_conventions.py --base origin/main` passes. Checked against LibreSSL 4.0.0 (`x509_set.c` 150-206, `x_x509.c` 380-388): the getm getters return NULL for a null cert, `cert_info` or `validity`, the get0 getters delegate, and `X509_get0_signature` writes only the non-null outputs, in the same `(psig, palg, x)` order. The only difference is the throw for a null cert with an output requested, and the debt entry says so. Layout: I compiled `offsetof` against the 4.0.0 headers. `x509_st` has `sig_alg` at 8 and `signature` at 16 (size 216), `X509_CINF` has `validity` at 32 (size 104), and `X509_VAL` is 16 bytes, all matching your static_asserts. The same program against 2.5.4 gives the same offsets for those fields (only `x509_st`'s total size differs, 176), so the getters read the right fields either way. Looks good to me. Not run: a title, or the full suite. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10491
No description provided.