~~NOTOC~~ ====== Scenarij 10.1: Postavljanje TLS servera ====== **Kategorija:** [[.:start|TLS/mTLS]] \\ **Složenost:** ⭐⭐⭐ (Srednja) \\ **Preduvjeti:** Server certifikat, privatni ključ \\ **Procijenjeno vrijeme:** 20-30 minuta ---- ===== Opis ===== Ovaj scenarij opisuje **postavljanje TLS servera** s Post-Quantum sigurnim certifikatima. TLS 1.3 je obavezan za modernu sigurnost. **Komponente:** * Server certifikat (ML-DSA ili Hybrid) * Lanac certifikata (Intermediate + Root) * TLS konfiguracija * Cipher Suites ---- ===== Tijek rada ===== flowchart LR CERT[Priprema certifikata] --> CHAIN[Kreiranje lanca] CHAIN --> CONFIG[Konfiguracija TLS-a] CONFIG --> TEST[Testiranje] TEST --> DEPLOY[Deployment] style CONFIG fill:#e8f5e9 ---- ===== Primjer koda: ASP.NET Core Kestrel ===== using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(options => { options.ListenAnyIP(443, listenOptions => { listenOptions.UseHttps(httpsOptions => { // Učitavanje server certifikata httpsOptions.ServerCertificate = LoadCertificateChain( "server.crt.pem", "server.key.pem", "intermediate-ca.crt.pem" ); // Forsiranje TLS 1.3 httpsOptions.SslProtocols = SslProtocols.Tls13; // Aktiviranje OCSP Stapling httpsOptions.OnAuthenticate = (context, sslOptions) => { sslOptions.CertificateRevocationCheckMode = X509RevocationMode.Online; }; }); // Aktiviranje HTTP/2 listenOptions.Protocols = HttpProtocols.Http1AndHttp2; }); }); var app = builder.Build(); // Aktiviranje HSTS app.UseHsts(); app.MapGet("/", () => "TLS Server aktivan"); app.Run(); static X509Certificate2 LoadCertificateChain( string certPath, string keyPath, string chainPath) { using var ctx = PqCryptoContext.Initialize(); // Server certifikat s privatnim ključem var cert = ctx.LoadCertificateWithPrivateKey(certPath, keyPath, null); // Dodavanje lanca (za potpuni lanac) var intermediate = ctx.LoadCertificate(chainPath); // Kreiranje PFX-a s lancem var pfxBytes = ctx.ExportToPfx(cert, cert.GetRSAPrivateKey(), new[] { intermediate }, null); return new X509Certificate2(pfxBytes); } ---- ===== Nginx konfiguracija ===== server { listen 443 ssl http2; server_name www.example.com; # Server certifikat (s lancem) ssl_certificate /etc/nginx/ssl/server-chain.pem; ssl_certificate_key /etc/nginx/ssl/server.key.pem; # Samo TLS 1.3 ssl_protocols TLSv1.3; # Cipher Suites (TLS 1.3 default) # ssl_ciphers TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256; ssl_prefer_server_ciphers off; # OCSP Stapling ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/nginx/ssl/ca-chain.pem; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; # Sigurnosni headeri add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "DENY" always; # Konfiguracija sesije ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; location / { proxy_pass http://backend:8080; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ---- ===== Apache konfiguracija ===== ServerName www.example.com # Aktiviranje SSL-a SSLEngine on # Certifikati SSLCertificateFile /etc/apache2/ssl/server.crt.pem SSLCertificateKeyFile /etc/apache2/ssl/server.key.pem SSLCertificateChainFile /etc/apache2/ssl/intermediate-ca.crt.pem # Samo TLS 1.3 SSLProtocol -all +TLSv1.3 # OCSP Stapling SSLUseStapling On SSLStaplingCache "shmcb:logs/ssl_stapling(32768)" SSLStaplingResponderTimeout 5 SSLStaplingReturnResponderErrors off # HSTS Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" # Deaktiviranje kompresije (BREACH) SSLCompression off Options -Indexes +FollowSymLinks AllowOverride All Require all granted ---- ===== Kreiranje lanca certifikata ===== # Server certifikat + Intermediate = lanac cat server.crt.pem intermediate-ca.crt.pem > server-chain.pem # Provjera redoslijeda openssl crl2pkcs7 -nocrl -certfile server-chain.pem | openssl pkcs7 -print_certs -noout # Validacija lanca openssl verify -CAfile root-ca.crt.pem -untrusted intermediate-ca.crt.pem server.crt.pem ---- ===== Testiranje TLS konfiguracije ===== # SSL Labs API (ako je javno) # https://www.ssllabs.com/ssltest/ # Lokalni test s OpenSSL-om openssl s_client -connect localhost:443 -tls1_3 -brief # Provjera Cipher Suites openssl s_client -connect localhost:443 -cipher 'TLS_AES_256_GCM_SHA384' /dev/null | openssl x509 -text -noout # Provjera OCSP Stapling openssl s_client -connect localhost:443 -status /dev/null | grep -A 5 "OCSP Response" # testssl.sh (sveobuhvatno) ./testssl.sh localhost:443 ---- ===== C# test klijent ===== public async Task TestTlsConnection(string url) { var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { Console.WriteLine($"Server: {cert.Subject}"); Console.WriteLine($"Issuer: {cert.Issuer}"); Console.WriteLine($"Algoritam: {cert.SignatureAlgorithm.FriendlyName}"); Console.WriteLine($"Vrijedi do: {cert.NotAfter}"); if (chain != null) { Console.WriteLine($"Duljina lanca: {chain.ChainElements.Count}"); foreach (var element in chain.ChainElements) { Console.WriteLine($" - {element.Certificate.Subject}"); } } if (errors != SslPolicyErrors.None) { Console.WriteLine($"SSL greške: {errors}"); return false; } return true; } }; using var client = new HttpClient(handler); var response = await client.GetAsync(url); Console.WriteLine($"Status: {response.StatusCode}"); Console.WriteLine($"Protokol: {response.Version}"); } ---- ===== Sektorski specifični TLS zahtjevi ===== ^ Sektor ^ Min. TLS ^ Cipher Suites ^ Posebnost ^ | **PCI-DSS** | TLS 1.2+ | Jake šifre | Godišnja provjera | | **HIPAA** | TLS 1.2+ | AES-256 | Audit logging | | **BSI TR-02102** | TLS 1.2+ | BSI-sukladne suite | PFS obavezan | | **Energetika/SCADA** | TLS 1.2+ | ICS-specifično | Dugoročna podrška | ---- ===== Povezani scenariji ===== ^ Odnos ^ Scenarij ^ Opis ^ | **Preduvjet** | [[hr:int:pqcrypt:szenarien:zertifikate:server_cert|3.1 Server certifikat]] | Kreiranje certifikata | | **Sljedeći korak** | [[.:client_config|10.2 TLS klijent]] | Konfiguracija klijenta | | **Proširenje** | [[.:mtls_deployment|10.3 mTLS Deployment]] | Obostrana autentifikacija | ---- << [[.:start|← Pregled TLS-a]] | [[hr:int:pqcrypt:szenarien:start|↑ Scenariji]] | [[.:client_config|10.2 TLS klijent →]] >> {{tag>scenarij tls server nginx kestrel https}} ---- //Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional//