@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
export MSYS_NO_PATHCONV=1
|
||||
|
||||
mkdir -p certs
|
||||
cd certs
|
||||
|
||||
# 1. CA
|
||||
openssl req -x509 -newkey rsa:4096 -days 365 -nodes \
|
||||
-keyout ca.key -out ca.crt \
|
||||
-subj "/C=RU/ST=Moscow/L=Moscow/O=MTUSI/CN=MTUSI-Local-CA"
|
||||
|
||||
# 2. Nginx (внешний TLS)
|
||||
openssl req -newkey rsa:2048 -nodes \
|
||||
-keyout nginx.key -out nginx.csr \
|
||||
-subj "/C=RU/ST=Moscow/L=Moscow/O=MTUSI/CN=localhost"
|
||||
|
||||
# Создаем временный файл с расширениями для SAN
|
||||
echo "subjectAltName=DNS:localhost,IP:127.0.0.1" > nginx.ext
|
||||
|
||||
openssl x509 -req -in nginx.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
|
||||
-out nginx.crt -days 365 -sha256 -extfile nginx.ext
|
||||
|
||||
# 3. API client (mTLS от Nginx)
|
||||
openssl req -newkey rsa:2048 -nodes \
|
||||
-keyout api-client.key -out api-client.csr \
|
||||
-subj "/C=RU/ST=Moscow/L=Moscow/O=MTUSI/CN=nginx-client"
|
||||
|
||||
openssl x509 -req -in api-client.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
|
||||
-out api-client.crt -days 365 -sha256
|
||||
|
||||
# 4. API server (mTLS)
|
||||
openssl req -newkey rsa:2048 -nodes \
|
||||
-keyout api-server.key -out api-server.csr \
|
||||
-subj "/C=RU/ST=Moscow/L=Moscow/O=MTUSI/CN=api"
|
||||
|
||||
# Создаем временный файл с расширениями для SAN
|
||||
echo "subjectAltName=DNS:api,IP:127.0.0.1" > api-server.ext
|
||||
|
||||
openssl x509 -req -in api-server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
|
||||
-out api-server.crt -days 365 -sha256 -extfile api-server.ext
|
||||
|
||||
# 5. Truststore для API
|
||||
keytool -importcert -noprompt -alias ca -file ca.crt -keystore truststore.p12 -storepass changeit -storetype PKCS12
|
||||
|
||||
# 6. Keystore для API
|
||||
openssl pkcs12 -export -in api-server.crt -inkey api-server.key -out keystore.p12 -name api -passout pass:changeit
|
||||
|
||||
echo "Сертификаты созданы."
|
||||
Reference in New Issue
Block a user