Free AI web copilot to create summaries, insights and extended knowledge, download it at here
3879
Abstract
rder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="24ff">You can find helper functions and meta tags down below.</p><p id="5095"><b>PubArea</b> is just continuation of the certInfo, and it contains information about public key.</p><figure id="bab0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*riJ5567Z3jKXyhyxMAwthQ.png"><figcaption></figcaption></figure><p id="49d6">The purpose of pubArea is to provide information about generated keypair. Lets review its fields:</p><ul><li><b>type</b> — type of key / key algorithm, i.e RSA, ECC. A member of TPM_ALG_ID</li><li><b>name alg</b> — an algorithm that was used to generate name field in certInfo. Must much algorithm in name</li><li><b>object attributes</b> — a bit map, with flags defining available key operations</li><li><b>auth policy</b> — a hash of the authentication policy. Ignore</li><li><b>parameters</b> — a list of key parameters.</li><li><b>unique</b> — generate public key. For RSA it’s the n coefficient, and for ECC it’s the concatenation of the X and Y coefficients. Must match newly generated public key in authData.</li></ul><p id="d164">For parameters:</p><ul><li><b>symmetric</b> — symmetric algorithm used for encryption. Must be set to NULL</li><li><b>scheme</b> — algorithm scheme, such as RSASSA(0x0014), RSAPSS(0x0016) for RSA and ECDSA(0x0018) for ECC. etc. Members of TPM_ALG_ID</li></ul><p id="6411">If type is set to RSA:</p><ul><li><b>keyBits</b> — length of key. 2048/4096 etc</li><li><b>exponent</b> — RSA key exponent. If set to 0x00, then exponent is a default RSA exponent of 2¹⁶+1(65537)</li></ul><p id="3aa8">If type is set to ECC:</p><ul><li><b>curveId</b> — curve identifier. Member of TPM_ECC_CURVE</li><li><b>kdf</b> — key derivative function identifier for symmetric encryption. Must be NULL.</li></ul><p id="0146">So the method for parsing would look like:</p>
<figure id="7901">
<div>
<div>
<iframe class="gist-iframe" src="/gist/herrjemand/413262f627a2f26e559ba9ebd5c34612.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h1 id="d0b0">Verifying attestation</h1><p id="d122">To verify attestation you need to do two things: verify structures and verify signature and chain</p><h2 id="3680">Verifying structures</h2><ol><li>Check that <b>“ver”</b> is set to <b>“2.0”</b></li><li>Check that the <b>“alg”</b> field is set to the equivalent value to the signatureAlgorithm in the metadata. You can find useful conversion tables in the appendix.</li><li>Parse <b>“pubArea”</b>.</li><li>Check that pubArea.parameters are corresponding the the chosen signatureAlgorithm in metadata.</li><li>Check that pubArea.unique is set to the same public key, as the one in <b>“authData”</b> struct.</li><li>Parse <b>“certInfo”</b>.</li><li>Check that certInfo.magic is set to TPM_GENERATED(0xFF544347).</li><li>Check that certInfo.type is set to TPM_ST_ATTEST_CERTIFY(0x8017).</li><li>Hash pubArea to create pubAreaHash using the nameAlg in <b>attested</b></li><li>Concatenate attested.nameAlg and pubAreaHash to create attestedName.</li><li>Check that certInfo.attested.name is equals to attestedName.</li><li>Concatenate authData with clientDataHash to create attToBeSigned</li><li>Hash attToBeSigned using the algorithm specified in attStmt.alg to create attToBeSignedHash</li><li>Check that certInfo.extraData is equals to attToBeSignedHash.</li></ol><h2 id="f7d6">Verifying signature</h2><p id="0c4a">At that point no one supports ECDAA, so I will only explain FULL attestation.</p><ol><li>Pick a leaf AIK certificate of the x5c array and parse it.</li><li>Check that certificate if of version 3(value mu
Options
st be set to 2).</li><li>Check that Subject sequence is empty.</li><li>Check that certificate is not expired and is started.</li><li>Check that certificate contains subjectAltName(2.5.29.17) extension, and check that tcpaTpmManufacturer(2.23.133.2.1) field is set to the existing manufacturer ID. You can find list of TPM_MANUFACTURERS in the appendix.</li><li>Check that certificate contains extKeyUsage(2.5.29.37) extension and it must contain tcg-kp-AIKCertificate (2.23.133.8.3) OID.</li><li>If certificate contains id-fido-gen-ce-aaguid(1.3.6.1.4.1.45724.1.1.4) extension, check that it’s value is set to the same AAGUID as in authData.</li><li>For attestationRoot in metadata.attestationRootCertificates, generate verification chain <b>verifX5C</b> by appending attestationRoot to the x5c. Try verifying <b>verifX5C</b>. If successful go to next step. If fail try next attestationRoot. If no attestationRoots left to try, fail.</li><li>Verify signature over certInfo with the public key extracted from AIK certificate.</li><li>Get Martini friend, you are done!</li></ol><p id="4dfc">That’s all folks. If you have any questions, please leave the comment down below, or find me on twitter <a href="https://twitter.com/herrjemand">@herrjemand</a></p><h1 id="df5b">Updates</h1><p id="0a16">30/07/18: Clarified exponent behaviour when set to 0</p><p id="c9fc">13/08/18: Clarified usage of the hashing algorithm for pubArea</p><p id="f90a">11/10/18: Fixed typos. Thanks @devsarif *)</p><p id="7835">29/04/19: Fixed name algorithm mixup</p><h1 id="faeb">References</h1><ol><li><a href="https://w3c.github.io/webauthn/#tpm-attestation">https://w3c.github.io/webauthn/#tpm-attestation</a></li><li><a href="https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf">https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf</a></li><li><a href="https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf">https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf</a></li><li><a href="https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-3-Commands-01.38.pdf">https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-3-Commands-01.38.pdf</a></li><li><a href="https://www.trustedcomputinggroup.org/wp-content/uploads/Credential_Profile_EK_V2.0_R14_published.pdf">https://www.trustedcomputinggroup.org/wp-content/uploads/Credential_Profile_EK_V2.0_R14_published.pdf</a></li></ol><h1 id="f215">Snippets</h1>
<figure id="48de">
<div>
<div>
<iframe class="gist-iframe" src="/gist/herrjemand/9d0045e76e9d1dbad6d3714920ecd80c.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure>
<figure id="000d">
<div>
<div>
<iframe class="gist-iframe" src="/gist/herrjemand/cd067cff891108c8ad16a67ba7a6771a.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h1 id="fb1d">License</h1><p id="dbc8">This article is licensed under <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)</a>. So you are free to read, share, etc. If you are interested in commercial use of this article, or wish to translate it to a different language, please contact ackermann(dot)yuriy(at)gmail(dot)com.</p><p id="06c4">The code samples are licensed under <a href="https://gist.github.com/herrjemand/09492b2c6fc6c4ebc0d49b5942d4ec30">MIT license</a>.</p></article></body>