|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the Apache 2.0 License. |
| 3 | + |
| 4 | +#include "ccf/ds/hex.h" |
| 5 | +#include "ccf/ds/quote_info.h" |
| 6 | +#include "ccf/pal/attestation.h" |
| 7 | +#include "ccf/pal/measurement.h" |
| 8 | +#include "ccf/pal/report_data.h" |
| 9 | +#include "crypto/openssl/hash.h" |
| 10 | +#include "pal/test/snp_attestation_validation_data.h" |
| 11 | + |
| 12 | +#define DOCTEST_CONFIG_IMPLEMENT |
| 13 | +#include <doctest/doctest.h> |
| 14 | + |
| 15 | +TEST_CASE("milan validation") |
| 16 | +{ |
| 17 | + using namespace ccf; |
| 18 | + |
| 19 | + auto milan_quote_info = QuoteInfo{ |
| 20 | + .format = QuoteFormat::amd_sev_snp_v1, |
| 21 | + .quote = pal::snp::testing::milan_attestation, |
| 22 | + .endorsements = std::vector<uint8_t>( |
| 23 | + pal::snp::testing::milan_endorsements.begin(), |
| 24 | + pal::snp::testing::milan_endorsements.end()), |
| 25 | + .uvm_endorsements = std::nullopt, |
| 26 | + }; |
| 27 | + |
| 28 | + pal::PlatformAttestationMeasurement measurement; |
| 29 | + pal::PlatformAttestationReportData report_data; |
| 30 | + |
| 31 | + pal::verify_snp_attestation_report( |
| 32 | + milan_quote_info, measurement, report_data); |
| 33 | +} |
| 34 | + |
| 35 | +TEST_CASE("genoa validation") |
| 36 | +{ |
| 37 | + using namespace ccf; |
| 38 | + |
| 39 | + auto genoa_quote_info = QuoteInfo{ |
| 40 | + .format = QuoteFormat::amd_sev_snp_v1, |
| 41 | + .quote = pal::snp::testing::genoa_attestation, |
| 42 | + .endorsements = std::vector<uint8_t>( |
| 43 | + pal::snp::testing::genoa_endorsements.begin(), |
| 44 | + pal::snp::testing::genoa_endorsements.end()), |
| 45 | + .uvm_endorsements = std::nullopt, |
| 46 | + }; |
| 47 | + |
| 48 | + pal::PlatformAttestationMeasurement measurement; |
| 49 | + pal::PlatformAttestationReportData report_data; |
| 50 | + |
| 51 | + pal::verify_snp_attestation_report( |
| 52 | + genoa_quote_info, measurement, report_data); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_CASE("Mismatched attestation and endorsements fail") |
| 56 | +{ |
| 57 | + using namespace ccf; |
| 58 | + |
| 59 | + auto mismatched_quote = QuoteInfo{ |
| 60 | + .format = QuoteFormat::amd_sev_snp_v1, |
| 61 | + .quote = pal::snp::testing::milan_attestation, |
| 62 | + .endorsements = std::vector<uint8_t>( |
| 63 | + pal::snp::testing::genoa_endorsements.begin(), |
| 64 | + pal::snp::testing::genoa_endorsements.end()), |
| 65 | + .uvm_endorsements = std::nullopt, |
| 66 | + }; |
| 67 | + |
| 68 | + pal::PlatformAttestationMeasurement measurement; |
| 69 | + pal::PlatformAttestationReportData report_data; |
| 70 | + |
| 71 | + try |
| 72 | + { |
| 73 | + pal::verify_snp_attestation_report( |
| 74 | + mismatched_quote, measurement, report_data); |
| 75 | + } |
| 76 | + catch (const std::logic_error& e) |
| 77 | + { |
| 78 | + const std::string what = e.what(); |
| 79 | + CHECK( |
| 80 | + what.find("SEV-SNP: The root of trust public key for this attestation " |
| 81 | + "was not the expected one") != std::string::npos); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +int main(int argc, char** argv) |
| 86 | +{ |
| 87 | + ccf::crypto::openssl_sha256_init(); |
| 88 | + doctest::Context context; |
| 89 | + context.applyCommandLine(argc, argv); |
| 90 | + int res = context.run(); |
| 91 | + ccf::crypto::openssl_sha256_shutdown(); |
| 92 | + return res; |
| 93 | +} |
0 commit comments