cryptohome: don't reinitialize install attributes

The install attributes would check failed when initialezed twice.

BUG=b:163736530
TEST=FEATURES=test emerge-soraka cryptohome
TEST=tast run $DUT hwsec.Attestation* hwsec.Chaps* hwsec.Cryptohome*
TEST=Manually enroll, login, logout on soraka

Change-Id: I6fa2e7abf7e14390bf00cbfa6d1338ca21d9798f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2498167
Tested-by: joe Chou <yich@google.com>
Commit-Queue: joe Chou <yich@google.com>
Reviewed-by: Leo Lai <cylai@google.com>
diff --git a/cryptohome/service.cc b/cryptohome/service.cc
index f815d6c..0cedec9 100644
--- a/cryptohome/service.cc
+++ b/cryptohome/service.cc
@@ -851,6 +851,11 @@
 }
 
 void Service::InitializeInstallAttributes() {
+  // Don't reinitialize when install attributes are valid.
+  if (install_attrs_->status() == InstallAttributes::Status::kValid) {
+    return;
+  }
+
   // The TPM owning instance may have changed since initialization.
   // InstallAttributes can handle a NULL or !IsEnabled Tpm object.
   install_attrs_->SetTpm(tpm_);
diff --git a/cryptohome/userdataauth.cc b/cryptohome/userdataauth.cc
index 7f63d12..26a82d8 100644
--- a/cryptohome/userdataauth.cc
+++ b/cryptohome/userdataauth.cc
@@ -1037,6 +1037,11 @@
 void UserDataAuth::InitializeInstallAttributes() {
   AssertOnOriginThread();
 
+  // Don't reinitialize when install attributes are valid.
+  if (install_attrs_->status() == InstallAttributes::Status::kValid) {
+    return;
+  }
+
   // The TPM owning instance may have changed since initialization.
   // InstallAttributes can handle a NULL or !IsEnabled Tpm object.
   install_attrs_->SetTpm(tpm_);