Botan
3.6.1
Crypto and TLS for C&
src
lib
prov
tpm2
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
15
using
TPMA_OBJECT
= uint32_t;
16
17
/// Forward declaration of TSS2 type for convenience
18
using
TPMI_ALG_PUBLIC
= uint16_t;
19
20
namespace
Botan::TPM2
{
21
22
struct
PublicInfo;
23
struct
ObjectHandles;
24
class
ObjectSetter;
25
class
SessionBundle;
26
27
/**
28
* See TPM 2.0 Part 2, Section 8.3.2
29
*/
30
struct
ObjectAttributes
{
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
44
bool
sensitive_data_origin
=
false
;
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
57
bool
encrypted_duplication
=
false
;
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
*/
85
class
BOTAN_PUBLIC_API
(3, 6)
Object
{
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
Botan::TPM2::Context
Definition
tpm2_context.h:39
Botan::TPM2::ObjectSetter
Definition
tpm2_util.h:174
Botan::TPM2::Object
Definition
tpm2_object.h:85
Botan::TPM2::Object::context
const std::shared_ptr< Context > & context() const
Definition
tpm2_object.h:110
Botan::TPM2::Object::operator=
Object & operator=(const Object &)=delete
Botan::TPM2::Object::Object
Object(const Object &)=delete
Botan::TPM2::SessionBundle
Definition
tpm2_session.h:173
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition
compiler.h:31
Botan::TPM2
Definition
tpm2_algo_mappings.h:24
Botan::TPM2::ObjectAttributes
Definition
tpm2_object.h:30
Botan::TPM2::ObjectAttributes::no_da
bool no_da
If set, the object is not subject to dictionary attack protection.
Definition
tpm2_object.h:53
Botan::TPM2::ObjectAttributes::fixed_tpm
bool fixed_tpm
The hierarchy of the object may or may not change (i.e. when keys are duplicated)
Definition
tpm2_object.h:35
Botan::TPM2::ObjectAttributes::x509sign
bool x509sign
Definition
tpm2_object.h:72
Botan::TPM2::ObjectAttributes::fixed_parent
bool fixed_parent
The parent of the object may or may not change.
Definition
tpm2_object.h:41
Botan::TPM2::ObjectAttributes::read
static ObjectAttributes read(TPMA_OBJECT attributes)
Definition
tpm2_object.cpp:40
Botan::TPM2::ObjectAttributes::restricted
bool restricted
Definition
tpm2_object.h:61
Botan::TPM2::ObjectAttributes::encrypted_duplication
bool encrypted_duplication
Definition
tpm2_object.h:57
Botan::TPM2::ObjectAttributes::admin_with_policy
bool admin_with_policy
ADMIN role actions may or may not require a policy session.
Definition
tpm2_object.h:50
Botan::TPM2::ObjectAttributes::user_with_auth
bool user_with_auth
USER role actions may or may not be performed without authorization (HMAC or password)
Definition
tpm2_object.h:47
Botan::TPM2::ObjectAttributes::sensitive_data_origin
bool sensitive_data_origin
Indicates that the TPM generated all of the sensitive data other than the authValue.
Definition
tpm2_object.h:44
Botan::TPM2::ObjectAttributes::sign_encrypt
bool sign_encrypt
Definition
tpm2_object.h:68
Botan::TPM2::ObjectAttributes::render
static TPMA_OBJECT render(ObjectAttributes attributes)
Definition
tpm2_object.cpp:44
Botan::TPM2::ObjectAttributes::st_clear
bool st_clear
Saved contexts of this object may or may not be loaded after Startup(CLEAR)
Definition
tpm2_object.h:38
Botan::TPM2::ObjectAttributes::decrypt
bool decrypt
The private portion of the key might be used for data decryption.
Definition
tpm2_object.h:64
Botan::TPM2::ObjectHandles
Definition
tpm2_util.h:162
Botan::TPM2::PublicInfo
Definition
tpm2_util.h:156
ESYS_TR
uint32_t ESYS_TR
Forward declaration of TSS2 type for convenience.
Definition
tpm2_context.h:23
TPM2_HANDLE
uint32_t TPM2_HANDLE
Forward declaration of TSS2 type for convenience.
Definition
tpm2_context.h:20
TPMI_ALG_PUBLIC
uint16_t TPMI_ALG_PUBLIC
Forward declaration of TSS2 type for convenience.
Definition
tpm2_object.h:18
TPMA_OBJECT
uint32_t TPMA_OBJECT
Forward declaration of TSS2 type for convenience.
Definition
tpm2_object.h:15
Generated by
1.12.0