void process_get_pcrvalues()

in client-library/src/Attestation/LinuxTpm/testclient/main.cpp [235:279]


void process_get_pcrvalues()
{
    auto pcrvalsFile = prepend_tempdir_path("pcrlist");
    std::ofstream pcrvalsf(pcrvalsFile);
    Tss2Ctx tmpCtx;
    attest::PcrList pcrs(Tss2Util::GetPcrCount(tmpCtx));
    //Populate the pcrs with the increasing values.
    std::iota(pcrs.begin(), pcrs.end(), 0);

    std::vector<attest::HashAlg> hashAlgs = {attest::HashAlg::Sha1, attest::HashAlg::Sha256, attest::HashAlg::Sha384 };

    // formatting to be the same as tpm2_pcrlist command
    for (auto &hashAlg : hashAlgs) {
        switch (hashAlg) {
            case attest::HashAlg::Sha1:
                pcrvalsf << "sha1:" << endl;
                break;
            case attest::HashAlg::Sha256:
                pcrvalsf << "sha256:" << endl;
                break;
            case attest::HashAlg::Sha384:
                pcrvalsf << "sha384:" << endl;
                break;
        }

        auto pcrValues = g_tpm.GetPCRValues(pcrs, hashAlg);
        for (auto &pcrVal : pcrValues.pcrs) {
            pcrvalsf << "  " << dec << (int) pcrVal.index;
            if (pcrVal.index < 10) {
                pcrvalsf << " : ";
            } else {
                pcrvalsf << ": ";
            }
            pcrvalsf << "0x" << hex << uppercase;

            for (auto &byte : pcrVal.digest) {
                // this ensures leading zero not lost when printing out byte
                pcrvalsf << setfill('0') << setw(2) << (int) byte;
            }
            pcrvalsf << endl;
        }
    }

    cout << "Wrote PCR Values to " << pcrvalsFile << endl;
}