Validity Is Two Times
A certificate is valid from notBefore through notAfter, both ends included; each time is a UTCTime with a two-digit year for 1950 to 2049 or a GeneralizedTime with four digits, and a program has to know the difference.
The question
A certificate says when it is valid with two times, notBefore and notAfter. How are the times written in the bytes, what does a two-digit year mean, and is the second at either end still inside the period? Getting any of these wrong makes a program accept a certificate too early or reject it too late.
The certificates of this book are test material, made for the lessons with 512-bit RSA keys, a toy size far too small to use. The page never reads a clock: the time to test is an input.
Work it by hand
RFC 5280, in the section called Validity (within section 4.1), says that the validity period is the period from notBefore through notAfter, inclusive. Both ends belong to it. It also says that dates through the year 2049 are encoded as UTCTime, and dates in 2050 or later as GeneralizedTime.
A UTCTime such as 260101000000Z reads year 26, month 01, day 01, 00:00:00, and Z for UTC: 2026-01-01 00:00:00. The year has two digits. The subsection UTCTime says that YY of 50 or more means 19YY and YY below 50 means 20YY, so 49 is 2049 and 50 is 1950.
A GeneralizedTime such as 20500101000000Z has four digits for the year: 2050-01-01 00:00:00. So a certificate valid from 2026 to 2050 has a notBefore in one encoding and a notAfter in the other.
Run it
The demo is one command (line 3): asn1parse -in in/cert.txt -strparse 62 -noout -out out.der parses the validity of the test certificate dates2050 again, starting at offset 62, the fifth child of its first part. It writes the 34 bytes of the validity to out.der. Read them: 30 20 is a SEQUENCE of 32 bytes. 17 0d is a UTCTime of 13 bytes, the ASCII characters 260101000000Z (32 is the character 2, 36 is 6 and 5a is Z). 18 0f is a GeneralizedTime of 15 bytes, 20500101000000Z.
The tags 17 and 18 tell the two encodings apart; asn1parse without -noout prints them as UTCTIME and GENERALIZEDTIME, measured on this certificate.
The offset 62 belongs to this certificate. Measured: in the leaf certificate the validity starts at offset 99, and at offset 62 the command writes 37 bytes of a different SEQUENCE, the common name of the issuer. For another certificate find the offset by walking the first part as in lesson 2.

Public test material, generated for this lesson. Never use it for anything real.
# Writes the validity, the element at offset 62, to out.der.
# Check runs it with other certificates in in/cert.txt.
openssl asn1parse -in in/cert.txt -strparse 62 -noout -out out.der
{
"answer": "3020170d3236303130313030303030305a180f32303530303130313030303030305a",
"file": "out.der",
"bytes": 34
}Your turn
The program below reads the two times as they are written in the certificate, not_before and not_after, in either encoding, and the time to test as at, written as YYYYMMDDHHMMSSZ. It should return before, valid or expired. Judge it, and find the candidates that are right for every input. Check runs each candidate on the data shown and on ten others.

Public test material, generated for this lesson. Never use it for anything real.
fn full(t: string) -> int {
let s = str_replace(t, "Z", "");
if (str_len(s) == 12) {
s = "20" + s;
}
return str_to_int(s);
}
let a = full(not_before);
let b = full(not_after);
let now = full(at);
let answer = "valid";
if (now < a) { answer = "before"; }
if (now > b) { answer = "expired"; }
{
"answer": "before"
}not_before and not_after are the two times of a certificate, each either a UTCTime of 12 digits and Z (YYMMDDHHMMSSZ) or a GeneralizedTime of 14 digits and Z; at is the time to test as YYYYMMDDHHMMSSZ. A UTCTime year of 50 or more means 19YY and a year below 50 means 20YY. The period is valid from notBefore through notAfter, both seconds included. Return the text before, valid or expired.
Read the result carefully
The program checks the period of validity and nothing else: not the signature, the chain, revocation or the clock of the machine. It treats a text of 12 digits as a UTCTime and any other as a GeneralizedTime with 14 digits; a text in another form is read as a number without a check, so garbage gives garbage.
Measured with the real tool, openssl verify -attime on the test chain: at the second of notBefore the certificate is accepted, one second earlier it is not yet valid, at the second of notAfter it is accepted, and one second later it has expired. Measured on this runtime, the two failing runs end with exit status 2 and OpenSSL says error 9 (not yet valid) and error 10 (expired); they are not part of the exercise.
Recap
- The validity period runs from notBefore through notAfter, both ends included (RFC 5280, section called Validity).
- UTCTime has a two-digit year: 50 to 99 mean 1950 to 1999 and 00 to 49 mean 2000 to 2049.
- GeneralizedTime has four digits and is used from the year 2050.
- The exercise takes the time to test as an input and never reads a clock.