Botan 3.6.1
Crypto and TLS for C&
tpm2_object.h
Go to the documentation of this file.
1/*
2* TPM 2.0 Base Object handling
3* (C) 2024 Jack Lloyd
4* (C) 2024 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity GmbH, financed by LANCOM Systems GmbH
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TPM2_BASE_OBJECT_H_
10#define BOTAN_TPM2_BASE_OBJECT_H_
11
12#include <botan/tpm2_context.h>
13
14/// Forward declaration of TSS2 type for convenience
15using TPMA_OBJECT = uint32_t;
16
17/// Forward declaration of TSS2 type for convenience
18using TPMI_ALG_PUBLIC = uint16_t;
19
20namespace Botan::TPM2 {
21
22struct PublicInfo;
23struct ObjectHandles;
24class ObjectSetter;
25class SessionBundle;
26
27/**
28 * See TPM 2.0 Part 2, Section 8.3.2
29 */
31 static ObjectAttributes read(TPMA_OBJECT attributes);
32 static TPMA_OBJECT render(ObjectAttributes attributes);
33
34 /// The hierarchy of the object may or may not change (i.e. when keys are duplicated)
35 bool fixed_tpm = false;
36
37 /// Saved contexts of this object may or may not be loaded after Startup(CLEAR)
38 bool st_clear = false;
39
40 /// The parent of the object may or may not change
41 bool fixed_parent = false;
42
43 /// Indicates that the TPM generated all of the sensitive data other than the authValue
45
46 /// USER role actions may or may not be performed without authorization (HMAC or password)
47 bool user_with_auth = false;
48
49 /// ADMIN role actions may or may not require a policy session
50 bool admin_with_policy = false;
51
52 /// If set, the object is not subject to dictionary attack protection
53 bool no_da = false;
54
55 /// If not set, the object may be duplicated without an inner wrapper on the private portion
56 /// Otherwise, symmetricAlg must not be TPM_ALG_NULL and newParentHandle must not be TPM_RH_NULL
58
59 /// Key usage is restricted to structures of known format
60 /// (e.g. it won't sign data whose hash was not calculated by the TPM)
61 bool restricted = false;
62
63 /// The private portion of the key might be used for data decryption
64 bool decrypt = false;
65
66 /// The private portion of the key might be used for data signing, or
67 /// data encryption (if the key is a symmetric key)
68 bool sign_encrypt = false;
69
70 /// The private portion of the key might be used for X.509 certificate signing
71 /// (normal signing, via Esys_Sign(), of arbitrary data is not allowed)
72 bool x509sign = false;
73};
74
75/**
76 * Wraps and manages the lifetime of TPM2 object handles both for transient and
77 * persistent objects. When this object is destroyed, the handles are released
78 * accordingly.
79 *
80 * Note that some TSS2 library functions may internally release handles passed
81 * to them. In such cases, the Object instance can be disengaged, ensuring that
82 * the handles are not released twice. This is an internal functionality and
83 * should not be used directly.
84 */
86 public:
87 explicit Object(std::shared_ptr<Context> ctx);
88
89 /**
90 * Create an object wrapper from a user-provided transient handle.
91 *
92 * Use this to wrap an externally created transient object handle
93 * into a Botan::TPM2::Object instance. This is useful when the object
94 * is created by the application and not by the Botan::TPM2 library.
95 *
96 * Note that this will take ownership of the ESYS_TR handle and will
97 * release it when the object is destroyed.
98 *
99 * @param ctx the TPM context to use
100 * @param handle the transient handle to wrap
101 */
102 Object(std::shared_ptr<Context> ctx, ESYS_TR handle);
103
104 virtual ~Object();
105 Object(const Object&) = delete;
106 Object& operator=(const Object&) = delete;
107 Object(Object&& other) noexcept;
108 Object& operator=(Object&& other) noexcept;
109
110 const std::shared_ptr<Context>& context() const { return m_ctx; }
111
112 bool has_persistent_handle() const;
113 bool has_transient_handle() const;
114
115 TPM2_HANDLE persistent_handle() const;
116 ESYS_TR transient_handle() const noexcept;
117
118 ObjectAttributes attributes(const SessionBundle& sessions) const;
119
120 void _reset() noexcept;
121 void _disengage() noexcept;
122 PublicInfo& _public_info(const SessionBundle& sessions, std::optional<TPMI_ALG_PUBLIC> expected_type = {}) const;
123
124 private:
125 friend class ObjectSetter;
126 ObjectHandles& handles();
127
128 void flush() const noexcept;
129 void scrub();
130
131 private:
132 std::shared_ptr<Context> m_ctx;
133 std::unique_ptr<ObjectHandles> m_handles;
134 mutable std::unique_ptr<PublicInfo> m_public_info;
135};
136
137} // namespace Botan::TPM2
138
139#endif
const std::shared_ptr< Context > & context() const
Object & operator=(const Object &)=delete
Object(const Object &)=delete
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
bool no_da
If set, the object is not subject to dictionary attack protection.
Definition tpm2_object.h:53
bool fixed_tpm
The hierarchy of the object may or may not change (i.e. when keys are duplicated)
Definition tpm2_object.h:35
bool fixed_parent
The parent of the object may or may not change.
Definition tpm2_object.h:41
static ObjectAttributes read(TPMA_OBJECT attributes)
bool admin_with_policy
ADMIN role actions may or may not require a policy session.
Definition tpm2_object.h:50
bool user_with_auth
USER role actions may or may not be performed without authorization (HMAC or password)
Definition tpm2_object.h:47
bool sensitive_data_origin
Indicates that the TPM generated all of the sensitive data other than the authValue.
Definition tpm2_object.h:44
static TPMA_OBJECT render(ObjectAttributes attributes)
bool st_clear
Saved contexts of this object may or may not be loaded after Startup(CLEAR)
Definition tpm2_object.h:38
bool decrypt
The private portion of the key might be used for data decryption.
Definition tpm2_object.h:64
uint32_t ESYS_TR
Forward declaration of TSS2 type for convenience.
uint32_t TPM2_HANDLE
Forward declaration of TSS2 type for convenience.
uint16_t TPMI_ALG_PUBLIC
Forward declaration of TSS2 type for convenience.
Definition tpm2_object.h:18
uint32_t TPMA_OBJECT
Forward declaration of TSS2 type for convenience.
Definition tpm2_object.h:15