Skip to content

[SDK] Stamp generated certificates with aware UTC datetimes - #154

Merged
V2arK merged 1 commit into
mainfrom
honglin/aware-cert-datetimes
Sep 17, 2026
Merged

V2arK merged 1 commit into
mainfrom
honglin/aware-cert-datetimes

Conversation

@V2arK

@V2arK V2arK commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

datetime.utcnow() returns a naive datetime holding UTC numbers. Anything that
later calls .timestamp() on such a value gets it interpreted as local time, so
the result is off by the host's UTC offset — silently, and invisibly on a UTC
machine:

TZ=America/New_York
time.time()            1789656016
aware.timestamp()      1789656016   +0s
naive.timestamp()      1789670416   +14400s

Python 3.12 already emits a DeprecationWarning for it, and cryptography has
been steering callers off naive datetimes, so certificate generation would
eventually fail rather than merely warn.

No behaviour change today

cryptography treats a naive datetime as UTC, and utcnow() supplied UTC
numbers, so the two mistakes cancelled out. This only removes the coincidence.

Test plan

./.venv/bin/python -m pytest tests/ -q                          # 119 passed
python -m pylint --rcfile ./scripts/pylintrc ./centml ./tests   # 10.00/10
python -m black --check ...                                     # 24 files unchanged
mypy centml tests                                               # no issues in 24 source files

generate_ca_client_triplet() run under TZ=America/New_York with
-W error::DeprecationWarning, so any surviving warning fails the check:

Check Result
Warning-free generation no DeprecationWarning raised under -W error
CA bounds 2026-09-17T14:42:14+00:00 .. 2031-09-16T14:42:14+00:00, tzinfo=UTC
Client bounds same instants, tzinfo=UTC
Validity span 1825 days, both certificates
notBefore falls inside the call window measured around generation
Chain client issued by the CA, and its ECDSA signature verifies against the CA public key

datetime.utcnow() returns a naive datetime holding UTC numbers, which reads as
local time to anything that later calls .timestamp() on it — a silent offset
equal to the host's UTC offset, invisible on a UTC machine. Python 3.12 already
warns on it, and cryptography has been steering callers off naive datetimes, so
certificate generation would eventually stop working rather than merely warn.

Nothing changes today: cryptography treats a naive datetime as UTC, and
utcnow() supplied UTC numbers, so the two mistakes cancelled. Verified under
TZ=America/New_York with -W error::DeprecationWarning that generation is silent
and that both certificates carry aware UTC bounds, a 1825-day span, and a
signature that verifies against the CA.

Signed-off-by: Honglin Cao <hocao@nvidia.com>
@V2arK
V2arK force-pushed the honglin/aware-cert-datetimes branch from 9fed11d to 97b9e51 Compare September 17, 2026 14:43
@anandj91

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-17T15:02:31.985646Z 97b9e51 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 97b9e5129e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@V2arK
V2arK merged commit fcb0273 into main Sep 17, 2026
5 checks passed
@V2arK
V2arK deleted the honglin/aware-cert-datetimes branch September 17, 2026 15:04
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.

2 participants