(2022-08-03 14:30:38 отредактировано vanobl)

Рутокен ЭЦП 2.0 + stunnel

OS = Ubuntu Server 22.04
token = Рутокен ЭЦП 2.0
openssl = OpenSSL 1.1.1f
stunnel = stunnel 5.56

Для настройки использовалась статья . Но с настройками openssl из статьи stunnel вообще не стартует. С настройками этой статьи stunnel стартует, процесс висит, но не работает.

Мои настройки такие:
openssl.cnf:

openssl_conf = openssl_def
*******
[openssl_def]
engines = engine_section

[engine_section]
rtengine = gost_section
pkcs11 = pkcs11_section

[gost_section]
engine_id = rtengine
dynamic_path = /usr/lib/x86_64-linux-gnu/librtengine.so
pkcs11_path = /usr/lib/librtpkcs11ecp.so
# rand_token = pkcs11:manufacturer=Aktiv%20Co.;model=Rutoken%20ECP;id=048883ad0cce9ce51ea7206c8f7d629a6bfdeb22
rand_token = pkcs11:model=Rutoken%20ECP?pin-value=12345678
default_algorithms = CIPHERS, DIGEST, PKEY, RAND
enable_rand = yes

[pkcs11_section]
engine_id = pkcs11
dynamic_path = /usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
MODULE_PATH = /usr/lib/librtpkcs11ecp.so
default_algorithms = CIPHERS, DIGEST, PKEY, RAND

stunnel.conf:

; уровень логирования и путь до лог-файла
debug = 7
output = /home/tester/stunnel.log
pid = /home/tester/stunnel_cli_pid.pid

; устанавливаем протокол защиты TLSv1
sslVersion = TLSv1.1
; sslVersion = all
; подгружаем движок
engine = rtengine
; engine = pkcs11
[https]
engineId = rtengine
; engineId = pkcs11

client = yes
accept = 127.0.0.1:8000
connect = sit01.dom.test.gosuslugi.ru:10082

; путь до корневого сертификата
CAFile = /etc/stunnel/CA-SIT_2022.pem
checkHost = yes

; путь до сертификата клиента
; cert=pkcs11:model=Rutoken%20ECP?pin-value=12345678
; cert=pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7
cert = /home/tester/my_certs/rezonans_new_base64.cer

; путь до ключа на токене.
key=pkcs11:model=Rutoken%20ECP?pin-value=12345678
; key=pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7
options = NO_SSLv2

; устанавливаем верификацию
verify = 2

stunnel.log:

