<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Форум Рутокен &mdash; rt_eng_new_p11_ossl_evp_pkey]]></title>
		<link>https://forum.rutoken.ru/topic/3269/</link>
		<atom:link href="https://forum.rutoken.ru/feed/rss/topic/3269/" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «rt_eng_new_p11_ossl_evp_pkey».]]></description>
		<lastBuildDate>Wed, 28 Oct 2020 05:20:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: rt_eng_new_p11_ossl_evp_pkey]]></title>
			<link>https://forum.rutoken.ru/post/14985/#p14985</link>
			<description><![CDATA[<p>Действительно использовал сертификат вместо публичного ключа...<br />Спасибо!</p>]]></description>
			<author><![CDATA[null@example.com (iWeaver)]]></author>
			<pubDate>Wed, 28 Oct 2020 05:20:40 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/14985/#p14985</guid>
		</item>
		<item>
			<title><![CDATA[Re: rt_eng_new_p11_ossl_evp_pkey]]></title>
			<link>https://forum.rutoken.ru/post/14984/#p14984</link>
			<description><![CDATA[<p><strong>iWeaver</strong>, в функцию должны передаваться хендлы ключевой пары:<br /></p><div class="codebox"><pre><code> evpPKey = rt_eng_new_p11_ossl_evp_pkey(wrappedSession, privateKey, publicKey);</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Павел Анфимов)]]></author>
			<pubDate>Tue, 27 Oct 2020 17:21:25 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/14984/#p14984</guid>
		</item>
		<item>
			<title><![CDATA[Re: rt_eng_new_p11_ossl_evp_pkey]]></title>
			<link>https://forum.rutoken.ru/post/14983/#p14983</link>
			<description><![CDATA[<p>Основа на примере<br /><a href="https://github.com/AktivCo/rutoken-demobank-ios/blob/master/Token.m">https://github.com/AktivCo/rutoken-demo … er/Token.m</a></p><p>Инициализация<br />&nbsp; &nbsp; CK_RV rv = rt_eng_init();<br />&nbsp; &nbsp; if (rv != 1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:0 fromFunction:@&quot;rt_eng_init&quot;];<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; ENGINE* rtEngine = rt_eng_get0_engine();<br />&nbsp; &nbsp; self.rtEngine = rtEngine;<br />&nbsp; &nbsp; if (rtEngine == nil) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:0 fromFunction:@&quot;rt_eng_get0_engine&quot;];<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; rv = ENGINE_set_default(rtEngine, ENGINE_METHOD_ALL - ENGINE_METHOD_RAND);<br />&nbsp; &nbsp; if (rv != 1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:0 fromFunction:@&quot;ENGINE_set_default&quot;];<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; rv = C_GetFunctionList(&amp;_functions);<br />&nbsp; &nbsp; if (CKR_OK != rv) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_GetFunctionList&quot;];<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; CK_C_INITIALIZE_ARGS args = {};<br />&nbsp; &nbsp; args.CreateMutex = NULL_PTR;<br />&nbsp; &nbsp; args.DestroyMutex = NULL_PTR;<br />&nbsp; &nbsp; args.LockMutex = NULL_PTR;<br />&nbsp; &nbsp; args.UnlockMutex = NULL_PTR;<br />&nbsp; &nbsp; args.pReserved = NULL_PTR;<br />&nbsp; &nbsp; args.flags = CKF_OS_LOCKING_OK;<br />&nbsp; &nbsp; rv = self.functions-&gt;C_Initialize(&amp;args);<br />&nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_Initialize&quot;];<br />&nbsp; &nbsp; }</p><br /><p>получение handle по id</p><p>- (void)findCertificate:(CK_SESSION_HANDLE)session certId:(NSData *)certId certificate:(CK_OBJECT_HANDLE_PTR)certificate key:(CK_OBJECT_HANDLE_PTR)key {<br />&nbsp; &nbsp; CK_RV rv = CKR_OK;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; // класс сертификата<br />&nbsp; &nbsp; CK_ULONG certClass = CKO_CERTIFICATE;</p><p>&nbsp; &nbsp; CK_CHAR_PTR attrCertId = 0;<br />&nbsp; &nbsp; NSUInteger attrCertIdSize = 0;<br />&nbsp; &nbsp; if (certId != NULL) {<br />&nbsp; &nbsp; &nbsp; &nbsp; attrCertId = (unsigned char *)certId.bytes;<br />&nbsp; &nbsp; &nbsp; &nbsp; attrCertIdSize = certId.length;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; // атрибуты для поиска сертификатов<br />&nbsp; &nbsp; CK_ATTRIBUTE certAttribs[] = {<br />&nbsp; &nbsp; &nbsp; &nbsp; {CKA_CLASS, &amp;certClass, sizeof(certClass)},<br />&nbsp; &nbsp; &nbsp; &nbsp; {CKA_ID, attrCertId, attrCertIdSize}<br />&nbsp; &nbsp; };</p><p>&nbsp; &nbsp; *certificate = [self findObj:session attributes:certAttribs attributesCount:sizeof(certAttribs)/sizeof(CK_ATTRIBUTE)];<br />&nbsp; &nbsp; if (*certificate == CK_INVALID_HANDLE) {<br />&nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; if (key == nil) {<br />&nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; certClass = CKO_PRIVATE_KEY;<br />&nbsp; &nbsp; *key = [self findObj:session attributes:certAttribs attributesCount:sizeof(certAttribs)/sizeof(CK_ATTRIBUTE)];<br />}</p><p>- (CK_OBJECT_HANDLE)findObj:(CK_SESSION_HANDLE)session attributes:(CK_ATTRIBUTE*)attributes attributesCount:(CK_ULONG)attributesCount {<br />&nbsp; &nbsp; CK_OBJECT_HANDLE result = CK_INVALID_HANDLE;<br />&nbsp; &nbsp; CK_RV rv = CKR_OK;</p><p>&nbsp; &nbsp; rv = self.functions-&gt;C_FindObjectsInit(session, attributes, attributesCount);<br />&nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_FindObjectsInit&quot;];<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; // массив хендлов сертификатов<br />&nbsp; &nbsp; &nbsp; &nbsp; CK_OBJECT_HANDLE certificates[1];<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // количество найденых сертификатов<br />&nbsp; &nbsp; &nbsp; &nbsp; CK_ULONG certsCount = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // поиск сертификатов<br />&nbsp; &nbsp; &nbsp; &nbsp; rv = self.functions-&gt;C_FindObjects(session, certificates, 1, &amp;certsCount);<br />&nbsp; &nbsp; &nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_FindObjects&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; if (certsCount != 0) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CK_OBJECT_HANDLE certHandle = certificates[0];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = certHandle;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // завершение операции поиска<br />&nbsp; &nbsp; &nbsp; &nbsp; rv = self.functions-&gt;C_FindObjectsFinal(session);<br />&nbsp; &nbsp; &nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_FindObjectsFinal&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; return result;<br />}</p><br /><p>подключение поиск хендлов</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rv = self.functions-&gt;C_OpenSession(slotID, (CKF_SERIAL_SESSION | CKF_RW_SESSION), nil, nil, &amp;session);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_OpenSession&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *pin = [signingParams.pinCode copy];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pin == nil)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pin = @&quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // подключение к токену с ПИН-кодом<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rv = self.functions-&gt;C_Login(session, CKU_USER, (CK_CHAR_PTR)[pin UTF8String], [pin length]);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rv != CKR_OK) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rv == CKR_PIN_LOCKED) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [NSException raise:@&quot;E_PIN_LOCKED&quot; format:@&quot;Пин заблокирован&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rv == CKR_PIN_INVALID || rv == CKR_PIN_INCORRECT || rv == CKR_ARGUMENTS_BAD || rv == CKR_PIN_LEN_RANGE) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [NSException raise:@&quot;E_PIN_ERROR&quot; format:@&quot;Не верный пин код, установите пин код в настройках приложения&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;C_Login&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Дескриптор сертификата и ключа<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CK_OBJECT_HANDLE certificateHandle = CK_INVALID_HANDLE;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CK_OBJECT_HANDLE keyHandle = CK_INVALID_HANDLE;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [self findCertificate:session certId:signingParams.signerInfo.signerCertificate.certificateId certificate:&amp;certificateHandle key:&amp;keyHandle];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&quot;certificateHandle: %ld&quot;, certificateHandle);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&quot;keyHandle: %ld&quot;, keyHandle);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wrappedSession = rt_eng_p11_session_new(self.functions, session, 0, NULL);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!wrappedSession.self) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ACPKCS11Exception raiseWithPKCS11ErrorCode:rv fromFunction:@&quot;rt_eng_p11_session_new&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; evpPKey = rt_eng_new_p11_ossl_evp_pkey(wrappedSession, keyHandle, certificateHandle);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RT_ENG_CALL(wrappedSession, free);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; evpPKey = NULL</p><p>сертификаты просроченные, может это является проблемой получения EVP_PKEY?</p>]]></description>
			<author><![CDATA[null@example.com (iWeaver)]]></author>
			<pubDate>Tue, 27 Oct 2020 13:39:52 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/14983/#p14983</guid>
		</item>
		<item>
			<title><![CDATA[Re: rt_eng_new_p11_ossl_evp_pkey]]></title>
			<link>https://forum.rutoken.ru/post/14982/#p14982</link>
			<description><![CDATA[<p><strong>iWeaver</strong>, добрый день!</p><p>Расскажите, пожалуйста: как вы проинициализировали rtengine, какие параметры вы передаете и как их получили.<br />Возможно вы опирались на наш пример, если да - то на какой?</p>]]></description>
			<author><![CDATA[null@example.com (Павел Анфимов)]]></author>
			<pubDate>Tue, 27 Oct 2020 10:50:38 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/14982/#p14982</guid>
		</item>
		<item>
			<title><![CDATA[rt_eng_new_p11_ossl_evp_pkey]]></title>
			<link>https://forum.rutoken.ru/post/14981/#p14981</link>
			<description><![CDATA[<p>По какой причине может не работать данная функция?<br />wrappedSession, keyHandle, certificateHandle все параметры проинициализированы.</p><p>При использовании keyHandle, certificateHandle в функции C_EX_PKCS7Sign все отрабатывает нормально.</p><p>Можно ли как-то включить логированние в ios приложении, чтобы выяснить причину?</p><p>IOS 14.1<br />SDK 140920</p>]]></description>
			<author><![CDATA[null@example.com (iWeaver)]]></author>
			<pubDate>Tue, 27 Oct 2020 09:14:28 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/14981/#p14981</guid>
		</item>
	</channel>
</rss>
