<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Форум Рутокен &mdash; rtengine и ENGINE_load_private_key]]></title>
	<link rel="self" href="https://forum.rutoken.ru/feed/atom/topic/2890/" />
	<updated>2018-12-03T07:39:50Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.rutoken.ru/topic/2890/</id>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12365/#p12365" />
			<content type="html"><![CDATA[<p>Добрый день, <strong>RV</strong>.</p><p>По PIN-коду уточнил у разработчиков. Раньше такая возможность была, но сейчас PIN можно передать только через PKCS#11. Причина - engine не умеет корректно работать с PIN-кодами в многопоточном режиме.</p>]]></content>
			<author>
				<name><![CDATA[Владимир Салыкин]]></name>
				<uri>https://forum.rutoken.ru/user/10195/</uri>
			</author>
			<updated>2018-12-03T07:39:50Z</updated>
			<id>https://forum.rutoken.ru/post/12365/#p12365</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12356/#p12356" />
			<content type="html"><![CDATA[<p>Добрый день, <strong>RV</strong>.</p><p>Никаких проблем с юридической точки зрения с распространением наших библиотек. Главное их не модифицировать, а распространять как есть. В идеале конечно, чтобы пользователь ставил сам последнюю версию библиотеки, благо они всегда доступны на нашем сайте.</p><p>&quot;При том, что они были в openssl.cnf &quot; - тут помочь ничем не могу. Это поведение openssl.</p><p>Можно ли как-то rtengine передать pin? - уточню у разработчиков.</p>]]></content>
			<author>
				<name><![CDATA[Владимир Салыкин]]></name>
				<uri>https://forum.rutoken.ru/user/10195/</uri>
			</author>
			<updated>2018-11-29T11:24:38Z</updated>
			<id>https://forum.rutoken.ru/post/12356/#p12356</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12354/#p12354" />
			<content type="html"><![CDATA[<p>Нашел в чем проблема.<br />Не хватало этих двух строчек<br />&nbsp; &nbsp; ENGINE_ctrl_cmd_string(e, &quot;dynamic_path&quot;, &quot;/usr/lib/x86_64-linux-gnu/engines-1.1/librtengine.so&quot;, 0);<br />&nbsp; &nbsp; ENGINE_ctrl_cmd_string(e, &quot;MODULE_PATH&quot;, &quot;/usr/lib/librtpkcs11ecp.so&quot;, 0);</p><p>При том, что они были в openssl.cnf: <br />dynamic_path=/usr/lib/x86_64-linux-gnu/engines-1.1/librtengine.so<br />MODULE_PATH=/usr/lib/librtpkcs11ecp.so</p><p>И еще вопрос появился. Можно ли как-то rtengine передать pin?<br />Пробовал по разному, все равно спрашивает.</p><p>#include &lt;stdio.h&gt;<br />#include &lt;openssl/engine.h&gt;</p><p>typedef struct pw_cb_data {<br />&nbsp; &nbsp; const void *password;<br />&nbsp; &nbsp; const char *prompt_info;<br />}PW_CB_DATA;</p><p>int main()<br />{<br />&nbsp; &nbsp; int r;<br />&nbsp; &nbsp; ENGINE *e;<br />&nbsp; &nbsp; EVP_PKEY * key;</p><p>&nbsp; &nbsp; PW_CB_DATA cb;<br />&nbsp; &nbsp; cb.password = &quot;12345678&quot;;<br />&nbsp; &nbsp; cb.prompt_info = &quot;pkcs11:id=3135&quot;;</p><p>&nbsp; &nbsp; ENGINE_load_builtin_engines();<br />&nbsp; &nbsp; ENGINE_load_dynamic();</p><p>&nbsp; &nbsp; e = ENGINE_by_id(&quot;rtengine&quot;);<br />&nbsp; &nbsp; if (!e){<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Can&#039;t find engine: %s\n&quot;, ERR_reason_error_string(ERR_get_error()));<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; ENGINE_ctrl_cmd_string(e, &quot;dynamic_path&quot;, &quot;/usr/lib/x86_64-linux-gnu/engines-1.1/librtengine.so&quot;, 0);<br />&nbsp; &nbsp; ENGINE_ctrl_cmd_string(e, &quot;MODULE_PATH&quot;, &quot;/usr/lib/librtpkcs11ecp.so&quot;, 0);<br />&nbsp; &nbsp; ENGINE_ctrl_cmd_string(e, &quot;PIN&quot;, &quot;12345678&quot;, 0);</p><p>&nbsp; &nbsp; if (!ENGINE_init(e)){<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine initialization failed!\n&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; ENGINE_free(e);<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; if (ENGINE_set_default(e, ENGINE_METHOD_ALL)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine %s(%s): Activated.\n&quot;, ENGINE_get_name(e), ENGINE_get_id(e));<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine %s(%s): Initialized but not usable.\n&quot;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENGINE_get_name(e), ENGINE_get_id(e));<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; key = ENGINE_load_private_key(e, &quot;pkcs11:id=3135&quot;, UI_OpenSSL(), &amp;cb);</p><p>&nbsp; &nbsp; printf(&quot;key = %x\n&quot;, key);</p><p>&nbsp; &nbsp; return 0;<br />}</p>]]></content>
			<author>
				<name><![CDATA[RV]]></name>
				<uri>https://forum.rutoken.ru/user/10972/</uri>
			</author>
			<updated>2018-11-29T01:49:25Z</updated>
			<id>https://forum.rutoken.ru/post/12354/#p12354</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12353/#p12353" />
			<content type="html"><![CDATA[<p>Здравствуйте, Владимир.</p><p>В примерах из SDK ключ считывается функцией get_key_pair(), которая обращается к getHardwareKeyPair(), которая в свою очередь работает с токеном через pkcs11.</p><p>Линковка не устраивает так как требуется опциональное присутствие в системе библиотеки librtpkcs11ecp и rtengine, как и поддержка Рутокен вообще. Также не хотелось бы усложнять код dlopen и pkcs11 протоколом.<br />Работа через интерфейс OpenSSL была бы решением.</p><p>Кстати говоря, возник юридический вопрос. На каких условиях могут распространяться эти библиотеки в стороннем софте?</p><p>Что касается ENGINE_load_private_key(), судя по ltrace openssl, вообще она работает. Подозреваю что неправильно подготовил UI_OpenSSL.</p>]]></content>
			<author>
				<name><![CDATA[RV]]></name>
				<uri>https://forum.rutoken.ru/user/10972/</uri>
			</author>
			<updated>2018-11-28T23:01:33Z</updated>
			<id>https://forum.rutoken.ru/post/12353/#p12353</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12347/#p12347" />
			<content type="html"><![CDATA[<p>Добрый день, <strong>RV</strong>.</p><p>Примеры из SDK по работе с engine (в частности, sdk\openssl\rtengine\samples\SignCMS) показывают как работать с нашим токеном с интерфейсом OpenSSL. Смотрите в них.</p><p>Не уловил, чем Вас смущает линковка. Engine все равно пойдет к токену через pkcs11 и его никак не обойти.</p>]]></content>
			<author>
				<name><![CDATA[Владимир Салыкин]]></name>
				<uri>https://forum.rutoken.ru/user/10195/</uri>
			</author>
			<updated>2018-11-28T07:39:00Z</updated>
			<id>https://forum.rutoken.ru/post/12347/#p12347</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12345/#p12345" />
			<content type="html"><![CDATA[<p>Чвсть ltrace openssl dgst -engine rtengine -sign &#039;pkcs11:id=3135&#039; -keyform engine file &gt; sig</p><p>BIO_s_file(0, 2046, 7, 1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x7f3edc426c60<br />BIO_new(0x7f3edc426c60, 2046, 7, 1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x561b9ebe8200<br />BIO_f_md(0x561b9ebe8200, 0, 0x561b9ebe8280, 0)&nbsp; &nbsp;= 0x7f3edc429380<br />BIO_new(0x7f3edc429380, 0, 0x561b9ebe8280, 0)&nbsp; &nbsp; = 0x561b9ebe82c0<br />BIO_new_fp(0x7f3edbb9b600, 0, 0, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x561b9ebe83c0<br />ENGINE_init(0x561b9ebdd6d0, 8, 0, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1<br />ENGINE_load_private_key(0x561b9ebdd6d0, 0x7ffe9c79d572, 0x561b9ebe7a10, 0x7ffe9c79c070 &lt;unfinished ...&gt;<br />UI_OpenSSL(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0) = 0x7f3edc44ef80<br />UI_method_get_opener(0x7f3edc44ef80, 0x561b9ebe86c0, 0, 0) = 0x7f3edc186650<br />UI_get_input_flags(0x561b9ebe86c0, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 2<br />UI_get0_user_data(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7ffe9c79c070<br />UI_get_string_type(0x561b9ebe86c0, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 1<br />UI_get0_user_data(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7ffe9c79c070<br />UI_OpenSSL(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7f3edc44ef80<br />UI_method_get_writer(0x7f3edc44ef80, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7f3edc186070<br />UI_get_input_flags(0x561b9ebe86c0, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 2<br />UI_get0_user_data(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7ffe9c79c070<br />UI_get_string_type(0x561b9ebe86c0, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 1<br />UI_get0_user_data(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7ffe9c79c070<br />UI_OpenSSL(0x561b9ebe8640, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7f3edc44ef80<br />UI_method_get_reader(0x7f3edc44ef80, 0x561b9ebe86c0, 0, 0x7f3edb8e15ca) = 0x7f3edc1864b0<br />UI_OpenSSL(0x561b9ebe8640, 0, 0, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x7f3edc44ef80<br />UI_method_get_closer(0x7f3edc44ef80, 0, 0, 0)&nbsp; &nbsp; = 0x7f3edc186020<br />&lt;... ENGINE_load_private_key resumed&gt; )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x561b9eca68d0<br />ENGINE_finish(0x561b9ebdd6d0, 0xffffffff, 0x7ffe9c79bf1c, 0x561b9ebe85c0) = 1<br />BIO_free(0, 0, 0x561b9ebd3530, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0<br />BIO_ctrl(0x561b9ebe82c0, 120, 0, 0x7ffe9c79c158) = 1<br />EVP_DigestSignInit(0x561b9ebe8380, 0x7ffe9c79c160, 0, 0) = 1<br />BIO_push(0x561b9ebe82c0, 0x561b9ebe8200, 0x101010101010101, 0) = 0x561b9ebe82c0<br />BIO_ctrl(0x561b9ebe82c0, 120, 0, 0x7ffe9c79c160) = 1<br />EVP_MD_CTX_md(0x561b9ebe8380, 1, 0, 0x7ffe9c79c160) = 0x561b9ec96af0<br />BIO_ctrl(0x561b9ebe8200, 108, 3, 0x7ffe9c79d591) = 1<br />BIO_read(0x561b9ebe82c0, 0x561b9ebe9700, 8192, 0) = 26<br />BIO_read(0x561b9ebe82c0, 0x561b9ebe9700, 8192, 0) = 0<br />BIO_ctrl(0x561b9ebe82c0, 120, 0, 0x7ffe9c79c030) = 1<br />EVP_DigestSignFinal(0x561b9ebe8380, 0x561b9ebe9700, 0x7ffe9c79c028, 0x7ffe9c79c030) = 1</p>]]></content>
			<author>
				<name><![CDATA[RV]]></name>
				<uri>https://forum.rutoken.ru/user/10972/</uri>
			</author>
			<updated>2018-11-27T19:06:58Z</updated>
			<id>https://forum.rutoken.ru/post/12345/#p12345</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12344/#p12344" />
			<content type="html"><![CDATA[<p>[ 3224.865515] test[2954]: segfault at 28 ip 00007fee5468c098 sp 00007ffd7d083d40 error 4 in librtengine.so[7fee54683000+30000]</p>]]></content>
			<author>
				<name><![CDATA[RV]]></name>
				<uri>https://forum.rutoken.ru/user/10972/</uri>
			</author>
			<updated>2018-11-27T19:03:06Z</updated>
			<id>https://forum.rutoken.ru/post/12344/#p12344</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[rtengine и ENGINE_load_private_key]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/12343/#p12343" />
			<content type="html"><![CDATA[<p>Здравствуйте.</p><p>Использую Рутокен ЭЦП, Linux, OpenSSL 1.1.0.</p><p>Подпись на Рутокен работает:</p><p>$ openssl dgst -engine rtengine -sign &#039;pkcs11:id=3135&#039; -keyform engine file &gt; sig</p><p>Я хочу получить аналогичный результат в коде на C. Примеры, которые поставляются с&nbsp; rtengine мне не подходят, так как они используют pkcs11 интерфейс и требуют линковки с вашей библиотекой pkcs11.<br />Мне требуется код, который взаимодействует через интерфейс OpenSSL.</p><p>Пытаюсь запустить тест по аналогии с </p><p><a href="https://stackoverflow.com/questions/40676573/how-to-reload-key-from-hsm-by-using-openssl">https://stackoverflow.com/questions/406 … ng-openssl</a></p><p>#include &lt;stdio.h&gt;<br />#include &lt;openssl/engine.h&gt;</p><p>typedef struct pw_cb_data {<br />&nbsp; &nbsp; const void *password;<br />&nbsp; &nbsp; const char *prompt_info;<br />}PW_CB_DATA;</p><p>int main()<br />{<br />&nbsp; &nbsp; int r;</p><p>&nbsp; &nbsp; ENGINE *e;<br />&nbsp; &nbsp; EVP_PKEY * key;</p><p>&nbsp; &nbsp; PW_CB_DATA cb;<br />&nbsp; &nbsp; cb.password = &quot;12345678&quot;;<br />&nbsp; &nbsp; cb.prompt_info = &quot;pkcs11:id=3135&quot;;</p><p>&nbsp; &nbsp; ENGINE_load_builtin_engines();<br />&nbsp; &nbsp; ENGINE_load_dynamic();</p><p>&nbsp; &nbsp; e = ENGINE_by_id(&quot;rtengine&quot;);<br />&nbsp; &nbsp; if (!e){<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Can&#039;t find engine: %s\n&quot;, ERR_reason_error_string(ERR_get_error()));<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; if (!ENGINE_init(e)){<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine initialization failed!\n&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; ENGINE_free(e);<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; if (ENGINE_set_default(e, ENGINE_METHOD_ALL)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine %s(%s): Activated.\n&quot;, ENGINE_get_name(e), ENGINE_get_id(e));<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Engine %s(%s): Initialized but not usable.\n&quot;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENGINE_get_name(e), ENGINE_get_id(e));<br />&nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; OpenSSL_add_all_algorithms();</p><br /><p>&nbsp; &nbsp; key = ENGINE_load_private_key(e, &quot;pkcs11:id=3135&quot;, UI_OpenSSL(), &amp;cb);<br />&nbsp; &nbsp; printf(&quot;key = %x\n&quot;, key);</p><p>&nbsp; &nbsp; return 0;<br />}</p><br /><p>$ ./test<br />Engine Rutoken engine(rtengine): Activated.<br />Segmentation fault<br />$</p><p>Код падает на ENGINE_load_private_key()<br />ltrace:</p><p>ENGINE_load_builtin_engines(1, 0x7ffc0d5d1578, 0x7ffc0d5d1588, 0) = 1<br />OPENSSL_init_crypto(1024, 0, 0x7ffc0d5d13f4, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1<br />ENGINE_by_id(0x56398512bd60, 0xffffffff, 0x7ffc0d5d13f4, 0)&nbsp; = 0x563986e58560<br />ENGINE_init(0x563986e58560, 0, 0x563986e46050, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1<br />ENGINE_set_default(0x563986e58560, 0xffff, 0x563986e46050, 0) = 1<br />ENGINE_get_id(0x563986e58560, 0, 0x563986e46050, 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0x7f05af205d93<br />ENGINE_get_name(0x563986e58560, 0, 0x563986e46050, 0)&nbsp; &nbsp; &nbsp; &nbsp; = 0x7f05af205d9c<br />printf(&quot;Engine %s(%s): Activated.\n&quot;, &quot;Rutoken engine&quot;, &quot;rtengine&quot;) = 44<br />OPENSSL_init_crypto(12, 0, 0x7f05afbd4760, 0x7fffffe1)&nbsp; &nbsp; &nbsp; &nbsp;= 1<br />UI_OpenSSL(0x7f05b0069314, 129, 0x7fffffff, 0x7f05af426760)&nbsp; = 0x7f05b0065f80<br />ENGINE_load_private_key(0x563986e58560, 0x56398512bd51, 0x7f05b0065f80, 0x7ffc0d5d1460 &lt;no return ...&gt;<br />--- SIGSEGV (Segmentation fault) ---<br />+++ killed by SIGSEGV +++</p>]]></content>
			<author>
				<name><![CDATA[RV]]></name>
				<uri>https://forum.rutoken.ru/user/10972/</uri>
			</author>
			<updated>2018-11-27T15:57:32Z</updated>
			<id>https://forum.rutoken.ru/post/12343/#p12343</id>
		</entry>
</feed>