2022.08.03 14:18:25 LOG7[ui]: Clients allowed=500
2022.08.03 14:18:25 LOG5[ui]: stunnel 5.56 on x86_64-pc-linux-gnu platform
2022.08.03 14:18:25 LOG5[ui]: Compiled with OpenSSL 1.1.1c  28 May 2019
2022.08.03 14:18:25 LOG5[ui]: Running  with OpenSSL 1.1.1f  31 Mar 2020
2022.08.03 14:18:25 LOG5[ui]: Threading:PTHREAD Sockets:POLL,IPv6,SYSTEMD TLS:ENGINE,FIPS,OCSP,PSK,SNI Auth:LIBWRAP
2022.08.03 14:18:25 LOG7[ui]: errno: (*__errno_location ())
2022.08.03 14:18:25 LOG5[ui]: Reading configuration from file /etc/stunnel/stunnel.conf
2022.08.03 14:18:25 LOG5[ui]: UTF-8 byte order mark not detected
2022.08.03 14:18:25 LOG7[ui]: Enabling support for engine "rtengine"
2022.08.03 14:18:25 LOG6[ui]: UI not supported by engine #1 (rtengine)
2022.08.03 14:18:25 LOG7[ui]: Initializing engine #1 (rtengine)
2022.08.03 14:18:25 LOG6[ui]: Engine #1 (rtengine) initialized
2022.08.03 14:18:25 LOG5[ui]: FIPS mode disabled
2022.08.03 14:18:25 LOG7[ui]: Compression disabled
2022.08.03 14:18:25 LOG7[ui]: No PRNG seeding was required
2022.08.03 14:18:25 LOG6[ui]: Initializing service [https]
2022.08.03 14:18:26 LOG7[ui]: Ciphers: HIGH:!aNULL:!SSLv2:!DH:!kDHEPSK
2022.08.03 14:18:26 LOG7[ui]: TLSv1.3 ciphersuites: TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM>2022.08.03 14:18:26 LOG7[ui]: TLS options: 0x02100004 (+0x00000000, -0x00000000)
2022.08.03 14:18:26 LOG6[ui]: Client certificate engine (rtengine) not supported
2022.08.03 14:18:26 LOG6[ui]: Loading certificate from engine ID: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 14:18:26 LOG3[ui]: ENGINE_ctrl_cmd: Peer suddenly disconnected
2022.08.03 14:18:26 LOG6[ui]: Initializing private key on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
2022.08.03 14:18:28 LOG6[ui]: Private key initialized on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
2022.08.03 14:18:28 LOG6[ui]: Loading certificate from file: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 14:18:28 LOG6[ui]: Certificate loaded from file: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 14:18:28 LOG7[ui]: Private key check succeeded
2022.08.03 14:18:28 LOG5[ui]: Configuration successful
2022.08.03 14:18:28 LOG7[ui]: Binding service [https]
2022.08.03 14:18:28 LOG7[ui]: Listening file descriptor created (FD=10)
2022.08.03 14:18:28 LOG7[ui]: Setting accept socket options (FD=10)
2022.08.03 14:18:28 LOG7[ui]: Option SO_REUSEADDR set on accept socket
2022.08.03 14:18:28 LOG6[ui]: Service [https] (FD=10) bound to 127.0.0.1:8000
2022.08.03 14:18:28 LOG7[main]: Created pid file /home/tester/stunnel_cli_pid.pid
2022.08.03 14:18:28 LOG7[cron]: Cron thread initialized
2022.08.03 14:18:28 LOG6[cron]: Executing cron jobs
2022.08.03 14:18:28 LOG6[cron]: Cron jobs completed in 0 seconds
2022.08.03 14:18:28 LOG7[cron]: Waiting 86400 seconds
2022.08.03 14:18:49 LOG7[main]: Found 1 ready file descriptor(s)
2022.08.03 14:18:49 LOG7[main]: FD=5 events=0x2001 revents=0x1
2022.08.03 14:18:49 LOG7[main]: FD=10 events=0x2001 revents=0x0
2022.08.03 14:18:49 LOG7[main]: Dispatching a signal from the signal pipe
2022.08.03 14:18:49 LOG7[main]: Processing SIGNAL_TERMINATE
2022.08.03 14:18:49 LOG5[main]: Terminated
2022.08.03 14:18:49 LOG7[main]: Leak detection table utilization: 13/997, 1.30%
2022.08.03 14:18:49 LOG7[main]: Removed pid file /home/tester/stunnel_cli_pid.pid
2022.08.03 14:18:49 LOG7[main]: Terminating the cron thread
2022.08.03 14:18:49 LOG5[main]: Terminating 1 service thread(s)
2022.08.03 14:18:49 LOG5[main]: Service threads terminated
2022.08.03 14:18:49 LOG7[main]: Deallocating section defaults

Подскажите, пожалуйста, в чём может быть проблема?

Если в stunnel.conf вызвать движок pkcs11, а так же параметр cert сделать:
pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7

Тогда при попытке запуска stunnel вывод будет таким:

