PV090: HTTP&PKI

Aleš Minařík, <xminari2@fi.muni.cz>

HTTP

Minimální požadavek a odpověď

GET / HTTP/1.1
Host: example.org
User-Agent: curl/8.0
Accept: */*
HTTP/1.1 200 OK
Date: Sat, 18 Oct 2025 10:15:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 1234
Server: nginx/1.24.0
          
<html>...</html>

Metody

Verze

Hlavičky požadavku

Stavové kódy

Nejčastější kódy:

Kód Název
100 Continue
101 Switching Protocols
200 OK
206 Partial Content
307 Temporary Redirect
308 Permanent Redirect
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error
502 Bad Gateway

Hlavičky odpovědi

Autentizace

Server -> klient

Proxy

Servery

CGI

Nginx — ukázky

Základní strukturou configu jsou bloky a formát připomínající json.

$ nginx -s reload
 $ nginx -s quit

Statické soubory:

http {
     server {
          listen 80;
          server_name example.org;

          root /data/www;
          location / {
               try_files $uri $uri/ =404;
          }

          location /non-to-www {
               return 301 $scheme://$host$request_uri;
          }
     }
}

CGI (FastCGI):

location /cgi-bin/ {
     fastcgi_split_path_info ^(/cgi-bin)(/.*)$;
     include fastcgi_params;
     fastcgi_param SCRIPT_FILENAME /var/www/cgi-bin$fastcgi_script_name;
     fastcgi_pass 127.0.0.1:9000;
}

Virtuální servery:

server {
     listen 80;
     server_name example1.com www.example1.com;
     root /var/www/example1;
}

server {
     listen 80;
     server_name example2.com www.example2.com;
     root /var/www/example2;
}

Basic auth:

$ htpasswd -c /etc/nginx/.htpasswd user
location /admin/ {
     auth_basic "admin area";
     auth_basic_user_file /etc/nginx/.htpasswd;
}

SSL (HTTPS):

server {
     listen 443 ssl;
     server_name www.example.com;

     ssl_certificate     /etc/ssl/certs/www.example.com.crt;
     ssl_certificate_key /etc/ssl/private/www.example.com.key;
     ssl_trusted_certificate /etc/ssl/certs/chain.crt;
}

PKI

HTTP nad TLS je založeno na asymetrickém šifrování. Veřejný klíč je součástí x509 certifikátu. Při navštěvě webové stránky:

  1. Server pošle svůj certifikát prohlížeči
  2. Prohlížeč ověří, že je certifikát
    • podepsaný důveryhodnou autoritou
    • vydaný pro navštěvovanou doménu
    • platný
  3. Pokud ano, prohlížeč důvěřuje veřejnému klíči serveru.

Zobrazení certifikátu dané stránky:

$ openssl s_client -showcerts -connect www.fi.muni.cz:443

Cíle PKI

Certificate Authority

CA vydávají a spravují certifikáty. Server typicky dostane certifikát podepsaný intermediate CA a musí poslat celý řetěz (mimo root).

DANE

DANE (TLSA záznamy v DNSSEC) umožňuje vázat veřejný klíč/certifikát na doménu přes DNSSEC.

Formát certifikátu

Důvěryhodné certifikáty

$ openssl version -d
 $ man update-ca-certificates

Zobrazení certifikátu

$ openssl x509 -in cert.pem -text -noout

Automatizace – Let’s Encrypt, ACME protokol

  1. Uživatel použije ACME klient, který pošle požadavek na Lets Encrypt
  2. Let’s Encrypt bude chtít důkaz, že uživatel vlastní danou doménu (eg specifický DNS záznam)
  3. Let’s Encrypt toto ověří z různých sítí
  4. Let’s Encrypt umožní danému klientu spravovat certifikát pro danou doménu

Self-signed certifikáty

Nástroje OpenSSL

  1. Vytváření klíčů
$ openssl genrsa -out private.key 409
  1. Vytvoření self-signed certifikátu
$ openssl req -x509 -new -key ca.key -sha256 -days 3650 -out ~/pv090/ca/certs/ca.crt
  1. Certificate signing request
$ openssl req -new -key other.key -out request.csr
  1. Podepsání CSR (předpokládá openssl.cnf)
$ openssl ca -in ~/pv090/server.csr -out ~/pv090/server.crt
  1. Revokace a CRL
$ openssl ca -revoke server.crt
 $ openssl ca -gencrl -out revoked.crl

Zdroje