Skip to content

Instantly share code, notes, and snippets.

@ramingar
Created August 28, 2025 21:32
Show Gist options
  • Select an option

  • Save ramingar/c524a3e3c419d285f6e8613663cf4efe to your computer and use it in GitHub Desktop.

Select an option

Save ramingar/c524a3e3c419d285f6e8613663cf4efe to your computer and use it in GitHub Desktop.
Crear certificado SSL con SAN (Subject Alternative Name)
  1. Creamos el archivo de configuración del SAN

Por ejemplo san.cnfs

[ req ]
default_bits       = 2048
prompt             = no
default_md         = sha256
req_extensions     = req_ext
distinguished_name = dn

[ dn ]
C  = ES
ST = Valencia
L  = Valencia
O  = MiEmpresa
OU = IT
CN = 192.168.1.50

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
IP.1 = 192.168.1.50
IP.2 = 127.0.0.1
DNS.1 = localhost
DNS.2 = mi.dominio-molon.com

  1. Script para generar CA y certificado con SAN:
# Crear CA (válida 10 años)
openssl req -x509 -new -nodes -days 3650 \
  -keyout ca.key -out ca.crt \
  -subj "/C=ES/ST=Valencia/L=Valencia/O=MiEmpresa/OU=IT/CN=Mi-CA"

# Crear clave y CSR del nodo usando SAN
openssl req -new -nodes \
  -keyout node.key -out node.csr \
  -config san.cnf

# Firmar el certificado del nodo con la CA, incluyendo SAN
openssl x509 -req -in node.csr \
  -CA ca.crt -CAkey ca.key -CAcreateserial \
  -out node.crt -days 365 -sha256 \
  -extfile san.cnf -extensions req_ext
  1. Verificación
openssl x509 -in node.crt -noout -text | grep -A1 "Subject Alternative Name"
X509v3 Subject Alternative Name:
    IP Address:192.168.1.50

Con este método, cada vez que quieras un nuevo certificado con otra IP o dominio, solo tienes que cambiar CN e IP.1 en san.cnf y volver a ejecutar los dos últimos comandos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment