Шифрование и подпись с помощью Рутокен ЭЦП
токен инициализировали так:
pkcs15-init --erase-card -p rutoken_ecp
pkcs15-init --create-pkcs15 --so-pin "1234567890" --so-puk ""
pkcs15-init --store-pin --label "User PIN" --auth-id 02 --pin "0987654321" --puk "" --so-pin "1234567890" --finalize
pkcs11-tool --module /usr/lib64/opensc-pkcs11.so --keypairgen --key-type rsa:2048 --login -p 0987654321 --label "user"
--id 6e65776b6579736574
Теперь необходимо подписать файл. Вариант раз, без использования библиотеки rutoken:
echo "engine -t dynamic -pre SO_PATH:/usr/lib64/openssl/engines/engine_pkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:/usr/lib64/opensc-pkcs11.so
rsautl -engine pkcs11 -keyform engine -inkey slot_2-id_6e65776b6579736574 -sign -in init_cs.sh -out init_cs.sh.sig"|openssl
В ответ openssl ругается
OpenSSL> (dynamic) Dynamic engine loading support
[Success]: SO_PATH:/usr/lib64/openssl/engines/engine_pkcs11.so
[Success]: ID:pkcs11
[Success]: LIST_ADD:1
[Success]: LOAD
[Success]: MODULE_PATH:/usr/lib64/opensc-pkcs11.so
Loaded: (pkcs11) pkcs11 engine
[ available ]
139943002773376:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:187:filename(/usr/lib64/openssl/engines/libgost.so): /usr/lib64/openssl/engines/libgost.so: cannot open shared object file: No such file or directory
139943002773376:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139943002773376:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:450:
139943002773376:error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:419:id=gost
139943002773376:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:187:filename(libgost.so): libgost.so: cannot open shared object file: No such file or directory
139943002773376:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139943002773376:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:450:
OpenSSL> engine "pkcs11" set.
Invalid slot number: 2
PKCS11_get_private_key returned NULL
cannot load Private Key from engine
139943002773376:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:187:filename(/usr/lib64/openssl/engines/libgost.so): /usr/lib64/openssl/engines/libgost.so: cannot open shared object file: No such file or directory
139943002773376:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139943002773376:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:450:
139943002773376:error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:419:id=gost
139943002773376:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:187:filename(libgost.so): libgost.so: cannot open shared object file: No such file or directory
139943002773376:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139943002773376:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:450:
139943002773376:error:26096080:engine routines:ENGINE_load_private_key:failed loading private key:eng_pkey.c:126:
unable to load Private Key
error in rsautl
OpenSSL>
Думается проблема в том, что модуль собран с gost'ом, а openssl - нет.
Вариант два, с использованием библиотеки рутокен:
echo "engine -t dynamic -pre SO_PATH:/usr/lib64/openssl/engines/engine_pkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:/opt/aktivco/rutokenecp/x86_64/librtpkcs11ecp.so
rsautl -engine pkcs11 -keyform engine -inkey slot_2-id_6e65776b6579736574 -sign -in init_cs.sh -out init_cs.sh.sig"|openssl
Ответ получаем другого содержания
OpenSSL> (dynamic) Dynamic engine loading support
[Success]: SO_PATH:/usr/lib64/openssl/engines/engine_pkcs11.so
[Success]: ID:pkcs11
[Success]: LIST_ADD:1
[Success]: LOAD
[Success]: MODULE_PATH:/opt/aktivco/rutokenecp/x86_64/librtpkcs11ecp.so
Loaded: (pkcs11) pkcs11 engine
[ available ]
OpenSSL> engine "pkcs11" set.
Found empty token;
PKCS11_get_private_key returned NULL
cannot load Private Key from engine
140095143139200:error:26096080:engine routines:ENGINE_load_private_key:failed loading private key:eng_pkey.c:126:
unable to load Private Key
error in rsautl
OpenSSL>
Судя по ответу — модуль подгрузился, но работать не захотел, ПИН не спросил.
Вывод различных утилит:
$ pkcs15-tool -D
Using reader with a card: Aktiv Rutoken ECP 00 00
PKCS#15 Card [Rutoken ECP]:
Version : 0
Serial number : 00000000303E60D0
Manufacturer ID: Aktiv Co.
Last update : 20140717055504Z
Flags : EID compliant
PIN [Security Officer PIN]
Object Flags : [0x3], private, modifiable
ID : 01
Flags : [0x99], case-sensitive, unblock-disabled, initialized, soPin
Length : min_len:8, max_len:32, stored_len:32
Pad char : 0x00
Reference : 1 (0x01)
Type : ascii-numeric
PIN [User PIN]
Object Flags : [0x3], private, modifiable
ID : 02
Flags : [0x19], case-sensitive, unblock-disabled, initialized
Length : min_len:4, max_len:32, stored_len:32
Pad char : 0x00
Reference : 2 (0x02)
Type : ascii-numeric
Private RSA Key [Certificate]
Object Flags : [0x3], private, modifiable
Usage : [0x2E], decrypt, sign, signRecover, unwrap
Access Flags : [0x0]
ModLength : 2048
Key ref : 1 (0x1)
Native : yes
Path : 3f001000100060020001
Auth ID : 02
ID : 6e65776b6579736574
GUID : {1c623536-406f-01c7-cfc0-4aab6ecb8b79}
Public RSA Key [kostousov-ds-ra]
Object Flags : [0x2], modifiable
Usage : [0xD1], encrypt, wrap, verify, verifyRecover
Access Flags : [0x0]
ModLength : 2048
Key ref : 0 (0x0)
Native : no
Path : 3f0050000200
ID : 6e65776b6579736574
DirectValue : <absent>
X.509 Certificate [Certificate]
Object Flags : [0x2], modifiable
Authority : no
Path : 3f0050000300
ID : 6e65776b6579736574
GUID : {1c623536-406f-01c7-cfc0-4aab6ecb8b79}
Encoded serial : 02 08 700D69305EEA7F8E
$ p11tool --list-tokens
Token 0:
URL: pkcs11:model=p11-kit-trust;manufacturer=PKCS%2311%20Kit;serial=1;token=System%20Trust
Label: System Trust
Manufacturer: PKCS#11 Kit
Model: p11-kit-trust
Serial: 1
Token 1:
URL: pkcs11:model=p11-kit-trust;manufacturer=PKCS%2311%20Kit;serial=1;token=Default%20Trust
Label: Default Trust
Manufacturer: PKCS#11 Kit
Model: p11-kit-trust
Serial: 1
Token 2:
URL: pkcs11:model=PKCS%2315;manufacturer=Aktiv%20Co.;serial=00000000303E60D0;token=Rutoken%20ECP%20%28User%20PIN%29
Label: Rutoken ECP (User PIN)
Manufacturer: Aktiv Co.
Model: PKCS#15
Serial: 00000000303E60D0
Как правильно производить подпись или шифрования средствами rutoken?
Операционная система Fedora 20 x86_64
opensc-0.13.0-11.fc20.x86_64
pkcs11-helper-1.10-2.fc20.x86_64
pcsc-tools-1.4.17-8.fc20.x86_64
pcsc-lite-ccid-1.4.13-1.fc20.x86_64
pcsc-lite-libs-1.8.10-2.fc20.x86_64
pcsc-perl-1.4.12-8.fc20.x86_64
pcsc-lite-1.8.10-2.fc20.x86_64
openssl-libs-1.0.1e-39.fc20.x86_64
openssl-1.0.1e-39.fc20.x86_64
librtpkcs11ecp-1.1.5-1.x86_64