28 static void verify_virtual_attestation_report(
33 auto j = nlohmann::json::parse(quote_info.
quote);
35 const auto s_measurement = j[
"measurement"].get<std::string>();
37 std::vector<uint8_t>(s_measurement.begin(), s_measurement.end());
39 j[
"report_data"].get<std::vector<uint8_t>>());
43 static void verify_snp_attestation_report(
45 PlatformAttestationMeasurement& measurement,
46 PlatformAttestationReportData& report_data)
50 throw std::logic_error(fmt::format(
51 "Unexpected attestation report to verify for SEV-SNP: {}",
55 if (quote_info.
quote.size() !=
sizeof(snp::Attestation))
57 throw std::logic_error(fmt::format(
58 "Input SEV-SNP attestation report is not of expected size {}: {}",
59 sizeof(snp::Attestation),
60 quote_info.
quote.size()));
64 *
reinterpret_cast<const snp::Attestation*
>(quote_info.
quote.data());
66 if (quote.version < snp::minimum_attestation_version)
68 throw std::logic_error(fmt::format(
69 "SEV-SNP: Attestation version is {} not >= expected minimum {}",
71 snp::minimum_attestation_version));
74 if (quote.flags.signing_key != snp::attestation_flags_signing_key_vcek)
76 throw std::logic_error(fmt::format(
77 "SEV-SNP: Attestation report must be signed by VCEK: {}",
78 static_cast<uint8_t
>(quote.flags.signing_key)));
81 if (quote.flags.mask_chip_key != 0)
83 throw std::logic_error(
84 fmt::format(
"SEV-SNP: Mask chip key must not be set"));
96 throw std::logic_error(fmt::format(
97 "SEV-SNP: VMPL for guest attestations must be in 0-3 range, not {}",
105 reinterpret_cast<const char*
>(quote_info.
endorsements.data()),
107 if (certificates.size() != 3)
109 throw std::logic_error(fmt::format(
110 "Expected 3 endorsement certificates but got {}", certificates.size()));
115 auto chip_certificate = certificates[0];
116 auto sev_version_certificate = certificates[1];
117 auto root_certificate = certificates[2];
121 std::string expected_root_public_key;
122 if (quote.version < 3)
134 throw std::logic_error(fmt::format(
135 "SEV-SNP: Unsupported CPUID family {} model {}",
137 quote.cpuid_mod_id));
139 expected_root_public_key =
key->second;
141 if (root_cert_verifier->public_key_pem().str() != expected_root_public_key)
143 throw std::logic_error(fmt::format(
144 "SEV-SNP: The root of trust public key for this attestation was not "
145 "the expected one for v{} {} {}: {} != {}",
149 root_cert_verifier->public_key_pem().str(),
150 expected_root_public_key));
153 if (!root_cert_verifier->verify_certificate({&root_certificate}))
155 throw std::logic_error(
156 "SEV-SNP: The root of trust public key for this attestation was not "
157 "self signed as expected");
161 if (!chip_cert_verifier->verify_certificate(
162 {&root_certificate}, {&sev_version_certificate}))
164 throw std::logic_error(
165 "SEV-SNP: The chain of signatures from the root of trust to this "
166 "attestation is broken");
172 throw std::logic_error(fmt::format(
173 "SEV-SNP: Unsupported signature algorithm: {} (supported: {})",
174 quote.signature_algo,
181 sizeof(quote.signature.r),
183 sizeof(quote.signature.s),
187 std::span quote_without_signature{
188 quote_info.
quote.data(),
189 quote_info.
quote.size() -
sizeof(quote.signature)};
190 if (!chip_cert_verifier->verify(quote_without_signature, quote_signature))
192 throw std::logic_error(
193 "SEV-SNP: Chip certificate (VCEK) did not sign this attestation");
206 if (quote.policy.debug != 0)
208 throw std::logic_error(
209 "SEV-SNP: SNP attestation report guest policy debugging must not be "
213 if (quote.policy.migrate_ma != 0)
215 throw std::logic_error(
"SEV-SNP: Migration agents must not be enabled");
221 const auto& endorsed_tcb = quote_info.
endorsed_tcb.value();
222 auto raw_tcb = ds::from_hex(quote_info.
endorsed_tcb.value());
224 if (raw_tcb.size() !=
sizeof(snp::TcbVersionRaw))
226 throw std::logic_error(fmt::format(
227 "SEV-SNP: TCB of size {}, expected {}",
229 sizeof(snp::TcbVersionRaw)));
234 raw_tcb.data(), "e.reported_tcb,
sizeof(snp::TcbVersionRaw)) != 0)
236 auto* reported_tcb =
reinterpret_cast<uint8_t*
>("e.reported_tcb);
237 throw std::logic_error(fmt::format(
238 "SEV-SNP: endorsed TCB {} does not match reported TCB {}",
241 {reported_tcb, reported_tcb +
sizeof(quote.reported_tcb)})));
246 static void verify_quote(
247 const QuoteInfo& quote_info,
248 PlatformAttestationMeasurement& measurement,
249 PlatformAttestationReportData& report_data)
253 verify_virtual_attestation_report(quote_info, measurement, report_data);
257 verify_snp_attestation_report(quote_info, measurement, report_data);
261 throw std::logic_error(
262 "SGX attestation reports are no longer supported from 6.0.0 onwards");
274 virtual const char*
what()
const throw()