<?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 — Verify cert using keyblob read from tpm nvram]]></title>
		<link>https://www.wolfssl.com/forums/topic1879-verify-cert-using-keyblob-read-from-tpm-nvram.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1879.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Verify cert using keyblob read from tpm nvram.]]></description>
		<lastBuildDate>Tue, 21 Jun 2022 18:29:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6605.html#p6605</link>
			<description><![CDATA[<p>Hi celov65111,</p><p>An X.509 certificate only contains a public key.</p><p>To compare the public key of the certificate to the TPM:<br />1) Read the public key from the TPM using something like `wolfTPM2_ReadPublicKey`<br />2) Export a RSA public key DER/ASN.1 using `wolfTPM2_RsaKey_TpmToWolf` and `wc_RsaKeyToPublicDer_ex. For ECC public key you can use `wolfTPM2_EccKey_TpmToWolf` and `wc_EccPublicKeyToDer`.<br />3) Extract the public key from the X.509 certificate.</p><div class="codebox"><pre><code>#include &quot;wolfssl/wolfcrypt/settings.h&quot;
#include &quot;wolfssl/wolfcrypt/asn.h&quot;

int ret;
DecodedCert cert;

InitDecodedCert(&amp;cert, certBuffer, certLen, NULL);
ret = ParseCert(&amp;cert, CERT_TYPE, NO_VERIFY, NULL);
if (ret == 0) {
    printf(&quot;Public Key %d\n&quot;, cert.pubKeySize);
    WOLFSSL_BUFFER(cert.publicKey, cert.pubKeySize);
    
}
FreeDecodedCert(&amp;cert);</code></pre></div><p>Also make sure you verify the signature of the certificate. You can pass `VERIFY` instead of `NO_VERIFY` on ParseCert. The 4th argument lets you pass in a Certificate Manager pointer for validating the signature against a trusted certificate. We have an example for that here: <a href="https://github.com/wolfSSL/wolfssl-examples/blob/master/certmanager/certloadverifybuffer.c">https://github.com/wolfSSL/wolfssl-exam … fybuffer.c</a></p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Tue, 21 Jun 2022 18:29:42 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6605.html#p6605</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6602.html#p6602</link>
			<description><![CDATA[<p>In another words, how can I check the public (or private) key in .crt file is the same one I read from TPM nvram ?</p>]]></description>
			<author><![CDATA[null@example.com (celov65111)]]></author>
			<pubDate>Sun, 19 Jun 2022 18:27:09 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6602.html#p6602</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6601.html#p6601</link>
			<description><![CDATA[<div class="quotebox"><cite>dgarske wrote:</cite><blockquote><p>Hi celov65111,</p><p>A certificate contains a public key which is signed by another key who is trusted. To verify a certificate you only need the public key for the signer. Typically the AKID (Authority Key Identifier) is used to identify the signer key. It is a hash of the signers public key.</p><p>If a TPM private key was used to sign you only need to have the public key to verify a certificate, since a verify is a pubic only operation.</p><p>You can export a TPM RSA public key using `wolfTPM2_RsaKey_TpmToPemPub`. Or you could export a RSA public key DER/ASN.1 using `wolfTPM2_RsaKey_TpmToWolf` and `wc_RsaKeyToPublicDer_ex. For ECC public key you can use `wolfTPM2_EccKey_TpmToWolf` and `wc_EccPublicKeyToDer`.</p><p>For validating a certificate you could leverage our wolfSSL Certificate Manager to do a certificate validation. See example here:<br /><a href="https://github.com/wolfSSL/wolfssl-examples/blob/master/certmanager/certloadverifybuffer.c">https://github.com/wolfSSL/wolfssl-exam … fybuffer.c</a></p><p>If you are looking for a more direct approach you could just do:<br />1) Hash the certificate (minus trailing signature)<br />2) Use wc_ecc_verify_hash or wc_RsaSSL_VerifyInline with the public key and hash to verify signature.</p><p>For reference a KEYBLOB is key material from the TPM in a TPM format. The private key is encrypted and not usable except when loaded to the TPM. The public portion of a key blob is exportable and can be used for wolfCrypt operations using the above conversion API&#039;s.</p><p>If you have more questions if would be helpful to know more about your project. Feel free to email us directly support at wolfssl.com and reference this ticket.</p><p>Thanks,<br />David Garske, wolfSSL</p></blockquote></div><p>I&#039;m quite confused because there are many structures. I will explain u what I have, and I hope u guide me to the best way I can go with<br />Basically, what I have is<br />1- KeyBlob I get from the TPM (private and public, using the nvram read example)<br />2- I have .crt file</p><p>what I need is to verify (by verify I mean making sure that keys I read from this .crt are same as keys I read from TPM, I think this is comparing public keys or private keys)</p><p>Now what steps should I do as I got lost in the docs and cannot find a proper way to do it. <br />Thanks in advance.</p>]]></description>
			<author><![CDATA[null@example.com (celov65111)]]></author>
			<pubDate>Sat, 18 Jun 2022 10:49:24 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6601.html#p6601</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6597.html#p6597</link>
			<description><![CDATA[<p>Hi celov65111,</p><p>A certificate contains a public key which is signed by another key who is trusted. To verify a certificate you only need the public key for the signer. Typically the AKID (Authority Key Identifier) is used to identify the signer key. It is a hash of the signers public key.</p><p>If a TPM private key was used to sign you only need to have the public key to verify a certificate, since a verify is a pubic only operation.</p><p>You can export a TPM RSA public key using `wolfTPM2_RsaKey_TpmToPemPub`. Or you could export a RSA public key DER/ASN.1 using `wolfTPM2_RsaKey_TpmToWolf` and `wc_RsaKeyToPublicDer_ex. For ECC public key you can use `wolfTPM2_EccKey_TpmToWolf` and `wc_EccPublicKeyToDer`.</p><p>For validating a certificate you could leverage our wolfSSL Certificate Manager to do a certificate validation. See example here:<br /><a href="https://github.com/wolfSSL/wolfssl-examples/blob/master/certmanager/certloadverifybuffer.c">https://github.com/wolfSSL/wolfssl-exam … fybuffer.c</a></p><p>If you are looking for a more direct approach you could just do:<br />1) Hash the certificate (minus trailing signature)<br />2) Use wc_ecc_verify_hash or wc_RsaSSL_VerifyInline with the public key and hash to verify signature.</p><p>For reference a KEYBLOB is key material from the TPM in a TPM format. The private key is encrypted and not usable except when loaded to the TPM. The public portion of a key blob is exportable and can be used for wolfCrypt operations using the above conversion API&#039;s.</p><p>If you have more questions if would be helpful to know more about your project. Feel free to email us directly support at wolfssl.com and reference this ticket.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Thu, 16 Jun 2022 20:50:07 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6597.html#p6597</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6596.html#p6596</link>
			<description><![CDATA[<div class="quotebox"><cite>embhorn wrote:</cite><blockquote><p>Hello celov65111</p><p>Welcome and thanks for joining the wolfSSL Forums. I moved this topic to the wolfTPM section, under the assumption that you are using wolfTPM to access the TPM device. Please correct me if I am mistaken.</p><p>Here is an example of reading a key from nvram:<br /><a href="https://github.com/wolfSSL/wolfTPM/blob/master/examples/nvram/read.c">https://github.com/wolfSSL/wolfTPM/blob … ram/read.c</a></p><p>Let us know if there are any questions.</p><p>Kind regards,<br />Eric @ wolfSSL Support</p></blockquote></div><p>Yes I read from nvram, and my code is using this example<br />my problem comes after that<br />I read public and private keys from tpm nvram, which is done well<br />Now, I &#039;ve .crt certificate which I want to verify (i.e.: verify this cert using the private key I read from nvram and check both private keys are same)</p><p>Question is: how can I do this? what I get from nvram reading is (Keyblob) structure, where none of the functions in the doc accepts keyblob. So, how can I use what I read from nvram to verify a .crt I have?</p><p>another question is, what is the format comes out /goes in to the nvram? is the keyblob pem format? ..etc</p><p>These are mainly my questions</p>]]></description>
			<author><![CDATA[null@example.com (celov65111)]]></author>
			<pubDate>Thu, 16 Jun 2022 14:21:34 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6596.html#p6596</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6595.html#p6595</link>
			<description><![CDATA[<p>Hello celov65111</p><p>Welcome and thanks for joining the wolfSSL Forums. I moved this topic to the wolfTPM section, under the assumption that you are using wolfTPM to access the TPM device. Please correct me if I am mistaken.</p><p>Here is an example of reading a key from nvram:<br /><a href="https://github.com/wolfSSL/wolfTPM/blob/master/examples/nvram/read.c">https://github.com/wolfSSL/wolfTPM/blob … ram/read.c</a></p><p>Let us know if there are any questions.</p><p>Kind regards,<br />Eric @ wolfSSL Support</p>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Thu, 16 Jun 2022 13:34:43 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6595.html#p6595</guid>
		</item>
		<item>
			<title><![CDATA[Verify cert using keyblob read from tpm nvram]]></title>
			<link>https://www.wolfssl.com/forums/post6594.html#p6594</link>
			<description><![CDATA[<p>Hello. <br />I&#039;m new to wolfssl and quite confused. I read private key (to KEYBLOB structure) from tpm nvram. I need to verify that this is the same key as one I have in another cert (i.e.: want to verify it).</p><p>How can I do this? <br />From documentation, I see (like in this post <a href="https://www.wolfssl.com/forums/topic1402-solved-how-to-verify-a-certificate-key-pair.html">https://www.wolfssl.com/forums/topic140 … -pair.html</a> ) that I can do it, but with key as pem not keyblob.</p><p>now what is the right way to do from keyblob?</p>]]></description>
			<author><![CDATA[null@example.com (celov65111)]]></author>
			<pubDate>Thu, 16 Jun 2022 10:31:08 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6594.html#p6594</guid>
		</item>
	</channel>
</rss>
