<?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 — Need help!]]></title>
		<link>https://www.wolfssl.com/forums/topic1893-need-help.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1893.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Need help!.]]></description>
		<lastBuildDate>Fri, 15 Jul 2022 12:32:12 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6651.html#p6651</link>
			<description><![CDATA[<div class="quotebox"><cite>dgarske wrote:</cite><blockquote><p>Hi tpm2user,</p><p>1) Load the TPM public key into a wolfCrypt ecc_key struct: <a href="https://github.com/wolfSSL/wolfTPM/blob/master/examples/tls/tls_client.c#L226">https://github.com/wolfSSL/wolfTPM/blob … ent.c#L226</a></p></blockquote></div><p>Thanks. For this, I see the functions:<br /></p><div class="codebox"><pre><code> rc = wolfTPM2_GetKeyTemplate_ECC(..)
 rc = getECCkey(..)</code></pre></div><p>I checked the getECCKey() function. It calls:<br />createAndLoadKey() and if I understand correctly, it generates its own keys from the TPM and loads the the public part into wolfEccKey object. I tried reading the context file via readKeyBlob and wolfTPM2_LoadKey(.) to receive a handle from TPM and pass it get getECCKey() function, but it failed.</p><div class="quotebox"><blockquote><p>I have my own context file generated by TPM [related to this post: <a href="https://www.wolfssl.com/forums/post6650.html#p6650)">https://www.wolfssl.com/forums/post6650.html#p6650)</a> (which I would like to have loaded externally to TPM. I don&#039;t understand how I can go ahead from here by letting TPM know that I already have what it wants.)</p></blockquote></div>]]></description>
			<author><![CDATA[null@example.com (tpm2user)]]></author>
			<pubDate>Fri, 15 Jul 2022 12:32:12 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6651.html#p6651</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6649.html#p6649</link>
			<description><![CDATA[<p>Thanks, will try this and report back.</p><p>On a side note, I have an context file generated via tpm2_loadexternal command.</p><div class="codebox"><pre><code>tpm2_loadexternal --hierarchy n \
                  --key-algorithm rsa \
                  --public &quot;$HOME/openssl_public.pem&quot; \
                  --private &quot;$HOME/openssl_private.pem&quot; \
                  --key-context &quot;$HOME/openssl.ctx&quot; \
                  --name &quot;$HOME/openssl.name&quot;</code></pre></div><p>Is there a way that this <strong>openssl.ctx</strong> file can be loaded using wolfTPM commands? I tried using keyload, but this seems to be a different format:</p><div class="quotebox"><blockquote><p>linux@tpm2user:~/test/wolfTPM/examples/keygen$ file keyblob.bin <br />keyblob.bin: PDP-11 overlaid pure executable not stripped</p><p>linux@tpm2user:~/test/wolfTPM/examples/keygen$ file ~/openssl.ctx <br />~/openssl.ctx: data</p><p>I also tried base64 to convert openssl.ctx:<br />linux@tpm2user:~/test/wolfTPM/examples/keygen$ file to_b64_openssl.ctx <br />to_b64_openssl.ctx: ASCII text</p></blockquote></div>]]></description>
			<author><![CDATA[null@example.com (tpm2user)]]></author>
			<pubDate>Thu, 14 Jul 2022 15:45:07 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6649.html#p6649</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6648.html#p6648</link>
			<description><![CDATA[<p>Hi tpm2user,</p><p>1) Load the TPM public key into a wolfCrypt ecc_key struct: <a href="https://github.com/wolfSSL/wolfTPM/blob/master/examples/tls/tls_client.c#L226">https://github.com/wolfSSL/wolfTPM/blob … ent.c#L226</a><br />2) Extract public key as DER: wc_EccPublicKeyToDer: <a href="https://github.com/wolfSSL/wolfTPM/blob/master/examples/tls/tls_client.c#L363">https://github.com/wolfSSL/wolfTPM/blob … ent.c#L363</a><br />3) Use DER with wolfSSL_CTX_use_PrivateKey_buffer and WOLFSSL_FILETYPE_ASN1</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Thu, 14 Jul 2022 15:23:58 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6648.html#p6648</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6647.html#p6647</link>
			<description><![CDATA[<p>Thanks David.</p><p>I looked at the TLS example, there were some minor changes since the last time I saw it.</p><p>To get the basics right, I did the following:</p><p># Generate keypair on TPM and generate ECC signed certificate for use:<br /></p><div class="codebox"><pre><code>sudo ./examples/keygen/keygen ecc_test_blob.raw -ecc -t
sudo ./examples/csr/csr
sudo ./certs/certreq.sh</code></pre></div><p>So, now I have <strong>ca-ecc-cert.pem </strong> signed certificate file and <strong>ecc_test_blob.raw</strong> file (the latter holding the key-pair)</p><p>In software, I have done the following:<br />1. Setup TPM callback using wolfTPM2_CryptoDevCb and wolfSSL_CTX_SetDevId<br />2. <span class="bbu">Q. How do I load the buffer as PEM?</span> I did the following:<br /></p><ul><li><p>a) Load the keyfile ecc_test_blob.raw into TPM and get back a TPM handle (OK)</p></li><li><p>b) Extract public_key from the above keyblob and store it as a buffer? The public_key is only available under WOLFTPM2_KEYBLOB</p></li></ul><p>I am a bit lost now, because it did not work. All I need is how to get the buffer_key correctly (which I now understand is the public key provided to wolfSSL and private_key is on the TPM itself which will be used via crypto_callback).</p><div class="codebox"><pre><code>if ((wolfSSL_CTX_use_PrivateKey_buffer(ctx, buffer_key, buffer_key_size, WOLFSSL_FILETYPE_PEM)) != WOLFSSL_SUCCESS)
{
    printf(&quot;Failed to set the key&quot;);   
    return -1;
}</code></pre></div><p>Looking to get this sorted. Its been a sharp learning curve with existing examples and unable to find sufficient wolfTpm signing examples.</p><p>Many thanks!</p>]]></description>
			<author><![CDATA[null@example.com (tpm2user)]]></author>
			<pubDate>Thu, 14 Jul 2022 12:27:36 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6647.html#p6647</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6646.html#p6646</link>
			<description><![CDATA[<p>Hi tpm2user,</p><p>1) For wolfSSL when using a TPM private key for TLS you need to extract the public key and pass it to the `wolfSSL_CTX_use_PrivateKey_*` function. The TLS examples were all updated recently to do this. See PR <a href="https://github.com/wolfSSL/wolfTPM/pull/210">https://github.com/wolfSSL/wolfTPM/pull/210</a><br />The use_PrivateKey functions support variations to allow using a file or buffer as PEM or DER.</p><p>2) The crypto callback requires registering a callback function (like wolfTPM2_CryptoDevCb) with a devId value. Then you use `wolfSSL_CTX_SetDevId` to tell the TLS layer and all internal keys to use the crypto callback.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Wed, 13 Jul 2022 16:33:27 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6646.html#p6646</guid>
		</item>
		<item>
			<title><![CDATA[Need help!]]></title>
			<link>https://www.wolfssl.com/forums/post6644.html#p6644</link>
			<description><![CDATA[<p>Hello,</p><p>This is my first post in this forum. The earliest post on tpm.dev went unanswered. I hope someone can help clarify here. My question is two-fold:</p><br /><p><strong>FIRST:</strong> I wish to have equivalent of the below function, but for TPM:</p><div class="codebox"><pre><code>if (wolfSSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, WOLFSSL_FILETYPE_PEM)   != SSL_SUCCESS)
{
    // Turn off TLS
    return 0;
} </code></pre></div><p>Note: Here, KEY_FILE is a plain .crt text file on filesystem containing a private key. (This was used prior to TPM present on hardware).</p><p><strong>SECOND:</strong> Regarding signing inside of TPM2 chip, I see i could use the following function:</p><br /><div class="codebox"><pre><code>/* [This is part of wolftpm2/tls/tls_server.c example:
* Private key only exists on the TPM and crypto callbacks are used for
* signing. Public key is required to enable TLS server auth.
* This API accepts public keys when crypto callbacks are enabled */
if (wolfSSL_CTX_use_PrivateKey_buffer(ctx, buffer, buffer_size, WOLFSSL_FILETYPE_ASN1) != WOLFSSL_SUCCESS) 
{
..
}</code></pre></div><p>It seems for the above function to use TPM2, we need to enable Crypto-callback and TPM2 should take care of signing using the callback. The following are the <strong>Steps</strong> I followed:</p><p>1. Generated raw file using keygen tool in wolftpm/examples (I renamed it to keyblob.bin)<br />2. I imported this to TPM to receive a temporary TPM2 handle (which went OK).<br />3. I have a public certificate (named test.crt) which contains public key (signed using CSR by Certificate Authority). so, this public certificate corresponds to the CSR generated by TPM for this private key.<br />4. I have enabled the crypto-dev callbacks.</p><p>So, now I have the TPM2 handle and certificate file. How can i register to the above buffer function using these for signing operations? In code I did:</p><div class="codebox"><pre><code>readKeyblob -&gt; get the private key
wolftpm2_load -&gt; get the handle for the key stored by TPM
wolfSSL_CTX_use_PrivateKey_buffer -&gt; The parameters were (ctx, keyBlob.priv.buffer, sizeof(keyBlob.priv.size)</code></pre></div><p>What am I doing wrong?</p>]]></description>
			<author><![CDATA[null@example.com (tpm2user)]]></author>
			<pubDate>Wed, 13 Jul 2022 13:09:31 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6644.html#p6644</guid>
		</item>
	</channel>
</rss>