Specified object not found
Specified object not found
Specified object not found
PKCS11_get_private_key returned NULL
[ ] Clients allowed=500
[.] stunnel 5.56 on x86_64-pc-linux-gnu platform
[.] Compiled with OpenSSL 1.1.1c  28 May 2019
[.] Running  with OpenSSL 1.1.1f  31 Mar 2020
[.] Threading:PTHREAD Sockets:POLL,IPv6,SYSTEMD TLS:ENGINE,FIPS,OCSP,PSK,SNI Auth:LIBWRAP
[ ] errno: (*__errno_location ())
[.] Reading configuration from file /etc/stunnel/stunnel.conf
[.] UTF-8 byte order mark not detected
[ ] Enabling support for engine "pkcs11"
[.] UI set for engine #1 (pkcs11)
[ ] Initializing engine #1 (pkcs11)
[ ] Engine #1 (pkcs11) initialized
[.] FIPS mode disabled
[ ] Compression disabled
[ ] No PRNG seeding was required
[ ] Initializing service [https]
[ ] Ciphers: HIGH:!aNULL:!SSLv2:!DH:!kDHEPSK
[ ] TLSv1.3 ciphersuites: TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256
[ ] TLS options: 0x02100004 (+0x00000000, -0x00000000)
[ ] Client certificate engine (pkcs11) not supported
[ ] Loading certificate from engine ID: pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7
[!] ENGINE_ctrl_cmd: eng_back.c:593: error:82066065:pkcs11 engine:ctx_ctrl_load_cert:object not found
[ ] Initializing private key on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
[!] error queue: ../crypto/engine/eng_pkey.c:77: error:26096080:engine routines:ENGINE_load_private_key:failed loading private key
[!] ENGINE_load_private_key: eng_back.c:858: error:82067065:pkcs11 engine:ctx_load_privkey:object not found
[ ] Loading certificate from file: pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7
[!] error queue: ../ssl/ssl_rsa.c:615: error:140DC002:SSL routines:use_certificate_chain_file:system lib
[!] error queue: ../crypto/bio/bss_file.c:290: error:20074002:BIO routines:file_ctrl:system lib
[!] SSL_CTX_use_certificate_chain_file: ../crypto/bio/bss_file.c:288: error:02001002:system library:fopen:No such file or directory
[!] Service [https]: Failed to initialize TLS context
[ ] Deallocating section defaults

Re: Рутокен ЭЦП 2.0 + stunnel

vanobl, добрый день.
Вам либо необходимо в конфиге openssl либо раскомментировать строку rand_token с указанием серийного номера токена, либо закомментировать строку enable_rand = yes

Re: Рутокен ЭЦП 2.0 + stunnel

Кирилл, здравствуйте!

Изменения не помогли.

openssl.cnf теперь такой (закоментированы неудачные пробы :))

[engine_section]
rtengine = gost_section

[gost_section]
engine_id = rtengine
dynamic_path = /usr/lib/x86_64-linux-gnu/librtengine.so
pkcs11_path = /usr/lib/librtpkcs11ecp.so
# rand_token = pkcs11:model=Rutoken%20ECP;object=67b77c19-2098-4892-944f-256813baaf0a?pin-value=12345678
rand_token = pkcs11:model=Rutoken%20ECP;id=0477dda5f69dfb917a512ff03460557567690ab7?pin-value=12345678
default_algorithms = CIPHERS, DIGEST, PKEY, RAND
enable_rand = yes
# MinProtocol = TLSv1
# CipherString = DEFAULT:@SECLEVEL=1

stunnel.log

