Skip to content

Improve verify and x509 CLI compatibility - #3548

Merged
justsmth merged 5 commits into
aws:mainfrom
justsmth:openssl-verify-x509-compat
Sep 21, 2026
Merged

justsmth merged 5 commits into
aws:mainfrom
justsmth:openssl-verify-x509-compat

Conversation

@justsmth

@justsmth justsmth commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Context and motivation

Scripts written against OpenSSL's verify and x509 break on the AWS-LC tool: verify requires -CAfile and lacks -CApath/-purpose/-no-CAfile/-no-CApath/-verbose; x509 -subject prints CN = value instead of CN=value, defeating the common sed 's/.*CN=//' idiom; -nameopt is rejected; and -text prints the CT SCT-list extension as a raw OID. Separately, X509_LOOKUP_hash_dir splits directory lists on : on Windows, mangling drive letters.

Description of changes

  • verify: -CAfile is optional and falls back to the default trust store (SSL_CERT_FILE/SSL_CERT_DIR). Adds -CApath, -no-CAfile, -no-CApath, -purpose, and -verbose (no-op). Explicit paths replace their defaults; -no-* disables a default only. -purpose also selects the matching trust type, so TRUSTED CERTIFICATE trust/reject attributes are honored as in OpenSSL. Exit codes follow OpenSSL: 1 for setup errors (including a non-directory -CApath, checked up front since X509_LOOKUP_add_dir defers filesystem access), 2 for any load/verify failure. Per-input errors print as they occur.
  • x509: -subject defaults to CN=value. New -nameopt accepts the presets compat, oneline, RFC2253, multiline; when given it also applies to -text's Issuer/Subject lines. -nameopt oneline restores the old -subject format.
  • Registers NID_ct_precert_scts (1.3.6.1.4.1.11129.2.4.2) so -text labels it "CT Precertificate SCTs". Name only; no SCT parsing. Generated files regenerated via crypto/obj/objects.go.
  • by_dir.c: use ; as the list separator on Windows, matching OpenSSL and the existing X509_LOOKUP_add_dir header comment.
  • test_util.h: ExecuteCommand re-quotes commands on Windows so cmd.exe doesn't strip the outer quotes.

Testing

New tests: ObjTest.CTPrecertSCTs; X509Test.HashDir*; VerifyChainTest.* and VerifyTrustTest.* (generated root/intermediate/leaf chain covering -CApath, -purpose, trust/reject attributes, -no-* with env-var defaults, exit codes, per-input errors, plus OpenSSL comparisons); X509Test.Subject*/Text*/Nameopt* (exact output per preset checked against OpenSSL 3.6.4, the sed CN idiom on a multi-CN/multi-valued-RDN subject, control-char escaping, SCT label vs. an unregistered OID).

Affected crypto_test/tool_openssl_test filters pass on macOS (vs OpenSSL 3.6.4), Ubuntu 24.04 x86-64 (vs 3.0.13, also under Valgrind), and Windows Server 2022/MSVC 19.40 (vs 3.6.3).

Review considerations

  • -nameopt accepts only the four presets, not OpenSSL's comma-separated flags (oneline,-esc_msb now exits 1). This is the one existing command line that could newly fail.
  • -subject output changes from CN = value to CN=value, matching OpenSSL 3.x. Default -text output is unchanged (still X509_print), so it does not pick up OpenSSL 3.x's UTF-8 rendering; switching it is a possible follow-up.
  • The 1.3 entry swap in kNIDsInOIDOrder (obj_dat.h) is regeneration noise from objects.go's unstable sort over two identical OIDs, not a change here.
  • Public API: only the additive NID_/SN_/LN_/OBJ_ct_precert_scts defines.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@justsmth
justsmth requested a review from a team as a code owner September 18, 2026 16:09

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread crypto/obj/obj_dat.h
Comment thread crypto/obj/obj_dat.h
@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security Review — View Report

Please review before merging.

@codecov-commenter

codecov-commenter commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.45205% with 105 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.35%. Comparing base (05adf18) to head (eb5e79c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tool-openssl/verify_test.cc 72.80% 55 Missing and 7 partials ⚠️
tool-openssl/x509_test.cc 88.72% 12 Missing and 3 partials ⚠️
crypto/x509/x509_test.cc 75.00% 6 Missing and 4 partials ⚠️
tool-openssl/x509.cc 80.95% 8 Missing ⚠️
tool-openssl/verify.cc 90.00% 6 Missing ⚠️
tool-openssl/test_util.h 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3548      +/-   ##
==========================================
+ Coverage   78.24%   78.35%   +0.11%     
==========================================
  Files         700      700              
  Lines      126282   126759     +477     
  Branches    17440    17501      +61     
==========================================
+ Hits        98810    99327     +517     
+ Misses      26594    26543      -51     
- Partials      878      889      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@justsmth
justsmth force-pushed the openssl-verify-x509-compat branch from 1fe0699 to 07ed70a Compare September 18, 2026 16:44
@justsmth
justsmth requested review from WillChilds-Klein, samuel40791765 and skmcgrail and removed request for samuel40791765 September 18, 2026 17:56
skmcgrail
skmcgrail previously approved these changes Sep 18, 2026
Comment thread tool-openssl/verify.cc Outdated
@justsmth
justsmth enabled auto-merge (squash) September 18, 2026 21:42
gtest has no printer for the VerifyTrustCase parameter struct, so it falls
back to hex-dumping the object's raw bytes when naming each TEST_P instance.
The struct has four bytes of tail padding that the aggregate initializers
never write, and Valgrind reports the snprintf("%02X") over them as a use of
uninitialised values, failing every valgrind shard that runs the suite.

Define PrintTo so gtest prints the fields instead, which also makes the
parameterized test names readable.
The file loop printed the error queue after each failed check() so the
next iteration's ERR_clear_error() would not discard it, while the stdin
path relied on tool.cc printing the queue after exit. The two paths were
equivalent in effect but looked asymmetric.

Move the per-input reporting into check() itself, matching the structure
of OpenSSL's verify: clear the queue, run the check, and print any errors
on failure. Both input paths now share it and the caller loop returns to
a one-liner.
Pre-C++11 glibc only defines the PRI* macros for C++ when
__STDC_FORMAT_MACROS is set, so the powerpc-old-glibc build failed with
"expected ')' before 'PRIx32'". Format the hash as unsigned long instead,
which is what tool-openssl/verify_test.cc already does for the same value.
createTempDirPath creates its directory under /tmp, which an Android app
process cannot write to, so the test fails on every Device Farm device and
takes the rest of the android-omnibus matrix down with it via fail-fast.
Skip it on Android as the other temp-file tests already do.
Comment thread tool-openssl/verify.cc
Comment on lines +208 to 212
bssl::UniquePtr<BIO> input(BIO_new_fp(stdin, BIO_NOCLOSE));
if (!input) {
return 0;
}
cert.reset(PEM_read_bio_X509(input.get(), nullptr, nullptr, nullptr));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like this case is not covered by tests

@justsmth
justsmth merged commit 01338f5 into aws:main Sep 21, 2026
474 of 477 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants