Skip to content

ssh-key: allow u64::MAX as "no expiry" sentinel in UnixTime#504

Merged
tarcieri merged 1 commit into
RustCrypto:masterfrom
gvz:master
May 10, 2026
Merged

ssh-key: allow u64::MAX as "no expiry" sentinel in UnixTime#504
tarcieri merged 1 commit into
RustCrypto:masterfrom
gvz:master

Conversation

@gvz
Copy link
Copy Markdown
Contributor

@gvz gvz commented May 8, 2026

OpenSSH PROTOCOL.certkeys specifies that valid_before=0xffffffffffffffff (u64::MAX) means the certificate never expires. Previously UnixTime::new rejected this value because it exceeds MAX_SECS (i64::MAX), causing Certificate parsing to fail for any cert generated without an explicit validity window (e.g. ssh-keygen -s ca -h key.pub without -V).

Add FOREVER_SECS=u64::MAX constant. In new(), cap its SystemTime representation at MAX_SECS to keep a valid SystemTime while preserving the raw secs value for round-trip encoding correctness.

Fixes: #503

OpenSSH PROTOCOL.certkeys specifies that valid_before=0xffffffffffffffff
(u64::MAX) means the certificate never expires. Previously UnixTime::new
rejected this value because it exceeds MAX_SECS (i64::MAX), causing
Certificate parsing to fail for any cert generated without an explicit
validity window (e.g. ssh-keygen -s ca -h key.pub without -V).

Add FOREVER_SECS=u64::MAX constant. In new(), cap its SystemTime
representation at MAX_SECS to keep a valid SystemTime while preserving
the raw secs value for round-trip encoding correctness.

Fixes: RustCrypto#503
@tarcieri tarcieri changed the title ssh-key: accept u64::MAX as OpenSSH "no expiry" sentinel in UnixTime ssh-key: allow u64::MAX as "no expiry" sentinel in UnixTime May 10, 2026
#[cfg(not(feature = "std"))]
pub fn new(secs: u64) -> Result<Self> {
if secs <= MAX_SECS {
if secs == FOREVER_SECS || secs <= MAX_SECS {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like the FOREVER_SECS case could use a convenience constructor like pub fn new_non_expiring or something to that effect, but that can be added as a followup

@tarcieri tarcieri merged commit 51bd0aa into RustCrypto:master May 10, 2026
14 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.

certificates with infinite validity fail to parse

2 participants