Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

HTTPS and certificates in practice

HTTPS protects HTTP with encryption and a way to check the server's identity. From the terminal, you can watch that protection begin, read the certificate it relies on, and follow the signatures back to an authority your computer trusts.

What TLS adds

When you typed a request into nc in Connections, ports and speaking HTTP by hand, the request and the response crossed the network as plain text. Every machine on the way, from the Wi-Fi router in a cafe to the networks between it and the server, could read the headers, the body and any password inside them. It could also change them, or answer in the server's place, and you would have no way to tell.

TLS, short for Transport Layer Security, closes those gaps. It sits between the TCP connection and HTTP, and gives the conversation three properties:

  • Encryption. Only the two ends can read what they send each other.
  • Integrity. Anything changed on the way is detected, and the connection fails instead of delivering altered data.
  • Server identity. The server proves, with a certificate, that it really is the name you asked for.

The client usually stays anonymous at this level and proves who it is later, inside HTTP, with a password, a cookie or a token. TLS can also ask the client for a certificate of its own, called mutual TLS, which some identity systems use to authenticate applications.

HTTPS is HTTP sent through TLS. The method, address, headers and body mean exactly what they meant over plain HTTP; curl shows them as readable lines even when HTTP/2 packs them into binary frames on the wire. What changes is the port, 443 instead of 80, and the scheme, https:// instead of http://.

TLS does not hide everything. Someone on the path still sees which address you connect to, roughly how much data flows and when, and usually the server name you asked for, because it travels at the start of the handshake. The URL path, the query, the headers, cookies and the body stay private.

The handshake

Before any HTTP is sent, the client and server run a short exchange called the handshake. In TLS 1.3, the current version, it goes like this:

  1. The client sends a Client Hello: the TLS versions and encryption methods (cipher suites) it supports, its half of a key exchange, and the server name it wants, called SNI (Server Name Indication). One address often serves many sites, and SNI tells the server which certificate to present.
  2. The server answers with a Server Hello that picks a version and cipher suite and carries its own half of the key exchange. From these two halves, both sides compute the same secret keys without ever sending them. Everything after this point is encrypted.
  3. The server sends its certificate, then a Certificate Verify message. These rely on a key pair: a private key the server keeps secret and a matching public key, inside the certificate, that anyone may see. A signature made with the private key can be checked with the public key, but cannot be made with it. Certificate Verify is such a signature, over the handshake so far. Anyone can copy a certificate, because it is public. Only the real server holds the private key, so this signature proves the server owns the certificate it sent.
  4. Each side sends Finished, a check value over the whole handshake. If anyone tampered with an earlier message, the values do not match and the connection stops.

The client checks the certificate while this happens, as the next sections explain. When everything passes, the HTTP request goes out, encrypted. All of this takes one round trip between client and server.

TLS 1.2 is still widely supported and safe when configured well. Its handshake needs two round trips, and the certificate travels before encryption starts, so an observer can read it. Older versions, TLS 1.0 and 1.1, are retired, and current clients refuse them.

curl -v prints the handshake as it happens. The -o /dev/null option sends the response body to /dev/null, a special file that throws away whatever is written to it, so only the connection details remain:

curl -sS -v -o /dev/null https://www.example.com/

Ubuntu 24.04 (Windows with WSL, or Linux)

Example output, shortened:

* Connected to www.example.com (192.0.2.10) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519 / id-ecPublicKey
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=www.example.com
*  start date: Aug 12 00:00:00 2026 GMT
*  expire date: Feb 27 23:59:59 2027 GMT
*  subjectAltName: host "www.example.com" matched cert's "www.example.com"
*  issuer: C=US; O=Example Trust; CN=Example Issuing CA 1
*  SSL certificate verify ok.

macOS 14 or later with Homebrew

The course uses Homebrew's curl, and curl --version shows which TLS library yours was built with. The shortened example below came from a macOS curl built with a different library, so its handshake lines and cipher names will not match yours exactly. The steps and certificate checks are the same.

