Home | History | Annotate | Download | only in server
      1 //
      2 // Copyright (C) 2015 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 TPM_MANAGER_SERVER_TPM_NVRAM_IMPL_H_
     18 #define TPM_MANAGER_SERVER_TPM_NVRAM_IMPL_H_
     19 
     20 #include "tpm_manager/server/tpm_nvram.h"
     21 
     22 #include <stdint.h>
     23 
     24 #include <string>
     25 
     26 #include <base/macros.h>
     27 #include <trousers/scoped_tss_type.h>
     28 #include <trousers/tss.h>
     29 
     30 #include "tpm_manager/server/tpm_connection.h"
     31 
     32 namespace tpm_manager {
     33 
     34 class LocalDataStore;
     35 
     36 class TpmNvramImpl : public TpmNvram {
     37  public:
     38   TpmNvramImpl(LocalDataStore* local_data_store);
     39   ~TpmNvramImpl() override = default;
     40 
     41   // TpmNvram methods.
     42   bool DefineNvram(uint32_t index, size_t length) override;
     43   bool DestroyNvram(uint32_t index) override;
     44   bool WriteNvram(uint32_t index, const std::string& data) override;
     45   bool ReadNvram(uint32_t index, std::string* data) override;
     46   bool IsNvramDefined(uint32_t index, bool* defined) override;
     47   bool IsNvramLocked(uint32_t index, bool* locked) override;
     48   bool GetNvramSize(uint32_t index, size_t* size) override;
     49 
     50  private:
     51   // This method creates and initializes the nvram object associated with
     52   // |handle| at |index|. Returns true on success, else false.
     53   bool InitializeNvramHandle(trousers::ScopedTssNvStore* nv_handle,
     54                              uint32_t index);
     55 
     56   // This method injects a tpm policy with the owner password. Returns true
     57   // on success.
     58   bool SetOwnerPolicy(trousers::ScopedTssNvStore* nv_handle);
     59 
     60   // This method sets up the composite pcr provided by |pcr_handle| with the
     61   // value of PCR0 at locality 1. Returns true on success.
     62   bool SetCompositePcr0(trousers::ScopedTssPcrs* pcr_handle);
     63 
     64   // This method gets the owner password stored on disk and returns it via the
     65   // out argument |owner_password|. Returns true if we were able to read a
     66   // non empty owner_password off disk, else false.
     67   bool GetOwnerPassword(std::string* owner_password);
     68 
     69   LocalDataStore* local_data_store_;
     70   TpmConnection tpm_connection_;
     71 
     72   DISALLOW_COPY_AND_ASSIGN(TpmNvramImpl);
     73 };
     74 
     75 }  // namespace tpm_manager
     76 
     77 #endif  // TPM_MANAGER_SERVER_TPM_NVRAM_IMPL_H_
     78