blob: 017cfaa82b0dcdb5066bf1aee418cc83a49a39e0 [file] [log] [blame]
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TPM_SOFTCLEAR_UTILS_TPM_H_
#define TPM_SOFTCLEAR_UTILS_TPM_H_
#include <vector>
#include <base/macros.h>
#include <base/optional.h>
namespace tpm_softclear_utils {
// Interface for soft-clearing TPM utilities.
class Tpm {
public:
Tpm() = default;
virtual ~Tpm() = default;
// Gets the authentication value for soft-clearing TPM owner from an on-disk
// file. The auth value in TPM 1.2 and 2.0 are different. Check the child
// classes for details.
//
// If the file doesn't exist, returns the default password. Note that the file
// not existing doesn't necessarily mean an error. It might just mean the TPM
// is already soft-cleared.
//
// Returns an empty Optional object if failing to read the file.
//
// This function doesn't check if the password, either default or from a file,
// works. Callers need to figure it out by themselves.
virtual base::Optional<std::vector<uint8_t>> GetAuthForOwnerReset() = 0;
// Resets TPM's owner hierarchy (and endorsement hierarchy for 2.0) using the
// given auth value |auth_for_owner_reset| and returns if the TPM is
// soft-cleared successfully. Implementation details for TPM 1.2 and 2.0 may
// vary. Check the function descriptions in the child classes for details.
virtual bool SoftClearOwner(
const std::vector<uint8_t>& auth_for_owner_reset) = 0;
// Creates a new TpmImpl or Tpm2Impl object, according to which
// version the TPM is, and returns the pointer to the new object.
static Tpm* Create();
private:
DISALLOW_COPY_AND_ASSIGN(Tpm);
};
} // namespace tpm_softclear_utils
#endif // TPM_SOFTCLEAR_UTILS_TPM_H_