Proyecto

General

Perfil

Actividad #23 » Guía para Configurar HTTPS con TLS 1.3 en el Servidor Web.md

Reynaldo León, 02/08/2025 17:35

 

🚀Guía para Configurar HTTPS con TLS 1.3 en el Servidor Web

🔐 Paso 1: Activar TLS 1.3 en el registro

  1. Abre PowerShell como Administrador y ejecuta:
# Crear rama del registro y valores
New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Force
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Name 'Enabled' -Value '1' -PropertyType 'DWord'
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Name 'DisabledByDefault' -Value '0' -PropertyType 'DWord'

🌐 Paso 2: Instalar Nginx con Chocolatey

# Instalar
choco install nginx -y

# Verificar
nginx -v

# Arrancar
nginx

🔏 Paso 3: Instalar OpenSSL

# Instalar
choco install openssl -y

# Verificar
openssl version

🔍 Paso 4: Instalar Nmap (para escanear TLS)

# Instalar
choco install nmap -y

# Verificar
nmap --version

📝 Paso 5: Mapear IP y dominio en hosts

  1. Abrir Bloc de notas como Administrador

  2. Archivo → Abrir → C:\Windows\System32\drivers\etc\hosts

  3. Añadir al final:

Ejemplo: 127.0.0.1 rey.webserver


🔐 Paso 6: Generar certificado autofirmado con OpenSSL

# Crear carpeta SSL
mkdir C:\nginx\ssl
cd C:\nginx\ssl

# Generar certificado
openssl req -x509 -nodes -days 365 -newkey rsa:2048 `
  -keyout rey.webserver.key `
  -out    rey.webserver.crt

🗒️ Parámetros rápidos
-x509 → cert autofirmado
-nodes → sin passphrase
-days 365 → validez 1 año
-newkey rsa:2048 → clave de 2048 bits


⚙️ Paso 7: Configurar nginx.conf

  1. Ruta típica: C:\nginx\conf\nginx.conf

  2. Añade o reemplaza dentro de http { … }:

# 🔁 Redirigir HTTP → HTTPS
server {
    listen       8080;
    server_name  rey.webserver;
    return 301 https://$host:8443$request_uri;
}

# 🔒 Servidor HTTPS (solo TLS 1.3)
server {
    listen       8443 ssl;
    server_name  rey.webserver;
    
    ssl_certificate      C:/nginx/ssl/rey.webserver.crt;
    ssl_certificate_key  C:/nginx/ssl/rey.webserver.key;
    
    ssl_protocols TLSv1.3;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_prefer_server_ciphers on;

# ⚙️ Redirigir las peticiones desde https://rey.webserver:8443
#    hacia la aplicación .NET ejecutandose en https://localhost:44362
    location / {
        proxy_pass https://localhost:44362;
        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;
    }
}

✅ Paso 8: Comprobaciones finales

# Validar sintaxis
nginx -t

# Recargar configuración
nginx -s reload

# Verificar TLS 1.3 con OpenSSL
openssl s_client -connect rey.webserver:8443 -tls1_3

# Verificar con Nmap
nmap --script ssl-enum-ciphers -p 8443 rey.webserver

⚙️Paso 9: Configuración en el código de la aplicación .NET

✅ 9.1 Verificar CORS y URLs en appsettings.json

Asegurarse de que las URLs coincidan con las que usa el cliente:

"App": {
  "AllowedHosts": "*",
  "ServerRootAddress": "https://rey.webserver:8443",
  "ClientRootAddress": "https://rey.webserver:8443",
  "CorsOrigins": "https://rey.webserver:8443"
}

✅ 9.2 Verificar que Kestrel escuche en HTTPS local

En appsettings.json:

"Kestrel": {
  "Endpoints": {
    "Https": {
      "Url": "https://127.0.0.1:44362",
      "Protocols": "Http1AndHttp2",
      "Certificate": {
        "Path": "C:/nginx/ssl/rey.webserver.crt",
        "KeyPath": "C:/nginx/ssl/rey.webserver.key"
      }
    }
  }
}

✅ 9.3 Configuración de Kestrel para TLS 1.3

Añadir la configuración de Kestrel para TLS 1.3 en Program.cs

builder.WebHost
    .UseUrls("https://*:44362")
    .ConfigureKestrel(serverOptions =>
    {
        serverOptions.ConfigureHttpsDefaults(httpsOptions =>
        {
            httpsOptions.SslProtocols = SslProtocols.Tls13;
        });
    });

✅ 9.4 Configuración de uso de Kestrel directamente (sin IIS Express)

Eliminar en launchSettings.json el perfil de IIS y configurar el perfil CRM.MVC.Capacitacion.Web:

"profiles": {
  "CRM.MVC.Capacitacion.Web": {
    "commandName": "Project",
    "launchBrowser": true,
    "launchUrl": "http://localhost:44362",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development",
      "ASPNETCORE_URLS": "http://localhost:44362"
    },
    "applicationUrl": "http://localhost:44362"
  }
}

🎉 ¡Listo!
Ahora el servidor responde en https://rey.webserver:8443 usando TLS 1.3 exclusivamente.

    (1-1/1)