* Connected to www.example.com (192.0.2.10) port 443
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=www.example.com
*  start date: Aug 12 00:00:00 2026 GMT
*  expire date: Feb 27 23:59:59 2027 GMT
*  subjectAltName: host "www.example.com" matched cert's "www.example.com"
*  issuer: C=US; O=Example Trust; CN=Example Issuing CA 1
*  SSL certificate verify ok.

Lines with (OUT) are messages your computer sent, and (IN) lines are messages it received. You can match them to the steps above: the two hellos, the certificate, the Certificate Verify signature and the two Finished messages. The last block summarizes the certificate. (SSL is the old name for TLS, and many tools still use it.)

Two other kinds of line describe choices the two sides made. The ALPN lines are Application-Layer Protocol Negotiation: inside its Client Hello, curl offers the HTTP versions it can speak, h2 (HTTP/2) and http/1.1, and the server accepts one. The SSL connection using line names the TLS version and the cipher suite they agreed on. In TLS_AES_256_GCM_SHA384, AES with 256-bit keys encrypts the data and SHA-384 is the hash the handshake uses; X25519 names the key exchange and id-ecPublicKey the type of key in the certificate. You never pick these by hand: current clients and servers only offer combinations that are safe.

The subjectAltName line shows the name check passing. Reading a certificate below explains what it checks.

The server picks the newest version that both sides support. To see an older one, cap what the client offers. --tls-max 1.2 tells curl not to offer anything newer than TLS 1.2:

curl -sS -v --tls-max 1.2 -o /dev/null https://www.example.com/

The handshake lines now start with TLSv1.2 and include messages that TLS 1.3 folded away, such as a separate Server key exchange and Client key exchange.

Reading a certificate

A certificate is a small signed document that binds a public key to a name. A certificate authority (CA), an organization that clients trust to check who controls a name, signs it to vouch for that binding. The fields that matter most in practice are:

FieldWhat it says
SubjectWho the certificate is about. For websites it often holds just a common name (CN), such as CN=www.example.com.
Subject Alternative Name (SAN)The names the certificate is valid for, such as DNS:www.example.com, DNS:example.com.
IssuerThe CA that signed it.
ValidityTwo dates, notBefore and notAfter. Outside that window the certificate is not valid.
Public keyThe key that matches the server's private key, used to check the Certificate Verify signature.

The SAN decides whether a certificate fits a site. The client takes the host name from the URL, the same name it sent as SNI, and looks for it in the SAN list. Older certificates put the host name in the subject's CN, but browsers and most current tools ignore the CN for this check, so every name the site uses must be in the SAN. Each entry starts with its type: DNS: for a host name, or IP Address: for an address.

A SAN entry can be a wildcard such as *.example.com. The star stands for exactly one label, one dot-separated part of the name, so it covers www.example.com and api.example.com, but not example.com itself or a.b.example.com. That is why certificates with a wildcard usually list example.com as a separate entry.

Validity dates are in GMT, the same as UTC. Public website certificates issued now last at most 200 days, and the maximum keeps shrinking, so servers renew them automatically. An expired certificate usually means that renewal broke.

openssl s_client is a TLS client for testing. It connects, runs the handshake and prints what it learned:

openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null

-connect takes the host and port. -servername sets SNI. Recent versions of openssl send SNI on their own when you connect by name, but writing it out keeps the command reliable, and it is required when you connect to an IP address. After the handshake, s_client waits for you to type a request. The </dev/null redirection gives it an empty input instead, so it closes the connection as soon as the handshake is done.

The output is long. To read just the server's certificate, pipe it into openssl x509, which reads and prints certificates. The certificate arrives in PEM format: base64 text between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines, which x509 finds in the stream. 2>/dev/null hides the progress lines s_client writes to standard error.

openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null 2>/dev/null | openssl x509 -out server.pem
openssl x509 -in server.pem -noout -subject -issuer -dates -ext subjectAltName

The first command saves the certificate to server.pem. In the second, -in reads that file, -noout stops x509 from printing the certificate itself, and the other options choose the fields: the subject, the issuer, both validity dates and the SAN extension. Example output (spacing differs a little between openssl versions):

subject=CN = www.example.com
issuer=C = US, O = Example Trust, CN = Example Issuing CA 1
notBefore=Aug 12 00:00:00 2026 GMT
notAfter=Feb 27 23:59:59 2027 GMT
X509v3 Subject Alternative Name:
    DNS:www.example.com, DNS:example.com

openssl x509 -in server.pem -noout -text prints every field, which is useful once you know what to look for. -checkend answers a common operational question, whether the certificate expires within a number of seconds. Thirty days is $((30*24*60*60)) seconds:

$ openssl x509 -in server.pem -noout -checkend $((30*24*60*60))
Certificate will not expire

It also sets the exit code, 0 when the certificate is good for that long and 1 when it is not, so a script can test it with if or &&. To know how many days are actually left, a script needs the date itself in a form it can do arithmetic on. -dateopt iso_8601 prints the dates in ISO 8601, such as notAfter=2027-02-27 23:59:59Z, which date turns into Unix time as Time and timestamps showed. What a certificate says covers every field and extension in depth.

The chain of trust

Your computer cannot know every server's certificate in advance. It knows a short list of root CAs instead, kept in a trust store that comes with the operating system or with a program. Root CAs rarely sign server certificates directly. They sign intermediate CA certificates, and the intermediates sign server certificates. That makes a chain: the server certificate was signed by an intermediate, which was signed by a root that your computer already trusts.

The server sends its own certificate and the intermediates. It does not need to send the root: a root only counts if the client already has it, so the client always uses its own copy. The client then checks each link. Each signature must verify with the public key in the certificate above it, up to the root. Every certificate must be within its validity dates. And the server certificate's SAN must match the requested name.

One failed check is enough to stop the connection, and each failure looks different. A server that sends its own certificate only, without the intermediate, leaves the client with no way to reach a root. A certificate past its notAfter date has expired, however good its chain. And a request for wrong.example.com fails the name check against the certificate for www.example.com, even though every signature verifies.

Every check passes

Requested name
www.example.com
Server sent
Own certificate and intermediate
Trust store
Example Root CA
  • Each signature verifies, up to the root
  • Within its validity dates
  • SAN matches the requested name

Verify return code: 0 (ok)

Its own certificate only

Requested name
www.example.com
Server sent
Own certificate only
Trust store
Example Root CA
  • Each signature verifies, up to the root
  • Within its validity dates
  • SAN matches the requested name

unable to get local issuer certificate

Past its notAfter date

Requested name
www.example.com
Server sent
Own certificate and intermediate
Trust store
Example Root CA
  • Each signature verifies, up to the root
  • Within its validity dates
  • SAN matches the requested name

certificate has expired

A request for wrong.example.com

Requested name
wrong.example.com
Server sent
Own certificate and intermediate
Trust store
Example Root CA
  • Each signature verifies, up to the root
  • Within its validity dates
  • SAN matches the requested name

no alternative certificate subject name matches

The server does not need to send the root: a root only counts if the client already has it.

The same three checks for a complete chain, a missing intermediate, an expired certificate and the wrong name. Every check must pass.

Some servers send one more certificate at the end: a cross-signed certificate, which is a newer root's certificate signed by an older root. Clients whose trust store already has the newer root stop there and do not need it. Older clients that only know the older root can still build a chain through it.

s_client shows both halves of this. The depth lines are its verification walk, from the root at the top down to the server certificate at depth 0. The Certificate chain block lists what the server actually sent, each with its subject (s:) and issuer (i:). Add -showcerts to print every sent certificate in PEM format as well, not just the first. Example output, shortened:

$ openssl s_client -connect www.example.com:443 -servername www.example.com -showcerts </dev/null
CONNECTED(00000003)
depth=2 C = US, O = Example Trust, CN = Example Root CA
verify return:1
depth=1 C = US, O = Example Trust, CN = Example Issuing CA 1
verify return:1
depth=0 CN = www.example.com
verify return:1
---
Certificate chain
 0 s:CN = www.example.com
   i:C = US, O = Example Trust, CN = Example Issuing CA 1
   a:PKEY: id-ecPublicKey, 256 (bit); sigalg: ecdsa-with-SHA384
   v:NotBefore: Aug 12 00:00:00 2026 GMT; NotAfter: Feb 27 23:59:59 2027 GMT
