Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@exitcode0
Copy link

Summary

Adds a new --valid-days CLI flag to control the validity period of self-signed certificates

If omitted, pivit defaults to previous behavior for backwards compatibility

Motivation

Previously, self-signed certificates generated by pivit had zero NotBefore and NotAfter times, which could cause issues with any tool that couldn't be set up toignore the validity

Changes

  • New flag: --valid-days (integer) - specify validity period in days for self-signed certificates
  • Default: 0 (preserves existing zero-time behavior)
  • When > 0: Sets proper NotBefore/NotAfter with 5-minute negative skew for clock drift
  • Backwards compatible: Existing workflows unchanged, opt-in only

More Change Details

  • When --valid-days > 0: Sets proper NotBefore and NotAfter times with 5-minute negative skew for clock drift tolerance
  • When --valid-days = 0 (default): Preserves original behavior with zero times for backwards compatibility
  • Only affects self-signed certificates (--self-sign flag)

Testing

  • TestGenerateCertificate_BackwardsCompatibility(): Verifies zero times when flag not used
  • TestGenerateCertificate_ValidityDays(): Validates proper validity period setting

Example

# Generate self-signed cert valid for 1 year
pivit --generate --self-sign --valid-days 365
# Generate self-signed cert valid for 30 days
pivit --generate --self-sign --valid-days 30
# Original behavior (zero times) - unchanged
pivit --generate --self-sign

Set NotBefore/NotAfter for self-signed certificates with default 2-year
validity and -5 minute skew for clock drift tolerance.

Rationale: Git x509 verification enforces time validity. Previously
self-signed certs used zero-time, causing NotBefore/NotAfter=year 0001.
HACD pipeline uses -no_check_time, but local git verification fails.
Setting sane defaults fixes local UX.

Future: Add CLI option to override validity duration.
Add CLI flag to control certificate validity period in days for
self-signed certificates.

- New flag: --valid-days <N> controls validity in days
- Defaults to 730 days if omitted or <= 0
- Preserves -5m NotBefore skew for clock drift protection
- Integrates with existing self-signed certificate generation
Only set NotBefore/NotAfter when ValidityDays > 0 is explicitly
provided. Preserve original zero-time behavior when ValidityDays = 0
(default value).

- Update CLI help text to clarify new behavior
- Add comprehensive test coverage for both modes
- Ensure existing workflows unchanged when flag not used
- Fix regression from previous commit that changed defaults
@codecov
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.16%. Comparing base (f769868) to head (1ee6407).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
+ Coverage   57.72%   58.16%   +0.43%     
==========================================
  Files          10       10              
  Lines         951      961      +10     
==========================================
+ Hits          549      559      +10     
  Misses        335      335              
  Partials       67       67              

☔ View full report in Codecov by Sentry.
📢 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.

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