Привет, Хабр!
Нужно дерево сертификатов (корневой -> промежуточный -> клиент).
Как создать корневой и сертификат клиента я разобрался, а вот промежуточный - нет.
Ниже прилагаю команды и конфиг.
Команды:
# корневой сертификат
.\openssl genrsa -out "root.key"
.\openssl req -x509 -new -nodes -key "root.key" -sha256 -days 1024 -out "root.crt" -config "cnf.cnf" -subj "/C=country/ST=state/L=city/O=corp/OU=unit/CN=name/emailAddress=name@domain"
# тут должен быть промежуточный...
# серверный
.\openssl genrsa -out "server.key"
.\openssl req -new -key "server.key" -out "server.csr" -config "cnf.cnf"
.\openssl x509 -req -in "server.csr" -CA "intermediate.crt" -CAkey "intermediate.key" -CAcreateserial -out "server.crt" -extensions v3_req -extfile "cnf.cnf" -subj "/C=country/ST=state/L=city/O=corp/OU=unit/CN=name/emailAddress=name@domain"
# экспортирую серверный сертификат
.\openssl pkcs12 -export -in "server.crt" -inkey "server.key" -out "server.p12" -password pass:"xxXX1234"
# клиента
.\openssl genrsa -out "client.key"
.\openssl req -new -key "client.key" -out "client.csr" -config "cnf.cnf"
.\openssl x509 -req -in "client.csr" -CA "intermediate.crt" -CAkey "intermediate.key" -CAcreateserial -out "client.crt" -extensions v3_req -extfile "cnf.cnf" -subj "/C=country/ST=state/L=city/O=corp/OU=unit/CN=name/emailAddress=name@domain"
# экспортирую всё
.\openssl pkcs12 -export -in "server.crt" -inkey "server.key" -in "client.crt" -inkey "client.key" -in "intermediate.crt" -inkey "intermediates.key" -in "root.crt" -inkey "root.key" -out out.p12 -password pass:"password"
Конфиг:
[ ca ]
default_ca = CA_default
[ CA_default ]
default_days = 36500
default_md = sha256
preserve = no
email_in_dn = no
nameopt = default_ca
certopt = default_ca
policy = policy_match
[ policy_match ]
commonName = supplied
countryName = optional
stateOrProvinceName = optional
organizationName = optional
organizationalUnitName = optional
emailAddress = optional
[ req ]
input_password = xxXX1234
prompt = no
distinguished_name = kostil
default_bits = 2048
default_keyfile = priv.pem
default_md = sha256
req_extensions = v3_req
encyrpt_key = no
[ kostil ]
commonName = KOSTIL'
[ v3_ca ]
basicConstraints = CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
[ v3_req ]
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = $dns
IP.1 = $ip