Home | History | Annotate | Download | only in trunks
      1 //
      2 // Copyright (C) 2014 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #ifndef TRUNKS_TPM_STATE_IMPL_H_
     18 #define TRUNKS_TPM_STATE_IMPL_H_
     19 
     20 #include "trunks/tpm_state.h"
     21 
     22 #include <base/macros.h>
     23 
     24 #include "trunks/tpm_generated.h"
     25 #include "trunks/trunks_export.h"
     26 
     27 namespace trunks {
     28 
     29 class TrunksFactory;
     30 
     31 // TpmStateImpl is the default implementation of the TpmState interface.
     32 class TRUNKS_EXPORT TpmStateImpl : public TpmState {
     33  public:
     34   explicit TpmStateImpl(const TrunksFactory& factory);
     35   ~TpmStateImpl() override;
     36 
     37   // TpmState methods.
     38   TPM_RC Initialize() override;
     39   bool IsOwnerPasswordSet() override;
     40   bool IsEndorsementPasswordSet() override;
     41   bool IsLockoutPasswordSet() override;
     42   bool IsOwned() override;
     43   bool IsInLockout() override;
     44   bool IsPlatformHierarchyEnabled() override;
     45   bool IsStorageHierarchyEnabled() override;
     46   bool IsEndorsementHierarchyEnabled() override;
     47   bool IsEnabled() override;
     48   bool WasShutdownOrderly() override;
     49   bool IsRSASupported() override;
     50   bool IsECCSupported() override;
     51   uint32_t GetLockoutCounter() override;
     52   uint32_t GetLockoutThreshold() override;
     53   uint32_t GetLockoutInterval() override;
     54   uint32_t GetLockoutRecovery() override;
     55 
     56  private:
     57   // This helped method calls Tpm2_GetCapability with TPM_CAP_TPM_PROPERTIES
     58   // and |property|. The returned structure is validated, and the value returned
     59   // is stored in the out argument |value|. Returns TPM_RC_SUCCESS on success.
     60   TPM_RC GetTpmProperty(uint32_t property, uint32_t* value);
     61 
     62   const TrunksFactory& factory_;
     63   bool initialized_;
     64   TPMA_PERMANENT permanent_flags_;
     65   TPMA_STARTUP_CLEAR startup_clear_flags_;
     66   uint32_t lockout_counter_;
     67   uint32_t lockout_threshold_;
     68   uint32_t lockout_interval_;
     69   uint32_t lockout_recovery_;
     70   TPMA_ALGORITHM rsa_flags_;
     71   TPMA_ALGORITHM ecc_flags_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(TpmStateImpl);
     74 };
     75 
     76 }  // namespace trunks
     77 
     78 #endif  // TRUNKS_TPM_STATE_IMPL_H_
     79