2022.08.03 17:22:27 LOG5[main]: Terminatedwed=500
2022.08.03 17:21:45 LOG5[ui]: stunnel 5.56 on x86_64-pc-linux-gnu platform
2022.08.03 17:21:45 LOG5[ui]: Compiled with OpenSSL 1.1.1c  28 May 2019
2022.08.03 17:21:45 LOG5[ui]: Running  with OpenSSL 1.1.1f  31 Mar 2020
2022.08.03 17:21:45 LOG5[ui]: Threading:PTHREAD Sockets:POLL,IPv6,SYSTEMD TLS:ENGINE,FIPS,OCSP,PSK,SNI Auth:LIBWRAP
2022.08.03 17:21:45 LOG7[ui]: errno: (*__errno_location ())
2022.08.03 17:21:45 LOG5[ui]: Reading configuration from file /etc/stunnel/stunnel.conf
2022.08.03 17:21:45 LOG5[ui]: UTF-8 byte order mark not detected
2022.08.03 17:21:45 LOG7[ui]: Enabling support for engine "rtengine"
2022.08.03 17:21:45 LOG6[ui]: UI not supported by engine #1 (rtengine)
2022.08.03 17:21:45 LOG7[ui]: Initializing engine #1 (rtengine)
2022.08.03 17:21:45 LOG6[ui]: Engine #1 (rtengine) initialized
2022.08.03 17:21:45 LOG5[ui]: FIPS mode disabled
2022.08.03 17:21:45 LOG7[ui]: Compression disabled
2022.08.03 17:21:45 LOG7[ui]: No PRNG seeding was required
2022.08.03 17:21:45 LOG6[ui]: Initializing service [https]
2022.08.03 17:21:46 LOG7[ui]: Ciphers: HIGH:!aNULL:!SSLv2:!DH:!kDHEPSK
2022.08.03 17:21:46 LOG7[ui]: TLSv1.3 ciphersuites: TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256
2022.08.03 17:21:46 LOG7[ui]: TLS options: 0x02100004 (+0x00000000, -0x00000000)
2022.08.03 17:21:46 LOG6[ui]: Client certificate engine (rtengine) not supported
2022.08.03 17:21:46 LOG6[ui]: Loading certificate from engine ID: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 17:21:46 LOG3[ui]: ENGINE_ctrl_cmd: Peer suddenly disconnected
2022.08.03 17:21:46 LOG6[ui]: Initializing private key on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
2022.08.03 17:21:48 LOG6[ui]: Private key initialized on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
2022.08.03 17:21:48 LOG6[ui]: Loading certificate from file: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 17:21:48 LOG6[ui]: Certificate loaded from file: /home/tester/my_certs/rezonans_new_base64.cer
2022.08.03 17:21:48 LOG7[ui]: Private key check succeeded
2022.08.03 17:21:48 LOG4[ui]: Service [https] needs authentication to prevent MITM attacks
2022.08.03 17:21:48 LOG5[ui]: Configuration successful
2022.08.03 17:21:48 LOG7[ui]: Binding service [https]
2022.08.03 17:21:48 LOG7[ui]: Listening file descriptor created (FD=10)
2022.08.03 17:21:48 LOG7[ui]: Setting accept socket options (FD=10)
2022.08.03 17:21:48 LOG7[ui]: Option SO_REUSEADDR set on accept socket
2022.08.03 17:21:48 LOG6[ui]: Service [https] (FD=10) bound to 127.0.0.1:8000
2022.08.03 17:21:48 LOG7[main]: Created pid file /home/tester/stunnel_cli_pid.pid
2022.08.03 17:21:48 LOG7[cron]: Cron thread initialized
2022.08.03 17:21:48 LOG6[cron]: Executing cron jobs
2022.08.03 17:21:48 LOG6[cron]: Cron jobs completed in 0 seconds
2022.08.03 17:21:48 LOG7[cron]: Waiting 86400 seconds
2022.08.03 17:22:02 LOG7[main]: Found 1 ready file descriptor(s)
2022.08.03 17:22:02 LOG7[main]: FD=5 events=0x2001 revents=0x0
2022.08.03 17:22:02 LOG7[main]: FD=10 events=0x2001 revents=0x1
2022.08.03 17:22:02 LOG7[main]: Service [https] accepted (FD=3) from 127.0.0.1:43420
2022.08.03 17:22:02 LOG7[0]: Service [https] started
2022.08.03 17:22:02 LOG7[0]: Setting local socket options (FD=3)
2022.08.03 17:22:02 LOG7[0]: Option TCP_NODELAY set on local socket
2022.08.03 17:22:02 LOG5[0]: Service [https] accepted connection from 127.0.0.1:43420
2022.08.03 17:22:02 LOG6[0]: s_connect: connecting 217.107.108.147:10082
2022.08.03 17:22:02 LOG7[0]: s_connect: s_poll_wait 217.107.108.147:10082: waiting 10 seconds
2022.08.03 17:22:02 LOG7[0]: FD=7 events=0x2001 revents=0x0
2022.08.03 17:22:02 LOG7[0]: FD=12 events=0x2005 revents=0x0
2022.08.03 17:22:02 LOG5[0]: s_connect: connected 217.107.108.147:10082
2022.08.03 17:22:02 LOG5[0]: Service [https] connected remote server from 192.168.1.3:47534
2022.08.03 17:22:02 LOG7[0]: Setting remote socket options (FD=12)
2022.08.03 17:22:02 LOG7[0]: Option TCP_NODELAY set on remote socket
2022.08.03 17:22:02 LOG7[0]: Remote descriptor (FD=12) initialized
2022.08.03 17:22:02 LOG6[0]: SNI: sending servername: sit01.dom.test.gosuslugi.ru
2022.08.03 17:22:02 LOG6[0]: Peer certificate not required
2022.08.03 17:22:02 LOG7[0]: TLS state (connect): before SSL initialization
2022.08.03 17:22:02 LOG7[0]: TLS alert (write): fatal: internal error
2022.08.03 17:22:02 LOG3[0]: SSL_connect: ../ssl/statem/statem_clnt.c:1112: error:141E70BF:SSL routines:tls_construct_client_hello:no protocols availa>2022.08.03 17:22:02 LOG5[0]: Connection reset: 0 byte(s) sent to TLS, 0 byte(s) sent to socket
2022.08.03 17:22:02 LOG7[0]: Remote descriptor (FD=12) closed
2022.08.03 17:22:02 LOG7[0]: Local descriptor (FD=3) closed
2022.08.03 17:22:02 LOG7[0]: Service [https] finished (0 left)
2022.08.03 17:22:27 LOG7[main]: Found 1 ready file descriptor(s)
2022.08.03 17:22:27 LOG7[main]: FD=5 events=0x2001 revents=0x1
2022.08.03 17:22:27 LOG7[main]: FD=10 events=0x2001 revents=0x0
2022.08.03 17:22:27 LOG7[main]: Dispatching a signal from the signal pipe
2022.08.03 17:22:27 LOG7[main]: Processing SIGNAL_TERMINATE
2022.08.03 17:22:27 LOG5[main]: Terminated
2022.08.03 17:22:27 LOG7[main]: Leak detection table utilization: 40/997, 4.01%
2022.08.03 17:22:27 LOG7[main]: Removed pid file /home/tester/stunnel_cli_pid.pid
2022.08.03 17:22:27 LOG7[main]: Terminating the cron thread

