<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — PKCS11 callback for hardware]]></title>
		<link>https://www.wolfssl.com/forums/topic1688-pkcs11-callback-for-hardware.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1688.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in PKCS11 callback for hardware.]]></description>
		<lastBuildDate>Fri, 19 Mar 2021 02:39:02 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5898.html#p5898</link>
			<description><![CDATA[<p>Hi Sean,</p><p>Yes you are right:<br />Pkcs11EcKeyGen() is calling Pkcs11GetEccPublicKey() and Pkcs11GetEccPublicKey() return 0, which mean everything is okay with the PKCS11 but when I try to print the key it is failing. It is like the key is in the structure but there is no way i can double check if the public key is correct.</p><p>In order to check if the public key is okay I do two things:<br />1. call:&nbsp; wc_ecc_check_key(key) which returns MP_OKAY<br />2. print the public key with:<br /></p><div class="codebox"><pre><code> word32 buffSz = 67;
  byte  der[buffSz];
 XMEMSET(der, 0, sizeof(der));
 wc_EccKeyToDer(key, der, buffSz); </code></pre></div><p>which return -173 </p><p>BAD_FUNC_ARG&nbsp; &nbsp; &nbsp; &nbsp;= -173,&nbsp; /* Bad function argument provided */</p><p>The function: <br /></p><div class="codebox"><pre><code>int wc_EccKeyToDer(ecc_key* key, byte* output, word32 inLen)</code></pre></div><p>calls:<br /></p><div class="codebox"><pre><code> static int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 inLen,
                             int pubIn)
{
 if (key == NULL || output == NULL || inLen == 0)
        return BAD_FUNC_ARG;
....
}</code></pre></div><p>Does it means my key actually null? it does not make sense, the wc_ecc_check_key(key) return MP_OKAY.</p><p>Anyway, </p><p>After enabling the PKCS11_DEBUG inside:<br />static int Pkcs11EcKeyGen(Pkcs11Session* session, wc_CryptoInfo* info)</p><p>C_OpenSession: OK<br />C_Login: OK<br />C_GenerateKeyPair: OK<br />C_GetAttributeValue: OK<br />C_GetAttributeValue: OK</p><p>Ec Public Key<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CKA_EC_POINT: 67<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x04,0x41,0x04,0xea,0x6a,0x08,0xad,0xa2,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xca,0x5b,0x15,0xbe,0x03,0xe8,0x05,0x89,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xc4,0xec,0x0f,0x03,0x35,0x71,0x71,0x8f,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x54,0x31,0xc0,0xfc,0x21,0x95,0x44,0x32,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xaa,0xab,0x19,0x43,0x6e,0x17,0x7f,0x8d,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x53,0x4d,0x6a,0x71,0x25,0x78,0x17,0x6f,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x12,0xd0,0xd8,0x0a,0xa4,0xad,0xf2,0x54,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x86,0x53,0x64,0x36,0xca,0x95,0x2c,0x7f,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x71,0x65,0x81,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CKA_EC_PARAMS: 10<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x01,0x07,</p><p> I am getting: <br />wolfSSL Leaving SendClientKeyExchange, return -354<br />wolfSSL error occurred, error = -354</p><p>&nbsp; ECC_EXPORT_ERROR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= -354,&nbsp; &nbsp;/* Bad ECC Export Key */</p><br /><br /><br /><p>Thanks for your help<br />Remy</p>]]></description>
			<author><![CDATA[null@example.com (saksikremy)]]></author>
			<pubDate>Fri, 19 Mar 2021 02:39:02 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5898.html#p5898</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5896.html#p5896</link>
			<description><![CDATA[<p>Hi Remy,</p><p>I&#039;m not sure what&#039;s going wrong here.<br />The function Pkcs11EcKeyGen() is calling Pkcs11GetEccPublicKey() which will fail when the key doesn&#039;t load.<br />Does your version of wc_pkcs11.c have this call sequence?</p><p>Note: WOLFSSL_DEBUG_PKCS11 will show more debug information about the PKCS #11 calls.</p><p>Thanks,<br />Sean Parkinson, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (Sean Parkinson)]]></author>
			<pubDate>Thu, 18 Mar 2021 23:02:24 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5896.html#p5896</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5892.html#p5892</link>
			<description><![CDATA[<p>Hi Remy,</p><p>Is it possible you need to call `int wc_ecc_make_pub_ex(ecc_key* key, ecc_point* pubOut, WC_RNG* rng)` first to generate the public key material? </p><p>I&#039;ve also asked our PKCS11 expert Sean P to review this post.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Thu, 18 Mar 2021 16:05:59 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5892.html#p5892</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5875.html#p5875</link>
			<description><![CDATA[<p>Hi,</p><p>Sorry for the late reply, I could not login to the forum.<br />Thank you for your previous answer. I could generate the secret as long as I fallback of the software implementation to generate the key pair.</p><p>But my purpose is to generate the key pair with my token (Can do) and use the generated public key to create the secret (cannot do). </p><p>I manage to use my token to generate the key pair, but it is not possible for me to re-inject the public key into the SSL context after the callback. I am stuck on this for a few weeks...</p><p>entry point: cryptocb.c<br />the key has been initialized but empty in order to let the token generate the public key in the &quot;key&quot; structure. <br /></p><div class="codebox"><pre><code>#ifdef HAVE_ECC
int wc_CryptoCb_MakeEccKey(WC_RNG* rng, int keySize, ecc_key* key, int curveId)
{
    printf(&quot;\n wc crypto Make ecc key. keySize= %d  \n&quot;, keySize);
    int ret = CRYPTOCB_UNAVAILABLE;
    CryptoCb* dev;

    if (key == NULL)
        return ret;

    /* locate registered callback */
    dev = wc_CryptoCb_FindDevice(key-&gt;devId);
    if (dev &amp;&amp; dev-&gt;cb) {
        wc_CryptoInfo cryptoInfo;
        XMEMSET(&amp;cryptoInfo, 0, sizeof(cryptoInfo));
        cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
        cryptoInfo.pk.type = WC_PK_TYPE_EC_KEYGEN;
        cryptoInfo.pk.eckg.rng = rng;
        cryptoInfo.pk.eckg.size = keySize;
        cryptoInfo.pk.eckg.key = key;
        cryptoInfo.pk.eckg.curveId = curveId;

        ret = dev-&gt;cb(dev-&gt;devId, &amp;cryptoInfo, dev-&gt;ctx);

          printf(&quot;\n INSIDE THE CALLBACK....  \n&quot;);

         #define FOURK_BUF 4096
            byte  der[FOURK_BUF];
            int derSz = 0;

            derSz = wc_EccKeyToDer(key, der, FOURK_BUF);
            int i;
            for (i = 0; i &lt;= derSz;i++){
                printf(&quot;%02x:&quot;, der[i]);
                if (((i+1)%16)==0){
                    printf(&quot;\n&quot;);
                }
            }
            printf(&quot;\n&quot;);
    }

    return wc_CryptoCb_TranslateErrorCode(ret);
}</code></pre></div><p>in my pkcs11 interface the following code allows me to generate the CKA-points for the public key:</p><div class="codebox"><pre><code>static int Pkcs11EcKeyGen(Pkcs11Session* session, wc_CryptoInfo* info)
{
    int               ret = 0;
    ecc_key*          key = info-&gt;pk.eckg.key;

...

rv = session-&gt;func-&gt;C_GenerateKeyPair(session-&gt;handle, &amp;mech,
                                                       pubKeyTmpl, pubTmplCnt,
                                                       privKeyTmpl, privTmplCnt,
                                                       &amp;pubKey, &amp;privKey);

...
Pkcs11GetEccPublicKey(key, session, pubKey);
pkcs11_dump_template(pubKeyTmpl, pubTmplCnt); </code></pre></div><p>Ecc Public Key<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CKA_EC_POINT: 67<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x04,0x41,0x04,0x80,0xf6,0x67,0x7a,0x5b,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xac,0x31,0x25,0xf8,0x2e,0xa7,0xc8,0x32,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x12,0xf9,0xad,0xd9,0x33,0x01,0x6d,0xe0,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x17,0x50,0xcb,0x2d,0x36,0xb1,0x28,0xf6,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x32,0x2a,0xf0,0x55,0x75,0x6e,0xe3,0xc9,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xff,0x7f,0xf4,0x0f,0xe2,0xce,0x4c,0x35,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0xbd,0x30,0x92,0x47,0x86,0x0f,0xc3,0x25,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x3f,0xaa,0xeb,0x1c,0xb4,0x58,0x98,0x9a,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x5e,0x02,0x1a,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CKA_EC_PARAMS: 10<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x01,0x07,</p><p>from here, the key structure must have the public key. I can print the public key CKA points just nice as expected.</p><br /><p>When this function ends I am going back to the callback (first sample of the code above.)</p><p>And then I try to display the public key after the printf : printf(&quot;\n INSIDE THE CALLBACK....&nbsp; \n&quot;);<br />But i always get error -173 =&gt;&nbsp; &nbsp; &nbsp;BAD_FUNC_ARG&nbsp; &nbsp; &nbsp; &nbsp;= -173,&nbsp; /* Bad function argument provided */</p><p>INSIDE THE CALLBACK....<br />00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:<br />00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:<br />00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:<br />00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:<br />00:00:00:</p><p>So I believe the public key is not getting updated in the &#039;ecc_key&#039; structure. it is quite hard to debug.</p><p>inside the Pkcs11 implementation i have tried to:</p><p>-check the &quot;ecc_key key&quot; with:<br /></p><div class="codebox"><pre><code>check_result = wc_ecc_check_key(key);</code></pre></div><p>-&gt; success<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p><p>- Copy the point from the template that display the CKA points to the &quot;ecc_key key&quot; structure.</p><div class="codebox"><pre><code>point = wc_ecc_new_point();
int copy_return = wc_ecc_copy_point(&amp;key-&gt;pubkey,  &amp;info-&gt;pk.eckg.key-&gt;pubkey);</code></pre></div><p>-&gt; success.</p><p>- Compare the CKA points inside the &quot;ecc_key key&quot; with:<br /></p><div class="codebox"><pre><code> int cmp_result = wc_ecc_cmp_point(&amp;key-&gt;pubkey, &amp;info-&gt;pk.eckg.key-&gt;pubkey);</code></pre></div><p>-&gt; success</p><p>- Export the points into byte array to print them with:<br /></p><div class="codebox"><pre><code>       word32 buffSz = 64;
        byte  der[buffSz];
        XMEMSET(der, 0, sizeof(der));
        wc_ecc_export_point_der(key-&gt;dp-&gt;id, &amp;key-&gt;pubkey, der,  &amp;buffSz);</code></pre></div><p>-&gt;&nbsp; not successful</p><br /><br /><p>I am short of idea, I am not sure where the keys goes and in which format the key is represented.</p><br /><p>Any help would highly appreciated.</p>]]></description>
			<author><![CDATA[null@example.com (saksikremy)]]></author>
			<pubDate>Wed, 17 Mar 2021 02:43:40 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5875.html#p5875</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5828.html#p5828</link>
			<description><![CDATA[<p>Hi Remy,</p><p>No, I do not think you need the pk callback option, but you mentioned earlier in the thread.</p><p>The `NO_ECC_KEY_EXPORT` define comes from here (because `HAVE_ECC` is defined):<br /><a href="https://github.com/wolfSSL/wolfssl/blob/4c1a94a6ad5c704501e32e2f45ea35b3a3d553b0/wolfssl/wolfcrypt/settings.h#L1821">https://github.com/wolfSSL/wolfssl/blob … gs.h#L1821</a></p><p>The public key is exported to the `ssl-&gt;hsKey` structure in order to compute the shared secret.<br /></p><div class="codebox"><pre><code>                    ret = EccSharedSecret(ssl,
                        (ecc_key*)ssl-&gt;hsKey, ssl-&gt;peerEccKey,
                        args-&gt;output + OPAQUE8_LEN, &amp;args-&gt;length,
                        ssl-&gt;arrays-&gt;preMasterSecret + OPAQUE16_LEN,
                        &amp;ssl-&gt;arrays-&gt;preMasterSz,
                        WOLFSSL_CLIENT_END
                    );</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Fri, 26 Feb 2021 17:15:04 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5828.html#p5828</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5821.html#p5821</link>
			<description><![CDATA[<p>I have removed it because i do not do anything extra with the public key, It is just the normal process of TLS handshake. But perhaps I am wrong. I am doubtful on the callback usage...I don&#039;t want to modify the internal.c code.</p><p>At sendClientKeyExhange():<br />The process leads me to: wc_ecc_export_x963.</p><p>Why do I need to export the public key? </p><p>The GenerateKeyPair() was successful so I have the public key already.</p><p>The process is:<br />A. public key = Generate the Key pair()<br />B. Export the public key () - strange to me<br />C. Compute the share secret()</p><p>Am I wrong?</p><p>Remy</p>]]></description>
			<author><![CDATA[null@example.com (saksik.remy)]]></author>
			<pubDate>Thu, 25 Feb 2021 02:01:46 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5821.html#p5821</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5820.html#p5820</link>
			<description><![CDATA[<p>Do you still have `--enable-pk-callback` in your configure line?</p>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Wed, 24 Feb 2021 19:07:20 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5820.html#p5820</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5814.html#p5814</link>
			<description><![CDATA[<p>Great I managed to verify my Certificate.</p><p>I still have an issue tho, could someone explain a bit the SendClientKeyExhange()?</p><p>I am using ECC (ECDSA 256). But somehow in this function after generating the Public key (EccMakeKey), I end up exporting the key with&nbsp; wc_ecc_export_x963 .... Which i found really strange...I am not sure i understand this part. I am supposed to compute the DH keys...</p><p>Then i have a error ECC_EXPORT_ERROR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= -354,&nbsp; &nbsp;/* Bad ECC Export Key */<br />Which make sense to me.</p><p>Did I forgot a #Define ?? or configure the WolfSSL build with some missing options?</p><br /><p>The code below is the internal.c file, sendClientKeyExchange(...)</p><p>i have define HAVE_ECC but i never defined the ECCKEY_EXPORT and I dont not have PK_CALLBACKS.</p><p>I would appreciate some help where I go wrong...</p><p>Thanks a lot for your time<br />Remy</p><div class="codebox"><pre><code> #if defined(HAVE_ECC) &amp;&amp; defined(HAVE_ECC_KEY_EXPORT)
                #ifdef HAVE_PK_CALLBACKS
                    /* if callback then use it for shared secret */
                    if (ssl-&gt;ctx-&gt;EccSharedSecretCb != NULL) {
                        break;
                    }
                #endif
                WOLFSSL_MSG(&quot;\reach here, why?\n&quot;);
                    /* Place ECC key in buffer, leaving room for size */
                    ret = wc_ecc_export_x963((ecc_key*)ssl-&gt;hsKey,
                                args-&gt;encSecret + OPAQUE8_LEN, &amp;args-&gt;encSz);
                    if (ret != 0) {
                        ERROR_OUT(ECC_EXPORT_ERROR, exit_scke);
                    }
                #endif /* HAVE_ECC */</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (saksik.remy)]]></author>
			<pubDate>Wed, 24 Feb 2021 07:24:45 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5814.html#p5814</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5808.html#p5808</link>
			<description><![CDATA[<p>The `-K` option is expecting a path to a file.</p>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Mon, 22 Feb 2021 23:08:56 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5808.html#p5808</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5806.html#p5806</link>
			<description><![CDATA[<p>Hi all,</p><p>Thanks for your help.</p><p>i will try to return the &quot;CRYPTOCB_UNAVAILABLE&quot; and see if it is working for me.</p><p>@embhor:<br />The verify operation fails i guess because it is NULL due to the &#039;&#039;Not supported operation&quot;</p><p>@all:<br />I also got confuse between the&quot; --enable-crytocb&quot;, and the &quot;--enable-pk-callback&quot;...<br />I believe I do not need the pk-callback, because I do not want to do extra operation with the keys...But maybe this two feature are working together.</p><br /><p>For your reference I have posted the log i am getting...<br />You can see I am using the private key ID as a standard URL with &quot;%&quot; separator, I am not sure that this is supported by WolfSSL tho.</p><p>pi@raspberrypi:~/experiment/wolfMQTT-Client/wolfMQTT/examples/mqttclient $ ./mqttclient -h localhost -p 1883 -t -A ~/certs/ca.crt -c ~/certs/exportedClientCert.crt <strong> -K %AA%07%19%18%C6%16%14%FF%DF%C7%3F%12%85%24</strong><br />MQTT Client: QoS 0, Use TLS 1<br />MQTT Net Init: Success (0)<br />MQTT Init: Success (0)<br />NetConnect: Host localhost, Port 1883, Timeout 5000 ms, Use TLS 1<br />wolfSSL Entering wolfSSL_Init<br />wolfSSL Entering wolfCrypt_Init<br />wolfSSL Entering TLSv1_2_client_method_ex<br />wolfSSL Entering wolfSSL_CTX_new_ex<br />wolfSSL Entering wolfSSL_CertManagerNew<br />wolfSSL Leaving WOLFSSL_CTX_new, return 0<br />wolfSSL Entering wolfSSL_CTX_set_verify<br />wolfSSL_CTX_load_verify_locations_ex<br />Getting dynamic buffer<br />Processing CA PEM file</p><p><strong>&lt;WolfSSL step hidden all okay &gt;</strong></p><p>Got Cert Header<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />Got Algo ID<br />Getting Cert Name<br />Getting Cert Name<br />Got Subject Name<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering GetObjectId()<br /><strong>Got Key<br />ECDSA cert signature [What is this step?]</strong></p><p>PKCS 11 REQUIRED<br />CTX DEV ID is 1<br />Loading my pkcs library</p><p>Application::Application - Elapsed time &lt;0.003377&gt; seconds<br />C_GetFunctionList - &lt;BEGIN&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:08(UTC)]<br />C_GetFunctionList - [IN]<br />C_GetFunctionList - CK_FUNCTION_LIST_PTR_PTR &lt;0x25244&gt;<br />C_GetFunctionList - Elapsed time &lt;0.000001&gt; seconds<br />C_GetFunctionList - [RV] &lt;0x00&gt; (CKR_OK)<br />C_GetFunctionList - [OUT]<br />C_GetFunctionList - CK_FUNCTION_LIST_PTR_PTR &lt;0x25244&gt;<br />C_GetFunctionList - &lt;END&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:08(UTC)]</p><br /><p><strong>PKCS 11 object are found here</strong></p><p>Object CKO_CERTIFICATE<br />CKA_TOKEN &lt;1&gt;<br />CKA_PRIVATE &lt;0&gt;<br />CKA_MODIFIABLE &lt;1&gt;<br />CKA_TRUSTED &lt;1&gt;<br />CKA_SUBJECT - &lt;0x2435c0&gt; - size &lt;33&gt; - buffer &lt;30 1F 31 1D 30 1B 06 03 55 04 03 0C 14 38 39 39 36 36 30 36 30 39 39 30 30 38 37 34 32 34 31 32 38&gt;<br />CKA_ID - &lt;0x2430e8&gt; - size &lt;20&gt; - buffer &lt;61 0A B8 C5 27 B1 CD 91 9B C4 E6 6A B2 42 70 45 9C A1 63 05&gt;</p><p>Object CKO_PUBLIC_KEY<br />CKA_TOKEN &lt;1&gt;<br />CKA_PRIVATE &lt;0&gt;<br />CKA_ID - &lt;0x2420a0&gt; - size &lt;20&gt; - buffer &lt;AA 07 19 18 C6 16 14 FF DF C7 3F 12 85 24 E9 18 FF B3 B7 02&gt;</p><p>Object CKO_PRIVATE_KEY<br />CKA_TOKEN &lt;1&gt;<br />CKA_PRIVATE &lt;1&gt;<br />CKA_MODIFIABLE &lt;1&gt;<br /><strong>CKA_ID - &lt;0x2446d8&gt; - size &lt;20&gt; - buffer &lt;AA 07 19 18 C6 16 14 FF DF C7 3F 12 85 24 E9 18 FF B3 B7 02&gt;</strong></p><br /><p>C_CloseSession - Elapsed time &lt;0.000062&gt; seconds<br />C_CloseSession - [RV] &lt;0x00&gt; (CKR_OK)<br />C_CloseSession - &lt;END&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]</p><p>wolfSSL Leaving SSL_new, return 0<br />wolfSSL Entering wolfSSL_SetCertCbCtx<br /> SSL DEVICE ID IS SET TO 1<br /> wolfSSL Entering SSL_connect()<br />wolfSSL Entering SendClientHello<br />Adding signature algorithms extension<br />growing output buffer</p><p>Signature Algorithms extension to write<br />Point Formats extension to write<br />Supported Groups extension to write<br />Encrypt-Then-Mac extension to write<br />EMS extension to write<br />Shrinking output buffer</p><p>wolfSSL Leaving SendClientHello, return 0<br />connect state: CLIENT_HELLO_SENT<br />growing input buffer</p><p>received record layer msg<br />got HANDSHAKE<br />wolfSSL Entering DoHandShakeMsg()<br />wolfSSL Entering DoHandShakeMsgType<br />processing server hello<br />wolfSSL Entering DoServerHello<br />Point Formats extension received<br />Extended Master Secret extension received<br />wolfSSL Entering VerifyClientSuite<br />wolfSSL Leaving DoServerHello, return 0<br />Shrinking input buffer</p><p>wolfSSL Leaving DoHandShakeMsgType(), return 0<br />wolfSSL Leaving DoHandShakeMsg(), return 0<br />growing input buffer</p><p>received record layer msg<br />got HANDSHAKE<br />wolfSSL Entering DoHandShakeMsg()<br />wolfSSL Entering DoHandShakeMsgType<br />processing certificate<br />wolfSSL Entering DoCertificate<br />wolfSSL Entering ProcessPeerCerts<br />Loading peer&#039;s cert chain<br />&nbsp; &nbsp; &nbsp; &nbsp; Put another cert into chain<br />&nbsp; &nbsp; &nbsp; &nbsp; Put another cert into chain<br />wolfSSL Entering GetExplicitVersion<br />wolfSSL Entering GetSerialNumber<br />Got Cert Header<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />Got Algo ID<br />Getting Cert Name<br />Getting Cert Name<br />Got Subject Name<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering GetObjectId()<br />Got Key<br />Parsed Past Key<br />wolfSSL Entering DecodeCertExtensions<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeSubjKeyId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeAuthKeyId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeBasicCaConstraint<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />CA found<br /><strong>wolfSSL Entering ConfirmSignature</strong><br /><strong>wolfSSL Entering GetObjectId()</strong></p><p>C_OpenSession - &lt;BEGIN&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]<br />C_OpenSession - [IN]<br />C_OpenSession - slotID &lt;00&gt;<br />C_OpenSession - CK_FLAGS &lt;CKF_SERIAL_SESSION&gt;<br />C_OpenSession - pApplication &lt;00&gt;<br />C_OpenSession - Notify &lt;00&gt;<br />C_OpenSession - phSession &lt;0xbe80aab8&gt; (0x323935a0)</p><p>C_GetMechanismInfo - &lt;BEGIN&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]<br />C_GetMechanismInfo - [IN]<br />C_GetMechanismInfo - slotID &lt;00&gt;<br /><strong>C_GetMechanismInfo - CK_MECHANISM_TYPE &lt;CKM_ECDSA&gt;</strong><br />C_GetMechanismInfo - CK_MECHANISM_INFO - ulMinKeySize &lt;0xb6eeaf2c&gt; - ulMaxKeySize &lt;0xbe80aab8&gt; - flags &lt;CKF_EXTENSION | CKF_UNWRAP | CKF_WRAP | CKF_GENERATE | CKF_VERIFY_RECOVER | CKF_ENCRYPT | CKF_SIGN&gt;</p><br /><p>C_GetMechanismInfo - Elapsed time &lt;0.034830&gt; seconds<br /><strong>C_GetMechanismInfo - [RV] &lt;0x5&gt; (CKR_GENERAL_ERROR) //Not Supported by hardware</strong><br />C_GetMechanismInfo - [OUT]<br />C_GetMechanismInfo - CK_MECHANISM_INFO - ulMinKeySize &lt;0xb6eeaf2c&gt; - ulMaxKeySize &lt;0xbe80aab8&gt; - flags &lt;CKF_EXTENSION | CKF_UNWRAP | CKF_WRAP | CKF_GENERATE | CKF_VERIFY_RECOVER | CKF_ENCRYPT | CKF_SIGN&gt;</p><p>C_CloseSession - Elapsed time &lt;0.000062&gt; seconds<br />C_CloseSession - [RV] &lt;0x00&gt; (CKR_OK)<br />C_CloseSession - &lt;END&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]</p><p>wolfSSL Leaving ConfirmSignature, return 0<br />Verified CA from chain and already had it<br />Verifying Peer&#039;s cert<br />wolfSSL Entering GetExplicitVersion<br />wolfSSL Entering GetSerialNumber<br />Got Cert Header<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />Got Algo ID<br />Getting Cert Name<br />Getting Cert Name<br />Got Subject Name<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering GetObjectId()<br />Got Key<br />Parsed Past Key<br />wolfSSL Entering DecodeCertExtensions<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeAuthKeyId<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeBasicCaConstraint<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeKeyUsage<br />wolfSSL Entering GetObjectId()<br />wolfSSL Entering DecodeAltNames<br />wolfSSL Entering GetAlgoId<br />wolfSSL Entering GetObjectId()<br />CA found<br /><strong>wolfSSL Entering ConfirmSignature</strong><br />wolfSSL Entering GetObjectId()</p><p>C_OpenSession - Elapsed time &lt;0.000159&gt; seconds<br />C_OpenSession - [RV] &lt;0x00&gt; (CKR_OK)</p><p>C_GetMechanismInfo - Elapsed time &lt;0.019171&gt; seconds<br /><strong>C_GetMechanismInfo - [RV] &lt;0x5&gt; (CKR_GENERAL_ERROR) //Not Supported by hardware</strong></p><p>C_CloseSession - Elapsed time &lt;0.000060&gt; seconds<br />C_CloseSession - [RV] &lt;0x00&gt; (CKR_OK)<br />C_CloseSession - &lt;END&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]</p><p>wolfSSL Leaving ConfirmSignature, return 0<br />Verified Peer&#039;s cert<br />wolfSSL Entering GetObjectId()<br />wolfSSL Leaving ProcessPeerCerts, return 0<br />wolfSSL Leaving DoCertificate, return 0<br />Shrinking input buffer</p><p>wolfSSL Leaving DoHandShakeMsgType(), return 0<br />wolfSSL Leaving DoHandShakeMsg(), return 0<br />growing input buffer</p><p>received record layer msg<br />got HANDSHAKE<br />wolfSSL Entering DoHandShakeMsg()<br />wolfSSL Entering DoHandShakeMsgType<br />processing server key exchange<br />wolfSSL Entering DoServerKeyExchange<br /><strong>wolfSSL Entering EccVerify</strong><br />C_OpenSession - &lt;BEGIN&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]<br />C_OpenSession - [IN]<br />C_OpenSession - slotID &lt;00&gt;</p><p>C_GetMechanismInfo - Elapsed time &lt;0.019167&gt; seconds<br /><strong>C_GetMechanismInfo - [RV] &lt;0x5&gt; (CKR_GENERAL_ERROR) //Not Supported by hardware</strong><br /> C_GetMechanismInfo - [OUT]<br />C_GetMechanismInfo - CK_MECHANISM_INFO - ulMinKeySize &lt;0xb6eeaf2c&gt; - ulMaxKeySize &lt;0xbe80ab68&gt; - flags &lt;CKF_EXTENSION | CKF_GENERATE | CKF_VERIFY | CKF_DIGEST | CKF_SIGN&gt;</p><p>C_CloseSession - Elapsed time &lt;0.000063&gt; seconds<br />C_CloseSession - [RV] &lt;0x00&gt; (CKR_OK)<br />C_CloseSession - &lt;END&gt; [PID=0x000003B1, TID=0xb6f6a210] [2021-02-22 02:01:12(UTC)]</p><p>wolfSSL Leaving EccVerify, return 0<br />wolfSSL Leaving DoServerKeyExchange, return 0<br />Shrinking input buffer</p><p>wolfSSL Leaving EccSign, return -170<br />wolfSSL Leaving SendCertificateVerify, return -170<br />wolfSSL error occurred, error = -170<br />wolfSSL Entering SSL_get_error<br />wolfSSL Leaving SSL_get_error, return -170<br />wolfSSL Entering SSL_free<br />CTX ref count not 0 yet, no free<br />Shrinking output buffer</p>]]></description>
			<author><![CDATA[null@example.com (saksik.remy)]]></author>
			<pubDate>Mon, 22 Feb 2021 02:54:50 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5806.html#p5806</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5802.html#p5802</link>
			<description><![CDATA[<p>Hi Remy,</p><p>In your crypto callback just return `CRYPTOCB_UNAVAILABLE` and it will fallback to using software operations.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Fri, 19 Feb 2021 19:38:40 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5802.html#p5802</guid>
		</item>
		<item>
			<title><![CDATA[Re: PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5800.html#p5800</link>
			<description><![CDATA[<p>Hi Remy,</p><p>Thanks for joining the wolfSSL Forum. When you said:<br /></p><div class="quotebox"><blockquote><p>Unfortunately by using this callback, WofSSL expect the verify operation to be found, but it is not supported.</p></blockquote></div><p>Could you please share the error that you are seeing? Is it an actual verify operation failure, or just that the init is failing because the verify does not exist (NULL)?</p>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Fri, 19 Feb 2021 16:42:13 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5800.html#p5800</guid>
		</item>
		<item>
			<title><![CDATA[PKCS11 callback for hardware]]></title>
			<link>https://www.wolfssl.com/forums/post5795.html#p5795</link>
			<description><![CDATA[<p>Dear community,</p><p>I am using a hardware token to do some PKCS11 operation such as generate key pair, generate random and sign using ECC.<br />I am using the WolfMQTT client with the latest wolfSSL code with&nbsp; --enable-pkcs11 and --enable-crytocb for the callback.</p><p>My hardware is well initialized, the&nbsp; communication is fine.</p><p>I modify the &#039;mqttexample&#039; to load the private key from the token, which seems to be fine.</p><p>I am using:<br />typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);<br />WOLFSSL_API int wc_CryptoCb_RegisterDevice(<br />&nbsp; &nbsp; int devId,<br />&nbsp; &nbsp; CryptoDevCallbackFunc cb,<br />&nbsp; &nbsp; void* ctx);</p><p>in my mqttexample file:<br /> _ret = wc_CryptoDev_RegisterDevice(devId, wc_Pkcs11_CryptoDevCb,&nbsp; &amp;token);</p><p>This seems to be fine.</p><p>The problem i am facing is my token only support generate key pair, generate random and sign using ECC.<br />All the other operation, i do not wish to use my hardware token.</p><p>Unfortunately by using this callback, WofSSL expect the verify operation to be found, but it is not supported.</p><p>How can implement a callback to only support these 3 operations. (random, genKeyPair and Sign)?</p><p>Thank you for your help.<br />Regards<br />Remy</p>]]></description>
			<author><![CDATA[null@example.com (saksik.remy)]]></author>
			<pubDate>Fri, 19 Feb 2021 08:34:35 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5795.html#p5795</guid>
		</item>
	</channel>
</rss>
