Skip to content

Improve validity encoding for certificates - #49

Merged
lealem47 merged 1 commit into
wolfSSL:masterfrom
sebastian-carpenter:rounded-cert-validity
Jul 23, 2026
Merged

Improve validity encoding for certificates#49
lealem47 merged 1 commit into
wolfSSL:masterfrom
sebastian-carpenter:rounded-cert-validity

Conversation

@sebastian-carpenter

Copy link
Copy Markdown
Contributor

Fixes F-5327

The validity encoding part of cert generation previously relied on the validDays API from wolfcrypt, updated the code to use exact dates for encoding. ASN.1 encoding for the times is now done in the GO wrapper because of this but the result should be more robust.

Inputs styles for generating certificates (also defined in wolfx509/README.md):

  • NotBefore and NotAfter - the literal validity
  • NotAfter alone - NotBefore is set to now then backdated one day to match wolfcrypt.
  • ValidDays alone - NotBefore calculated as above. NotAfter will be ValidDays after now.

Intentionally left out the NotBefore + ValidDays combination. But it could be added later if desired.

I had to change the test vectors but this should maintain backwards compatibility. Otherwise, a lot of vectors were added to confirm correctness.

@sebastian-carpenter sebastian-carpenter self-assigned this Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 21:16
@sebastian-carpenter
sebastian-carpenter requested review from Copilot and lealem47 and removed request for Copilot July 22, 2026 21:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates certificate generation validity handling in wolfx509 to stop relying on wolfCrypt’s daysValid-based API and instead encode NotBefore/NotAfter explicitly in the Go wrapper, supporting exact-date validity windows and a ValidDays convenience mode.

Changes:

  • Introduces Certificate.ValidDays and a resolveValidity() helper to derive (NotBefore, NotAfter) from supported input combinations.
  • Encodes ASN.1 UTCTime vs GeneralizedTime in Go (encodeValidityTime) and writes the encoded values into the wolfCrypt Cert struct fields.
  • Updates and expands tests to validate validity resolution and ASN.1 encoding, including GeneralizedTime coverage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wolfx509/README.md Documents supported validity input modes and the one-day backdate behavior.
wolfx509/certificate.go Adds ValidDays to the Certificate template.
wolfx509/certgen.go Switches to resolved (NotBefore, NotAfter) and adds ASN.1 time encoding helpers.
wolfx509/certgen_wolfcrypt.go Writes encoded validity times into wolfCrypt cert buffers instead of using daysValid.
wolfx509/certgen_test.go Updates existing vectors and adds broader tests for validity resolution and encoding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wolfx509/certgen.go
Comment thread wolfx509/certgen_wolfcrypt.go

@lealem47 lealem47 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.

@lealem47
lealem47 merged commit cd4a322 into wolfSSL:master Jul 23, 2026
5 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.

3 participants