# Создание сертификатов для TLS

Для генерации сертификатов потребуется установленная программа [openssl](https://www.openssl.org/).

1. Сгенерируйте корневой ключ. Вместо слова «password» укажите пароль ключа:

```
openssl genrsa -aes256 -passout pass:password -out RootKey.pem 2048
```

2. Сгенерируйте самоподписанный сертификат полученного ключа. Вместо слова «password» укажите ранее указанный пароль ключа, после ключа `-subj` укажите информацию об авторе ключа:

```
openssl req -x509 -new -nodes -key RootKey.pem 
    -passin pass:password -sha256 -days 365 -out RootCert.pem 
    -subj "/C=CountryName/ST=StateOrProvinceName/L=Locality/O=Organization/OU=OrganizationalUnit/CN=CommonName"
```

3. Сгенерируйте еще один ключ:

```
openssl genrsa -aes256 -passout pass:password -out PK.pem 2048
```

4. Создайте запрос на подписывание этого ключа ранее созданным корневым сертификатом. После `-subj` укажите информацию о новом ключе:

```
openssl req -new -key PK.pem -passin pass:password -out PK_SignReq.pem 
    -subj "/C=CountryName/ST=StateOrProvinceName/L=Locality/O=Organization/OU=OrganizationalUnit/CN=Serv.CommonName"
```

5. Подпишите ключ корневым сертификатом:

```
openssl x509 -req -in PK_SignReq.pem -CA RootCert.pem -CAkey RootKey.pem 
    -passin pass:password -CAcreateserial -out ServCert.pem -days 365 -sha256
```

6. Поместите ключи и сертификаты в хранилище сертификатов в формате PKCS12. Вместо «password» укажите пароль ключа, вместо «passwordKeystore» - пароль от хранилища (**Рекомендуется указать пароль, отличный от других паролей**):
7. В файле настроек *application.properties* укажите следующее:

```
server.ssl.key-store-type=PKCS12
server.ssl.key-store=[путь к файлу Keystore.p12]
server.ssl.key-store-password=[passwordKeyStore]
server.ssl.key-alias=Key
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aamsystems.ru/passoffice/passoffice-guide/admin-guide-doc/ustanovka-passoffice/tls-certs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
