Hola a todos, no sabía si poner el post aquí o en Hardware>Unix
Estoy haciendo pruebas para crear una ROOT CA + SUB CA con OpenSSL.
Actualmente tenemos todo el sistema montado con Windows con la entidad de Certificacion que trae la propia Windows:
- Root CA: fuera de dominio y apagada
- Sub CA: Integrada en dominio y es la que también proporciona la web con los CRL, además de tener las plantillas para que los equipos de dominio soliciten y se genere automáticamente su certificado.
Mi idea es reproducir el entorno pero con Linux y Openssl. Almenos mi primer objetivo es para las webs internas.
He seguido este tutorial https://jamielinux.com/docs/openssl-certificate-authority/ y todo funciona bien.
Problema con campo Subject Alternative Name (SAN)
- Creo la Root CA y la autofirmo
- Creo la Subca, la firmo con la Root y verifico que la cadena de certificacion sea correcta -> OK
- Creo el certificado de la web
openssl req -nodes -new -newkey rsa:4096 \
-keyout test3.psc.local.key \
-out test3.psc.local.csr \
-addext "subjectAltName = DNS:test3.psc.local" \
-subj "/C=ES/ST=Barcelona/L=Barcelona/O=GRG-CA/OU=GRG-CA/[email protected]/CN=test3.psc.local/"
Si reviso el CSR generado, veo que aparece el campo Subject Alternative Name con el nombre DNS (ya que se lo he indicado en el comando anterior con el -addext.
spoilerCertificate Request:
Data:
Version: 1 (0x0)
Subject: C = ES, ST = Barcelona, L = Barcelona, O = GRG-CA, OU = GRG-CA, emailAddress = [email protected], CN = test3.psc.local
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (4096 bit)
Modulus:
00:dc:17:8c:c1:90:26:16:67:4e:16:b3:0c:9b:2b:
3d:ec:8e:94:47:b9:8c:b8:14:ac:be:09:b8:bb:f5:
d8:f2:79:26:a6:9d:2f:73:5b:48:64:cb:3a:c2:f6:
bd:6d:7f:fd:7e:f2:3b:b7:07:35:70:20:5c:d3:f3:
0e:7d:8d:af:77:b8:f5:15:03:6a:d7:d3:17:a6:70:
da:60:a9:76:ef:61:0d:cd:8e:b2:b3:3c:ee:b2:b9:
54:af:2d:10:94:c6:95:39:25:c8:de:7c:84:9e:1e:
cb:27:fc:63:c7:6f:dc:78:92:6f:0e:a9:36:4a:d5:
67:63:bc:42:a6:82:42:06:bb:6b:8c:6f:79:55:a7:
c6:e0:c7:74:12:64:8f:bd:65:aa:72:1c:2b:ea:e9:
e6:9b:b3:98:37:90:89:b3:e1:e1:3a:4f:32:ea:19:
51:d1:c8:3b:92:83:e2:b3:89:cd:6a:a3:33:fc:ba:
4f:35:50:97:cd:24:3d:f8:35:ee:81:5f:1e:71:0f:
38:ff:54:93:27:bf:2c:32:c5:1b:31:ad:95:50:7f:
13:df:08:fe:9e:62:62:44:10:ba:ca:4b:4d:1e:51:
7b:f1:19:5d:99:07:75:e1:0c:d7:01:b2:46:c8:7d:
7e:b1:0d:17:5e:1c:56:d7:8b:3f:6a:96:ac:59:e9:
43:86:b6:82:c5:c4:b3:53:a6:2d:96:86:09:dc:2f:
4c:97:4c:3f:7e:20:00:3a:70:9c:8e:77:32:1d:e4:
5f:ca:f4:5a:5d:37:80:4e:09:7c:46:0b:7b:be:4a:
d1:31:f7:7a:a0:35:05:f3:d5:9a:22:a5:df:6c:9b:
6b:18:ae:22:43:3f:c8:0b:83:27:b1:c2:dc:37:d2:
5b:b4:63:82:bf:c7:8a:ec:3a:b1:23:c0:ac:e8:59:
38:57:f1:85:92:6c:0d:ba:fe:6f:84:30:61:b9:5e:
8b:d7:a4:f2:2f:80:c2:d6:cb:01:49:6f:49:65:2f:
26:55:c1:e0:96:db:a4:df:53:37:21:2d:c8:b2:3e:
fa:38:fe:e0:a7:74:81:69:cd:e3:7e:5c:3b:ac:78:
a1:51:89:8a:96:59:4d:5a:13:bb:b2:ed:8c:1b:ba:
b9:80:8c:0d:3b:e2:63:c0:60:0c:ce:72:de:e8:d7:
fb:64:fa:01:9a:30:31:36:4d:55:06:31:69:3a:7d:
f1:d8:78:82:24:ab:31:47:79:92:98:78:22:86:21:
0a:22:da:70:02:2f:38:8e:4c:e5:25:4a:07:5d:a9:
d0:c6:79:72:30:32:7d:32:20:cf:4f:12:de:ff:58:
f4:85:8c:d5:7e:a7:e0:e1:a0:b2:3b:67:42:5d:1a:
ea:56:63
Exponent: 65537 (0x10001)
Attributes:
Requested Extensions:
X509v3 Subject Alternative Name:
DNS:test3.psc.local
Signature Algorithm: sha256WithRSAEncryption
b5:f0:7f:ba:ab:dc:f6:ee:37:c5:fa:14:27:6b:09:a8:b8:08:
0b:4f:ed:2a:44:72:cd:8d:50:47:79:7d:69:e3:73:cc:14:89:
b6:69:ff:61:bb:79:0a:41:12:32:c7:d1:6f:1d:a4:e4:cb:ef:
16:56:35:fd:44:0a:0c:70:fc:45:1f:7d:c2:d7:4c:ca:bd:66:
6d:e6:41:74:56:2c:48:c9:a2:e5:0a:e7:05:69:a7:08:19:ef:
9d:20:35:f7:d2:06:47:88:4d:13:b2:73:cb:83:29:ae:0d:0b:
8d:bd:1c:a2:81:21:31:d9:b3:5c:65:76:fb:95:17:05:16:6c:
de:87:f2:f1:e7:90:12:69:94:13:d7:ec:64:20:a3:cd:0a:18:
87:be:e3:1a:ef:13:59:05:00:2c:09:61:be:d2:16:56:ad:e2:
e4:df:5a:b9:f8:fc:52:79:e7:07:53:f2:ec:f2:74:a1:d6:b9:
8e:00:19:2b:e5:25:5a:92:47:89:84:77:7b:cc:cd:6c:ec:a1:
7a:b8:6a:5c:41:c0:09:a4:3e:e8:49:9f:e7:c3:4e:23:cd:4a:
00:27:05:b1:2c:f7:ca:64:ff:35:8d:21:b3:06:a7:f4:aa:5f:
62:9f:dc:0c:df:07:8f:59:69:71:2e:d3:aa:5a:23:75:de:06:
6e:0a:72:15:7c:97:06:72:16:54:68:6b:fd:0c:74:2f:8d:56:
2d:67:65:99:2e:d0:27:fb:86:c1:91:d8:e8:a1:ad:ec:90:4b:
95:82:dc:15:a5:83:68:59:d4:2a:73:35:11:92:06:19:9d:54:
c0:dd:b6:b3:b4:87:d0:42:57:34:a7:74:5f:36:02:a0:20:2b:
14:37:da:cf:d9:36:b0:02:54:36:37:e1:20:1c:3f:20:bd:57:
85:33:29:fe:26:6f:05:37:10:62:5f:03:30:5f:4a:2f:d4:52:
9a:d0:b6:a2:2f:fc:72:f5:d4:ae:0f:dd:9d:9d:9c:68:ae:3b:
23:56:a3:3e:38:6b:ab:2b:2b:de:4c:11:d0:c7:6c:fa:df:bb:
0a:53:5d:7b:aa:14:53:98:e7:85:66:b6:c4:12:8c:ec:9f:81:
ba:bd:5a:31:9e:12:29:ff:12:26:ef:c5:b4:ee:3a:df:aa:d7:
19:fb:8f:1c:5a:bd:c0:36:31:92:49:06:59:41:72:e7:26:ce:
87:39:85:27:d5:df:97:3a:ac:ee:bd:f7:e8:45:e5:d0:2a:a5:
34:07:eb:a2:ca:88:2b:a5:9d:85:af:3f:7a:31:03:2b:1e:d3:
a1:5a:7f:64:e9:19:46:84:3c:0c:d8:7f:1b:1f:40:5f:bb:9c:
d5:04:7a:ae:68:26:77:ed
Sin embargo a la hora de firmarlo desaparece
root@PSC-CA-SUB:~/ca# openssl ca -config intermediate/sub-ca-openssl.cnf \
-extensions server_cert \
-days 375 -notext -md sha512 \
-in /root/ca/test3.psc.local.csr \
-out /root/ca/test3.psc.local.crt
spoilerUsing configuration from intermediate/sub-ca-openssl.cnf
Enter pass phrase for /root/ca/intermediate/private/intermediate.key.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 4099 (0x1003)
Validity
Not Before: Oct 12 20:58:53 2022 GMT
Not After : Oct 22 20:58:53 2023 GMT
Subject:
countryName = ES
stateOrProvinceName = Barcelona
localityName = Barcelona
organizationName = GRG-CA
organizationalUnitName = GRG-CA
commonName = test3.psc.local
emailAddress = [email protected]
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Cert Type:
SSL Server
Netscape Comment:
OpenSSL Generated Server Certificate
X509v3 Subject Key Identifier:
BC:11:0C:2E:08:FA:7D:91:16:1E:AC:0E:12:DA:80:69:64:F7:F1:58
X509v3 Authority Key Identifier:
keyid:7D:B8:7B:9E:59:4F:70:7B:F8:2C:1F:2B:0C:A2:E9:90:3C:D1:7A:71
DirName:/C=ES/ST=Barcelona/L=Barcelona/O=GRG-CA/OU=GRG-CA/CN=GRG Root CA
serial:10:00
X509v3 Key Usage: critical
Digital Signature, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 CRL Distribution Points:
Full Name:
URI:http://pki.dominio.com/intermediate.crl
Certificate is to be certified until Oct 22 20:58:53 2023 GMT (375 days)
Sign the certificate? [y/n]:
Esto es un problema, porque Firefox desde la version 101 usa este campo para marcar el certificado como fiable (obviamente comprobando también toda la cadena). Edge y Chrome más de lo mismo... solo Internet Explorer 11 lo acepta aunque no disponga de este campo. Obviamente me interesa que lo reconozcan los navegadores correctamente.
Actualmente con la de Windows lo hace, supongo que no eliminará dicho campo y por lo tanto los certificados quedan bien firmados.
Contenido del fichero de config de openssl para la subca
spoiler[ ca ]
default_ca = CA_default
[ CA_default ]
dir = /root/ca/intermediate
certs = $dir/certs
crl_dir = $dir/crl
new_certs_dir = $dir/newcerts
database = $dir/subordinate-ca-database.txt
serial = $dir/serial
RANDFILE = $dir/private/.rand
private_key = $dir/private/intermediate.key.pem
certificate = $dir/certs/intermediate.cert.pem
crlnumber = $dir/crlnumber
crl = $dir/crl/intermediate.crl.pem
crl_extensions = crl_ext
default_crl_days = 365
default_md = sha512
name_opt = ca_default
cert_opt = ca_default
default_days = 5840
preserve = no
policy = subca_policy
[ subca_policy ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
string_mask = utf8only
default_md = sha512
x509_extensions = v3_ca
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
stateOrProvinceName = State or Province Name
localityName = Locality Name
0.organizationName = Organization Name
organizationalUnitName = Organizational Unit Name
commonName = Common Name
emailAddress = Email Address
# Optionally, specify some defaults.
countryName_default = ES
stateOrProvinceName_default = Barcelona
localityName_default = Barcelona
0.organizationName_default = GRG-CA
organizationalUnitName_default = GRG-CA
#emailAddress_default =
[ v3_ca ]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical,CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
[ v3_intermediate_ca ]
# Extensions for a typical intermediate CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
[ usr_cert ]
# Extensions for client certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = client, email
nsComment = "OpenSSL Generated Client Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, emailProtection
[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
crlDistributionPoints = URI:http://pki.dominio.com/intermediate.crl
[ ocsp ]
# Extension for OCSP signing certificates (`man ocsp`).
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, digitalSignature
extendedKeyUsage = critical, OCSPSigning
[ crl_ext ]
# Extension for CRLs (`man x509v3_config`).
authorityKeyIdentifier=keyid:always
[ crl_info ]
URI.0 = http://pki.dominio.com/sub-ca.crl
URI.1 = https://www.dominio.com/pki/sub-ca.crl
He visto que hay gente que indica que a la hora de firmar, se añada un fichero con los alternative Names del dominio a firmar, pero me parece un poco feo si ya viene en el CSR tener que generar una config para cada firma que tenga que hacer... cosa que con el sistema de Windows no es necesario. No se si hay alguna forma de decirle que el campo SAN lo copie del fichero CSR (o almenos que no lo elimine)
He visto que otros dicen que se ponga un
extensions = copy
sin embargo por lo que leo en las respuestas, lo desaconsejan porque si alguien envia un certificado con CA:TRUE aunque fuera para un web server, estaría firmandole como subca... y aunque por lo general va a ser para uso interno, me gustaría dejarlo bien hecho