cryptohome: Correctly print attestation preparation status
We can't rely on the sizeof the preparations map as entries with
a status of false are now in the map.
Before this fix:
# cryptohome --action=tpm_attestation_more_status
Attestation Prepared: true
Prepared for the default PCA: false
Prepared for the test PCA: false
Attestation Enrolled: false
#
After:
# cryptohome --action=tpm_attestation_more_status
Attestation Prepared: false
Prepared for the default PCA: false
Prepared for the test PCA: false
Attestation Enrolled: false
#
BUG=chromium:949388
TEST=manual
Change-Id: I6a958223b656b23c6710553ad88946c67980aab7
Reviewed-on: https://chromium-review.googlesource.com/1542502
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Yves Arrouye <drcrash@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
diff --git a/cryptohome/cryptohome.cc b/cryptohome/cryptohome.cc
index b100fd8..f40fafa 100644
--- a/cryptohome/cryptohome.cc
+++ b/cryptohome/cryptohome.cc
@@ -1828,9 +1828,12 @@
cryptohome::AttestationGetEnrollmentPreparationsReply* extension =
reply.MutableExtension(
cryptohome::AttestationGetEnrollmentPreparationsReply::reply);
- printf("Attestation Prepared: %s\n",
- (extension->enrollment_preparations().size() ? "true" : "false"));
auto map = extension->enrollment_preparations();
+ bool prepared = false;
+ for (auto it = map.cbegin(), end = map.cend(); it != end; ++it) {
+ prepared |= it->second;
+ }
+ printf("Attestation Prepared: %s\n", prepared ? "true" : "false");
for (auto it = map.cbegin(), end = map.cend(); it != end; ++it) {
printf(" Prepared for %s: %s\n", GetPCAName(it->first).c_str(),
(it->second ? "true" : "false"));