Speed

Expired, and Not Yet Valid

A certificate has two dates and the client compares both with its own clock. An expired leaf is refused with alert 45, certificate_expired, and which alert goes with the other date is the implementation's choice.

The question

A certificate says when it starts and when it ends, and a client checks both against the date on its own clock. What does the client do with a certificate whose end date is already past, and what do the two ends hear?

Both ends are test endpoints in this tab's memory, made with ssl.tls_pair. The server holds the test leaf, with the same key and names as always and other dates, the test intermediate and the key. The page cannot set the clock: the client reads the real date of your computer. The certificates are public test material, made for these lessons.

Work it by hand

The default test leaf is valid from 2026-01-01 to 2036-01-01. The test material has two more leaves with the same key and the same names, signed by the same intermediate, with only the dates changed: one valid from 2020-01-01 to 2021-01-01, the other from 2040-01-01 to 2050-01-01.

A client whose clock reads a day between 2026 and 2036 finds the first leaf valid, the second one over and the third not started. For the one that is over, it refuses and sends a 7-byte alert: 15 03 03 00 02, level 02 and the description 2d, which is 45, certificate_expired. RFC 9846 section 6.2 describes that alert as "A certificate has expired or is not currently valid". Which alert a client sends for each date problem is its own choice.

Run it

Lines 1 to 5 build the pair with leaf_pem as the server's certificate. The loop of lines 7 to 11 lets the ends take turns and keeps the last flight with bytes; lines 12 to 14 read the alert number from it if it is a 7-byte alert. Lines 15 and 16 return the two dates of the certificate you gave. Line 17 returns the alert bytes, line 18 the client's verify_result(), and line 19 the name the server saw and the alert number.

Four rows: the certificate is valid from 2020-01-01T00:00:00Z to 2021-01-01T00:00:00Z, the verify result is certificate has expired and the alert bytes are 15 03 03 00 02 02 2d.

Public test material, generated for this lesson. Never use it for anything real.

let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, host);
let turns = 0; let flights = 0; let last = "";
while (!pair.done() && pair.error() == "" && turns < 10) {
  let flight = pair.step(); turns = turns + 1;
  if (str_len(flight) > 0) { flights = flights + 1; }
  if (str_len(flight) > 0) { last = str_hex_encode(flight); }
}
let code = 0 - 1; let alert = "";
let plain = hex_len(last) == 7 && hex_u8(last, 0) == 21;
if (plain) { code = hex_u8(last, 6); alert = last; }
lmcode_return_put("not_before", ssl.parse_cert(leaf_pem).not_before());
lmcode_return_put("not_after", ssl.parse_cert(leaf_pem).not_after());
lmcode_return_put("alert", alert);
lmcode_return_put("verify_result", pair.verify_result());
let answer = pair.server_name() + " " + str(code);
{
  "answer": "www.example.test 45",
  "not_before": "2020-01-01T00:00:00Z",
  "not_after": "2021-01-01T00:00:00Z",
  "alert": "1503030002022d",
  "verify_result": "certificate has expired"
}

With the expired leaf and www.example.test the answer is www.example.test 45. The dates are 2020-01-01T00:00:00Z and 2021-01-01T00:00:00Z, the alert bytes are 1503030002022d, and what this OpenSSL build says is certificate has expired for verify_result(). These come from this run.

You can change host and leaf_pem. A name the certificate does not list, such as www.example.testx, gives hostname mismatch and alert 42 with the expired leaf too: in this build the name is reported before the dates. The valid leaf finishes the handshake, with an empty alert and -1.

A name such as x or www.example.test. stops line 5 with "Line 5: Ssl.tls_pair: set host to verify". A leaf text that is cut short stops line 1 with "Line 1: Ssl.parse_cert: not a PEM certificate: error:04800066:PEM routines::bad end line", and a certificate that does not belong to the key stops line 1 with "Line 1: Ssl.server_ctx: use private key: error:05800074:x509 certificate routines::key values mismatch".

Your turn

The program below should return one of four words for the client's verdict on the leaf: valid now if the handshake finished, expired if verify_result() says the certificate has expired, not yet valid if it says the certificate is not yet valid, and other refusal for any other refusal. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on six others.

The name that the client asks for in the case shown, www.example.test.

Public test material, generated for this lesson. Never use it for anything real.

let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, host);
let turns = 0; let flights = 0;
while (pair.error() == "" && turns < 2) {
  let flight = pair.step(); turns = turns + 1; flights = flights + 1;
}
let said = pair.verify_result(); let answer = "other refusal";
if (pair.error() == "") { answer = "valid now"; }
if (str_contains(said, "expired")) { answer = "expired"; }
if (str_contains(said, "not yet valid")) { answer = "not yet valid"; }
lmcode_return_put("flights", flights);
{
  "answer": "valid now",
  "flights": 2
}

A client asks for the name host and trusts root_pem; the server holds leaf_pem, int_pem and leaf_key. Both ends are test endpoints in this tab's memory. Run the handshake, taking turns while it is not done and has no error, at most ten times. Return valid now if the handshake finished; otherwise expired if the client's verify_result() contains the word expired, not yet valid if it contains the words not yet valid, and other refusal for any other refusal. Check runs each candidate on the data shown and on six others.

Read the result carefully

The result depends on your clock. A clock before 2026 makes the valid leaf fail as not yet valid, and a clock from 2036 on makes it fail as expired; the intermediate and the root start in 2026, so no clock makes the expired leaf valid, and the page has no way to set the time. The results here hold only between those years. Certificates like these are made with a CA's key, which a-small-certificate-authority shows, and their dates are fields of the certificate, listed in x509-certificates-field-by-field.

The texts are what this OpenSSL build says, and a real server may answer differently or not at all. All certificates and keys are test material.

Recap

  • A certificate has a start and an end date and the client compares both with its own clock.
  • With an expired leaf this build sends alert 45, certificate_expired (RFC 9846 section 6.2).
  • verify_result() names the date problem in words; the alert is the implementation's choice.
  • The results depend on your clock: they hold between 2026 and 2036.