Re: Рутокен ЭЦП 2.0 + stunnel

Можете попробовать в конфиге stunnel поменять версию протокола TLS:
sslVersion=TLSv1 или TLSv1.1

Re: Рутокен ЭЦП 2.0 + stunnel

Кирилл, спасибо! Но этот параметр уже есть в конфиге.
Буду пробовать всё накатить на чистую систему, может дело в этом...

Re: Рутокен ЭЦП 2.0 + stunnel

vanobl пишет:

Но этот параметр уже есть в конфиге.

Тогда странно, что в логе подключения есть информация про TLS 1.3. Может быть сервер не поддерживает такое подключение?
Есть возможность проверить установку соединения с ключем не на токене, а в файле?

Так же, можно для проверки, что сам stunnel работает корректно, проверить соединение с тестовыми серверами КриптоПро по инструкции https://habr.com/ru/company/aktiv-company/blog/477650/

Re: Рутокен ЭЦП 2.0 + stunnel

Аверченко Кирилл пишет:

Тогда странно, что в логе подключения есть информация про TLS 1.3. Может быть сервер не поддерживает такое подключение?
Есть возможность проверить установку соединения с ключем не на токене, а в файле?

Так же, можно для проверки, что сам stunnel работает корректно, проверить соединение с тестовыми серверами КриптоПро по инструкции https://habr.com/ru/company/aktiv-company/blog/477650/

Да я тоже видел TLS 1.3 и никак не могу понять откуда он берётся.
К сожалению у нас не выгружаемый контейнер.
А вот всё остальное проверить можно.
Так же хочу проверить на чистой системе, чтобы небыло установки криптопро и stunnel от криптопро.

Re: Рутокен ЭЦП 2.0 + stunnel

Есть некоторые подвижки.

Немного изменил файл stunnel.conf:

; уровень логирования и путь до лог-файла
debug = 7
output = /var/lib/stunnel4/stunnel.log

; устанавливаем протокол защиты TLSv1.2
sslVersion=TLSv1.1

