Time Breaks a Chain
Every certificate on the path must be inside its validity period at the time of the check; the verify command takes the time from an option so a run can be repeated, and it reports a time before the start once, at the root, but an expired certificate at every depth that has expired.
The question
A chain is only as old as its youngest end date. Every certificate has a start and an end, and the verifier asks about all of them at one moment. Which certificate does the command blame when the moment is wrong, and what does it report when several are wrong at once?
The certificates of this book are test material, 512-bit RSA keys, a toy size far too small to use.
Work it by hand
The check is the same for each certificate on the path: its notBefore must not be after the time of the check and its notAfter must not be before it. Both ends are inclusive, as the validity lesson of A Certificate, Field by Field shows. A verifier asks the time from the clock unless it is given one; -attime takes a number of seconds since 1 January 1970 and makes the run repeatable.
The example chain was made with the start 2026-01-01 00:00:00 for all three certificates and the end 2036-01-01 00:00:00. The number 1790000000 is a time in September 2026, inside all three windows.
The model in the exercise is fixed on one reading: it scans from the root down and returns the first failure, as [error number, depth], where the root of this chain is at depth 2 and the leaf at depth 0. Error 9 means not yet valid and error 10 means expired.
Run it
The demo is one command (lines 3 and 4): verify -attime 1790000000 -CAfile in/root.txt -untrusted in/int.txt in/leaf.txt prints in/leaf.txt: OK.

Public test material, generated for this lesson. Never use it for anything real.
# Verifies the leaf at one fixed time.
# Check runs it with other chains in the three files in/.
openssl verify -attime 1790000000 -CAfile in/root.txt -untrusted in/int.txt \
in/leaf.txt
{
"answer": "in/leaf.txt: OK"
}You can change the number. Measured on this chain: every time from 1767225600 (the start second) to 2082758400 (the end second) gives OK; the number 1767225599 gives error 9 at 2 depth lookup: certificate is not yet valid or the system clock is incorrect, and 2082758401 gives error 10 at 2 and error 10 at 1, and then error 10 at 0, each with depth lookup: certificate has expired. A failing command is shown as a failure on this page.
Your turn
The program below is a model of the time check. not_before is the start that the three certificates share, root_end, int_end and leaf_end are their ends, and at is the time of the check, all as YYYYMMDDHHMMSSZ. Return the first failing [error number, depth] when going from the root down, or [0, -1] if no certificate fails. Judge it, and find the candidates that are right for every input. Check runs each candidate on the data shown and on eleven others.

Public test material, generated for this lesson. Never use it for anything real.
fn num(t: string) -> int { return str_to_int(str_replace(t, "Z", "")); }
let ends = int_list();
ends.add(num(leaf_end));
ends.add(num(int_end));
ends.add(num(root_end));
let now = num(at);
let err = 0;
let depth = -1;
for (i in range(0, 3)) {
if (err == 0 && now < num(not_before)) { err = 9; depth = i; }
if (err == 0 && now > ends.at(i)) { err = 10; depth = i; }
}
let answer = int_list();
answer.add(err);
answer.add(depth);
{
"answer": [
10,
0
]
}not_before is the start that the root, the intermediate and the leaf share; root_end, int_end and leaf_end are their ends; at is the time of the check; all are texts of the form YYYYMMDDHHMMSSZ. A certificate is valid when not_before <= at <= its end. Go from the root (depth 2) down to the leaf (depth 0) and return a list of two numbers for the first certificate that fails: 9 for a time before the start or 10 for an expired one, then its depth. Return [0, -1] if none fails.
Read the result carefully
The model was checked against the command on chains made for this lesson from the committed keys with only the end dates changed. With the leaf expired the command reports error 10 at 0; with the intermediate expired error 10 at 1; with the root expired error 10 at 2; with the root and the leaf expired error 10 at 2 and then error 10 at 0. A time before the start gives one line, error 9 at 2, although all three certificates are not yet valid.
Exactly at an end second the chain is valid.
The model has one common start and no other checks. The command prints every depth that expired, and the model returns only the first of them.
Recap
- Each certificate on the path needs
notBefore <= time <= notAfter. -attimesets the time, in seconds since 1970, so that a run is repeatable.- A time before the start gives error 9 once, at the root; expiry gives error 10 at each depth that has expired, root first.
- The end second itself is still valid.