QA Interview Hub · Knowledge base · Quizzes · Українська

Networking › TCP/IP and the path of a request

TCP handshake, TLS 1.3 and certificates

TCP opens a connection in three steps (SYN, SYN-ACK, ACK), and TLS 1.3 encrypts traffic and authenticates the server with a certificate in one RTT. The client checks the chain to a trusted root, the validity period and that the name matches the SAN. Refused means an RST from a closed port, a timeout means dropped packets, a reset means a cut connection. TLS checks are not disabled globally in tests.

Networking · TCP/IP

A stand test failed with a certificate error although everything worked yesterday. What changed?

The nightly run on the stand is red: certificate has expired. The code was not touched and the browser opens the page without errors because a developer already added an exception. Such a failure has two causes: the certificate really expired, or the client does not trust it. To tell them apart you must understand what happens between pressing Enter and the first data byte: the TCP handshake, then TLS. The lesson takes both steps apart and shows how to read their errors.

How it works and why. TCP builds a reliable stream on top of unreliable packets. Before data, the sides synchronise: the client sends SYN, the server SYN-ACK, the client ACK. That is one round trip (RTT). The connection is closed with FIN segments from both sides, and RST tears it down at once. These three signals stand behind the most common client errors:

SymptomWhat happened in TCP
Connection refusedthe port is closed, the OS answered RST at once
Timeoutno answer: a firewall drops packets, the host is off, no route
Connection resetthe connection existed and the other side tore it down (RST): a process crash, an idle timeout on a balancer

TLS gives three things: encryption, integrity and server authentication (and the client's too if needed, mTLS). In TLS 1.3 the full handshake takes one RTT: in ClientHello the client immediately sends the supported ciphers, its key share and the SNI (the host name, so one IP can serve many domains). The server answers with its share, the certificate and a confirmation, and everything after is encrypted. The application protocol is negotiated here too (ALPN): h2 or http/1.1. About 0-RTT on session resumption: early data can be replayed by an attacker, so it is allowed only for safe requests. TLS 1.0 and 1.1 are obsolete and disabled in modern browsers.

Before the first HTTP request

TCP: SYN, SYN-ACK, ACK1 RTT before the first data byteTLS 1.3: ClientHello, ServerHello, Finished1 RTT: keys, certificate, ALPNHTTP request and response, already encryptedone more RTT plus server time
Figure 1. A new HTTPS request costs two round trips before HTTP itself: TCP and TLS. That is why open connections are reused.

What the client checks in a certificate. A certificate binds a public key to a name. The client checks the signature chain up to a trusted root, the validity period, that the requested name matches the SAN entries (modern browsers no longer check the CN field) and, in some clients, the revocation status. So errors differ by cause:

  • ERR_CERT_DATE_INVALID: the certificate has expired (or the machine clock is off);
  • ERR_CERT_COMMON_NAME_INVALID: the requested name does not match the certificate, for example a request by IP or by another domain;
  • ERR_CERT_AUTHORITY_INVALID, UNABLE_TO_VERIFY_LEAF_SIGNATURE: a self-signed certificate or a missing intermediate in the chain;
  • in a corporate network, TLS inspection replaces certificates with its own root, and tools without that root complain about trust.

Example: from a red run to the cause. Start with what the server really serves, without relying on the browser:

curl -sS https://staging.example.com/health
# curl: (60) SSL certificate problem: certificate has expired

openssl s_client -connect staging.example.com:443 \
  -servername staging.example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
# notAfter=Nov  3 09:12:00 2026 GMT        # illustration: the date is already in the past
# X509v3 Subject Alternative Name: DNS:staging.example.com

The notAfter date is in the past: the certificate expired, and this is the stand's problem, not the tests' code. If the date is fine, look at subjectAltName (is the needed name there), then at the chain (-showcerts): a frequent cause of "not trusted" is a server that serves the leaf certificate without the intermediate. The stand's owner fixes it by renewing the certificate and the chain. Turning checks off in tests as a "fix" is not allowed, because then the test would miss a real problem in production.

Limits and alternatives. For stands with a self-signed certificate Playwright has the ignoreHTTPSErrors option:

// playwright.config.ts
export default defineConfig({
  projects: [
    {
      name: 'staging',
      use: {
        baseURL: 'https://staging.example.com',
        // only for a stand with a self-signed certificate
        ignoreHTTPSErrors: true,
      },
    },
  ],
});

It is enabled narrowly for known harmless environments, not "just in case". Revocation checking is uneven: CRL lists have limits, OCSP is being phased out (Let's Encrypt stopped supporting it in 2025), so each client behaves in its own way. Certificate lifetimes keep shrinking: for public CAs the limit is lowered in stages, so automated renewal (ACME) becomes the norm, and expiry stays a typical cause of stand and internal service failures. Mobile apps with certificate pinning reject even a valid certificate if it is not the one embedded in the app.

Common mistakes.

  • Turning TLS verification off globally in tests: the test will not see an expired or wrong certificate in production.
  • Reading ECONNRESET as a "certificate error": a certificate concerns only the TLS step, while a reset is a TCP abort.
  • Connecting by IP instead of by name and wondering about COMMON_NAME_INVALID: SNI and name checks are tied to the name.
  • Not checking the clock of the machine or container: a wrong time yields an "expired" or "not yet valid" certificate.
  • Renewing only the leaf certificate and forgetting the intermediate: a browser will guess, but curl and Node will not.

Check yourself

curl returns connection refused, while another service on the same network gives a timeout. What do the two TCP failures have in common and how do they differ?

Answer

Both mean the connection was not established. Refused: the host is reachable, the port is closed, the OS answered RST at once. Timeout: there is no answer, packets are dropped (a firewall, no route, a powered-off host). Refused is diagnosed on the service host, timeout in the network and its rules.

Why is the TLS 1.3 handshake faster than TLS 1.2 and what is the limit of 0-RTT?

Answer

In TLS 1.3 the client sends its key share at once, so the handshake takes one RTT instead of two. 0-RTT on session resumption allows data to go with the first packet, but it can be replayed by an attacker, so the server accepts it only for requests that are safe to repeat.

In an interview. Junior: TCP opens a connection in three steps: SYN, SYN-ACK, ACK. TLS encrypts traffic and proves with a certificate that the server is who it claims to be. An expired certificate gives a trust error. Middle/Senior: I tell refused, timeout and reset apart by TCP behaviour. In TLS 1.3 the handshake takes one RTT, the name goes in SNI, and the client checks the chain, validity, SAN and name. I read a certificate with openssl s_client and enable ignoreHTTPSErrors only for a known stand.

More articles in this chapter