; подгружаем движок
engine = pkcs11
engineCtrl = MODULE_PATH:/usr/lib/librtpkcs11ecp.so

fips = no

; настраиваем туннель на клиенте
[https]
; указываем engine, необходимый для подгрузки ключей
engineId = pkcs11

; устанавливаем верификацию 2 (принудительную проверку сертификата)
verify = 2
; путь до корневого сертификата
CAFile = /etc/stunnel/CA-SIT_2022.pem
; путь до сертификата клиента
cert = pkcs11:model=Rutoken%20ECP?pin-value=12345678

; путь до ключа на токене.
; key = pkcs11:id=0477dda5f69dfb917a512ff03460557567690ab7
; key = pkcs11:id=7837865CFAD361E58A23474F42185EE4848DA2F2
options = NO_SSLv2


client = yes
accept = 127.0.0.1:8000
connect = sit01.dom.test.gosuslugi.ru:10082

Вывод при запуске тоже поменялся:

No private keys found.
PKCS11_get_private_key returned NULL
[ ] Clients allowed=500
[.] stunnel 5.56 on x86_64-pc-linux-gnu platform
[.] Compiled with OpenSSL 1.1.1c  28 May 2019
[.] Running  with OpenSSL 1.1.1f  31 Mar 2020
[.] Threading:PTHREAD Sockets:POLL,IPv6,SYSTEMD TLS:ENGINE,FIPS,OCSP,PSK,SNI Auth:LIBWRAP
[ ] errno: (*__errno_location ())
[.] Reading configuration from file /etc/stunnel/stunnel.conf
[.] UTF-8 byte order mark not detected
[ ] Enabling support for engine "pkcs11"
[.] UI set for engine #1 (pkcs11)
[ ] Executing engine control command MODULE_PATH:/usr/lib/librtpkcs11ecp.so
[ ] Initializing engine #1 (pkcs11)
[ ] Engine #1 (pkcs11) initialized
[.] FIPS mode disabled
[ ] Compression disabled
[ ] No PRNG seeding was required
[ ] Initializing service [https]
[ ] Ciphers: HIGH:!aNULL:!SSLv2:!DH:!kDHEPSK
[ ] TLSv1.3 ciphersuites: TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256
[ ] TLS options: 0x02100004 (+0x00000000, -0x00000000)
[ ] Client certificate engine (pkcs11) not supported
[ ] Loading certificate from engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
[ ] Certificate loaded from engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
[ ] Initializing private key on engine ID: pkcs11:model=Rutoken%20ECP?pin-value=12345678
[!] error queue: ../crypto/engine/eng_pkey.c:77: error:26096080:engine routines:ENGINE_load_private_key:failed loading private key
[!] ENGINE_load_private_key: eng_back.c:858: error:82067065:pkcs11 engine:ctx_load_privkey:object not found
[ ] Loading private key from file: pkcs11:model=Rutoken%20ECP?pin-value=12345678
[!] pkcs11:model=Rutoken%20ECP?pin-value=12345678: No such file or directory (2)
[!] Service [https]: Failed to initialize TLS context
[ ] Deallocating section defaults

Теперь не находит только приватный ключ.

openssl.cnf теперь такой:

[openssl_def]
engines = engine_section

[engine_section]
rtengine = gost_section
pkcs11 = pkcs11_section

[gost_section]
engine_id = rtengine
dynamic_path = /usr/lib/x86_64-linux-gnu/librtengine.so
pkcs11_path = /usr/lib/librtpkcs11ecp.so
rand_token = pkcs11:model=Rutoken%20ECP?pin-value=12345678
default_algorithms = CIPHERS, DIGEST, PKEY, RAND
enable_rand = yes

[pkcs11_section]
engine_id = pkcs11
dynamic_path = /usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
MODULE_PATH = /usr/lib/librtpkcs11ecp.so
default_algorithms = CIPHERS, DIGEST, PKEY, RAND

Re: Рутокен ЭЦП 2.0 + stunnel

Если вы используете сертификат и ключи формата ГОСТ, то использовать pkcs11.so не получится.
Необходимо все-таки использовать rtengine.
Второй момент, у вас указано где взять сертификат, но закомментирована строка с ключем.