-----BEGIN CERTIFICATE-----
MIIDtjCCAzygAwIBAgIQ...
-----END CERTIFICATE-----
 1 s:C = US, O = Example Trust, CN = Example Issuing CA 1
   i:C = US, O = Example Trust, CN = Example Root CA
   a:PKEY: id-ecPublicKey, 384 (bit); sigalg: ecdsa-with-SHA384
   v:NotBefore: Mar 13 00:00:00 2024 GMT; NotAfter: Mar 12 23:59:59 2027 GMT
-----BEGIN CERTIFICATE-----
MIIEVzCCAj+gAwIBAgIR...
-----END CERTIFICATE-----
---
...
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
...
    Verify return code: 0 (ok)

Follow the names: the issuer of certificate 0 is the subject of certificate 1, and the issuer of certificate 1 is the root at depth 2, which appears only in the verification walk because it came from the trust store. Verify return code: 0 (ok) means the whole chain checked out.

Ubuntu 24.04 (Windows with WSL, or Linux)

On Ubuntu, curl and openssl share the system trust store in /etc/ssl/certs, which the ca-certificates package keeps up to date.

macOS 14 or later with Homebrew

On macOS, the terminal and the browser can trust different lists. Safari and Apple's own tools read the macOS Keychain, while Homebrew's curl and openssl@3 read a file of root certificates that Homebrew keeps in $(brew --prefix)/etc/ca-certificates/. The two lists are mostly the same, but a root that a company network adds to the Keychain can make a site work in Safari and fail in the terminal. The CAfile: line in curl -v output names the file your curl used.

Certificate authorities and chains explains how CAs earn that trust and how they are kept in check.

When verification fails

When a check fails, curl stops before sending any HTTP and exits with code 60. The message names the check that failed:

The error mentionsWhat usually happened
certificate has expiredToday is after notAfter and renewal failed. Also check your own clock: a computer with the wrong date rejects good certificates.
no alternative certificate subject name matchesThe name you used is not in the SAN list. You may have the wrong name, or the server presented a certificate for a different site.
unable to get local issuer certificateThe chain does not reach a root in your trust store. Often the server forgot to send its intermediate, or the certificate comes from a private CA your computer does not know.
self-signed certificateThe certificate signed itself and is not in your trust store, which is common on test servers and devices. Some tools write it as self signed certificate.

openssl s_client is the tool for finding out why. It completes the handshake even when verification fails, then prints the reason in its Verify return code line, and its chain block shows exactly what the server sent. A chain with only certificate 0, for example, points to a missing intermediate.

curl has an option, -k (long form --insecure), that skips all of these checks. The connection is still encrypted, but you no longer know who is on the other end: a machine in the middle could present its own certificate, read everything you send and pass it on. Use -k only for a moment while diagnosing a server you are responsible for, never in scripts, and never on a request that carries a password, token or key. When a server uses a private CA you trust, give curl that CA's certificate with --cacert ca.pem instead, so verification stays on.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

curl refuses to connect to shop.example.com with "no alternative certificate subject name matches". The certificate's SAN list is DNS:example.com, DNS:www.example.com. What is wrong? 1 of 4

Choose one answer.

openssl s_client shows that a server sent two certificates: its own and an intermediate. The root CA is not among them, and the verify return code is 0 (ok). Is something missing? 2 of 4

Choose one answer.

Ava opens https://shop.example/orders?id=42 on cafe Wi-Fi, and her browser sends its session cookie with the request. Someone recording the cafe network captures the whole connection. What can they learn from it? 3 of 4

Choose one answer.

A script calls https://reports.internal.example, whose certificate comes from the company's private CA. curl fails with "unable to get local issuer certificate", and a colleague suggests adding -k. What should the script do instead? 4 of 4

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity