ifapi_keystore.h
/* SPDX-License-Identifier: BSD-2-Clause */
/*******************************************************************************
* Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG
* All rights reserved.
******************************************************************************/
#ifndef IFAPI_KEYSTORE_H
#define IFAPI_KEYSTORE_H
#include <stdlib.h>
#include "tss2_common.h"
#include "tss2_tpm2_types.h"
#include "fapi_types.h"
#include "ifapi_policy_types.h"
#include "tss2_esys.h"
#include "tss2_policy.h"
typedef UINT32 IFAPI_OBJECT_TYPE_CONSTANT;
#define IFAPI_OBJ_NONE 0
#define IFAPI_KEY_OBJ 1
#define IFAPI_NV_OBJ 2
#define IFAPI_EXT_PUB_KEY_OBJ 3
#define IFAPI_HIERARCHY_OBJ 4
#define IFAPI_DUPLICATE_OBJ 5
typedef struct {
UINT32 persistent_handle;
TPM2B_PUBLIC public;
UINT8_ARY serialization;
UINT8_ARY private;
char *policyInstance;
TPM2B_DIGEST creationHash;
TPM2B_CREATION_DATA creationData;
TPMT_TK_CREATION creationTicket;
char *description;
UINT8_ARY appData;
char *certificate;
TPMT_SIG_SCHEME signing_scheme;
TPM2B_NAME name;
TPMI_YES_NO with_auth;
UINT32 reset_count;
TPMI_YES_NO delete_prohibited;
TPMI_YES_NO ek_profile;
TPM2B_DIGEST nonce;
} IFAPI_KEY;
typedef struct {
char *pem_ext_public;
char *certificate;
TPM2B_PUBLIC public;
} IFAPI_EXT_PUB_KEY;
typedef struct {
TPMI_YES_NO with_auth;
char *description;
TPM2B_DIGEST authPolicy;
ESYS_TR esysHandle;
bool authorized;
TPM2B_NAME name;
} IFAPI_HIERARCHY;
typedef struct {
TPM2B_NV_PUBLIC public;
UINT8_ARY serialization;
UINT32 hierarchy;
char *policyInstance;
char *description;
UINT8_ARY appData;
TPMI_YES_NO with_auth;
char* event_log;
} IFAPI_NV;
typedef struct {
TPM2B_PRIVATE duplicate;
TPM2B_ENCRYPTED_SECRET encrypted_seed;
TPM2B_PUBLIC public;
TPM2B_PUBLIC public_parent;
char *certificate;
TPMS_POLICY *policy;
} IFAPI_DUPLICATE;
typedef union {
IFAPI_EXT_PUB_KEY ext_pub_key;
IFAPI_KEY key;
IFAPI_NV nv;
IFAPI_DUPLICATE key_tree;
IFAPI_HIERARCHY hierarchy;
} IFAPI_OBJECT_UNION;
enum FAPI_SEARCH_STATE {
KSEARCH_INIT = 0,
KSEARCH_SEARCH_OBJECT,
KSEARCH_READ
};
typedef struct {
size_t path_idx;
size_t numPaths;
char **pathlist;
enum FAPI_SEARCH_STATE state;
} IFAPI_KEY_SEARCH;
typedef struct IFAPI_KEYSTORE {
char *systemdir;
char *userdir;
char *defaultprofile;
IFAPI_KEY_SEARCH key_search;
const char* rel_path;
} IFAPI_KEYSTORE;
enum IFAPI_AUTHORIZATION_STATE {
AUTH_INIT = 0,
AUTH_CHECK_POLICY,
AUTH_CREATE_SESSION,
AUTH_EXEC_POLICY,
AUTH_FLUSH_OLD_POLICY,
AUTH_DONE
};
enum IFAPI_IO_STATE {
IO_INIT = 0,
IO_ACTIVE,
};
#define TSS2_OBJECT_TO_IFAPI_OBJECT(p) ((IFAPI_OBJECT *)p)
typedef struct _IFAPI_OBJECT {
/* TSS2_OBJECT MUST GO FIRST. In C pointer of first element
* is equal to pointer of base type, use this to hide data by
* only passing pointer to public in callbacks, however, internal
* FAPI code can do a simple upcast it back to the original.
*
* **NOTE**: One could use offset of, and play the same trick
* the linux kernel linked list uses with container_of, but
* since offsetof isn't C99, we won't use it here.
*/
TSS2_OBJECT public;
TPMS_POLICY *policy;
IFAPI_OBJECT_TYPE_CONSTANT objectType;
IFAPI_OBJECT_UNION misc;
TPMI_YES_NO system;
enum IFAPI_AUTHORIZATION_STATE authorization_state;
enum IFAPI_IO_STATE state;
const char *rel_path;
} IFAPI_OBJECT;
TSS2_RC
ifapi_check_valid_path(const char *path);
TSS2_RC
ifapi_keystore_initialize(
IFAPI_KEYSTORE *keystore,
const char *config_systemdir,
const char *config_userdir,
const char *config_defaultprofile);
TSS2_RC
ifapi_keystore_load_async(
IFAPI_KEYSTORE *keystore,
IFAPI_IO *io,
const char *path);
TSS2_RC
ifapi_keystore_load_finish(
IFAPI_KEYSTORE *keystore,
IFAPI_IO *io,
IFAPI_OBJECT *object);
TSS2_RC
ifapi_keystore_object_does_not_exist(
IFAPI_KEYSTORE *keystore,
const char *path,
const IFAPI_OBJECT *object);
TSS2_RC
ifapi_keystore_store_async(
IFAPI_KEYSTORE *keystore,
IFAPI_IO *io,
const char *path,
const IFAPI_OBJECT *object);
TSS2_RC
ifapi_keystore_store_finish(
IFAPI_IO *io);
TSS2_RC
ifapi_keystore_list_all(
IFAPI_KEYSTORE *keystore,
const char *searchpath,
char ***results,
size_t *numresults);
TSS2_RC
ifapi_keystore_delete(
IFAPI_KEYSTORE *keystore,
char *path);
TSS2_RC
ifapi_keystore_remove_directories(
IFAPI_KEYSTORE *keystore,
const char *dir_name);
TSS2_RC
ifapi_keystore_search_obj(
IFAPI_KEYSTORE *keystore,
IFAPI_IO *io,
TPM2B_NAME *name,
char **found_path);
TSS2_RC
ifapi_keystore_search_nv_obj(
IFAPI_KEYSTORE *keystore,
IFAPI_IO *io,
TPM2B_NV_PUBLIC *nv_public,
char **found_path);
TSS2_RC
ifapi_keystore_check_overwrite(
IFAPI_KEYSTORE *keystore,
const char *path);
TSS2_RC
ifapi_keystore_check_writeable(
IFAPI_KEYSTORE *keystore,
const char *path);
TSS2_RC
ifapi_copy_ifapi_key(
IFAPI_KEY * dest,
const IFAPI_KEY * src);
TSS2_RC
ifapi_copy_ifapi_hierarchy(
IFAPI_HIERARCHY * dest,
const IFAPI_HIERARCHY * src);
TSS2_RC
ifapi_copy_ifapi_key_object(
IFAPI_OBJECT * dest,
const IFAPI_OBJECT * src);
TSS2_RC
ifapi_copy_ifapi_hierarchy_object(
IFAPI_OBJECT * dest,
const IFAPI_OBJECT * src);
void ifapi_cleanup_ifapi_key(
IFAPI_KEY * key);
void ifapi_cleanup_ifapi_ext_pub_key(
IFAPI_EXT_PUB_KEY * key);
void ifapi_cleanup_ifapi_hierarchy(
IFAPI_HIERARCHY * hierarchy);
void ifapi_cleanup_ifapi_nv(
IFAPI_NV * nv);
void ifapi_cleanup_ifapi_duplicate(
IFAPI_DUPLICATE * duplicate);
void ifapi_cleanup_ifapi_key_search(
IFAPI_KEY_SEARCH * key_search);
void ifapi_cleanup_ifapi_keystore(
IFAPI_KEYSTORE * keystore);
void
ifapi_cleanup_ifapi_object(
IFAPI_OBJECT *object);
TSS2_RC
ifapi_check_provisioned(
IFAPI_KEYSTORE *keystore,
const char *rel_path,
bool *ok);
#endif /* IFAPI_KEYSTORE_H */
ESYS_TR
uint32_t ESYS_TR
Definition tss2_esys.h:16
ifapi_copy_ifapi_key_object
TSS2_RC ifapi_copy_ifapi_key_object(IFAPI_OBJECT *dest, const IFAPI_OBJECT *src)
Definition ifapi_keystore.c:1638
ifapi_keystore_search_obj
TSS2_RC ifapi_keystore_search_obj(IFAPI_KEYSTORE *keystore, IFAPI_IO *io, TPM2B_NAME *name, char **found_path)
Definition ifapi_keystore.c:1244
ifapi_keystore_object_does_not_exist
TSS2_RC ifapi_keystore_object_does_not_exist(IFAPI_KEYSTORE *keystore, const char *path, const IFAPI_OBJECT *object)
Definition ifapi_keystore.c:753
ifapi_copy_ifapi_key
TSS2_RC ifapi_copy_ifapi_key(IFAPI_KEY *dest, const IFAPI_KEY *src)
Definition ifapi_keystore.c:1455
ifapi_keystore_load_async
TSS2_RC ifapi_keystore_load_async(IFAPI_KEYSTORE *keystore, IFAPI_IO *io, const char *path)
Definition ifapi_keystore.c:564
ifapi_keystore_delete
TSS2_RC ifapi_keystore_delete(IFAPI_KEYSTORE *keystore, char *path)
Definition ifapi_keystore.c:959
ifapi_keystore_remove_directories
TSS2_RC ifapi_keystore_remove_directories(IFAPI_KEYSTORE *keystore, const char *dir_name)
Definition ifapi_keystore.c:1042
ifapi_keystore_search_nv_obj
TSS2_RC ifapi_keystore_search_nv_obj(IFAPI_KEYSTORE *keystore, IFAPI_IO *io, TPM2B_NV_PUBLIC *nv_public, char **found_path)
Definition ifapi_keystore.c:1282
ifapi_keystore_list_all
TSS2_RC ifapi_keystore_list_all(IFAPI_KEYSTORE *keystore, const char *searchpath, char ***results, size_t *numresults)
Definition ifapi_keystore.c:920
ifapi_keystore_initialize
TSS2_RC ifapi_keystore_initialize(IFAPI_KEYSTORE *keystore, const char *config_systemdir, const char *config_userdir, const char *config_defaultprofile)
Definition ifapi_keystore.c:423
ifapi_cleanup_ifapi_hierarchy
void ifapi_cleanup_ifapi_hierarchy(IFAPI_HIERARCHY *hierarchy)
Definition ifapi_keystore.c:1573
ifapi_cleanup_ifapi_ext_pub_key
void ifapi_cleanup_ifapi_ext_pub_key(IFAPI_EXT_PUB_KEY *key)
Definition ifapi_keystore.c:1559
ifapi_cleanup_ifapi_object
void ifapi_cleanup_ifapi_object(IFAPI_OBJECT *object)
Definition ifapi_keystore.c:1726
ifapi_copy_ifapi_hierarchy_object
TSS2_RC ifapi_copy_ifapi_hierarchy_object(IFAPI_OBJECT *dest, const IFAPI_OBJECT *src)
Definition ifapi_keystore.c:1686
ifapi_cleanup_ifapi_keystore
void ifapi_cleanup_ifapi_keystore(IFAPI_KEYSTORE *keystore)
Definition ifapi_keystore.c:1616
ifapi_copy_ifapi_hierarchy
TSS2_RC ifapi_copy_ifapi_hierarchy(IFAPI_HIERARCHY *dest, const IFAPI_HIERARCHY *src)
Definition ifapi_keystore.c:1511
ifapi_keystore_store_async
TSS2_RC ifapi_keystore_store_async(IFAPI_KEYSTORE *keystore, IFAPI_IO *io, const char *path, const IFAPI_OBJECT *object)
Definition ifapi_keystore.c:674
ifapi_cleanup_ifapi_duplicate
void ifapi_cleanup_ifapi_duplicate(IFAPI_DUPLICATE *duplicate)
Definition ifapi_keystore.c:1603
ifapi_cleanup_ifapi_key
void ifapi_cleanup_ifapi_key(IFAPI_KEY *key)
Definition ifapi_keystore.c:1541
ifapi_cleanup_ifapi_nv
void ifapi_cleanup_ifapi_nv(IFAPI_NV *nv)
Definition ifapi_keystore.c:1586
_IFAPI_OBJECT
Definition ifapi_keystore.h:150
_IFAPI_OBJECT::system
TPMI_YES_NO system
Definition ifapi_keystore.h:164
_IFAPI_OBJECT::authorization_state
enum IFAPI_AUTHORIZATION_STATE authorization_state
Definition ifapi_keystore.h:166
_IFAPI_OBJECT::rel_path
const char * rel_path
Definition ifapi_keystore.h:168
_IFAPI_OBJECT::misc
IFAPI_OBJECT_UNION misc
Definition ifapi_keystore.h:163
_IFAPI_OBJECT::objectType
IFAPI_OBJECT_TYPE_CONSTANT objectType
Definition ifapi_keystore.h:162
IFAPI_DUPLICATE
Definition ifapi_keystore.h:85
IFAPI_DUPLICATE::duplicate
TPM2B_PRIVATE duplicate
Definition ifapi_keystore.h:87
IFAPI_DUPLICATE::policy
TPMS_POLICY * policy
Definition ifapi_keystore.h:92
IFAPI_DUPLICATE::encrypted_seed
TPM2B_ENCRYPTED_SECRET encrypted_seed
Definition ifapi_keystore.h:88
IFAPI_DUPLICATE::public_parent
TPM2B_PUBLIC public_parent
Definition ifapi_keystore.h:90
IFAPI_DUPLICATE::certificate
char * certificate
Definition ifapi_keystore.h:91
IFAPI_EXT_PUB_KEY
Definition ifapi_keystore.h:53
IFAPI_EXT_PUB_KEY::pem_ext_public
char * pem_ext_public
Definition ifapi_keystore.h:54
IFAPI_EXT_PUB_KEY::certificate
char * certificate
Definition ifapi_keystore.h:55
IFAPI_HIERARCHY
Definition ifapi_keystore.h:61
IFAPI_HIERARCHY::authorized
bool authorized
Definition ifapi_keystore.h:66
IFAPI_HIERARCHY::with_auth
TPMI_YES_NO with_auth
Definition ifapi_keystore.h:62
IFAPI_HIERARCHY::description
char * description
Definition ifapi_keystore.h:63
IFAPI_HIERARCHY::name
TPM2B_NAME name
Definition ifapi_keystore.h:67
IFAPI_IO
Definition ifapi_io.h:15
IFAPI_KEY_SEARCH
Definition ifapi_keystore.h:114
IFAPI_KEY_SEARCH::pathlist
char ** pathlist
Definition ifapi_keystore.h:117
IFAPI_KEY_SEARCH::numPaths
size_t numPaths
Definition ifapi_keystore.h:116
IFAPI_KEY_SEARCH::path_idx
size_t path_idx
Definition ifapi_keystore.h:115
IFAPI_KEY
Definition ifapi_keystore.h:29
IFAPI_KEY::policyInstance
char * policyInstance
Definition ifapi_keystore.h:34
IFAPI_KEY::serialization
UINT8_ARY serialization
Definition ifapi_keystore.h:32
IFAPI_KEY::ek_profile
TPMI_YES_NO ek_profile
Definition ifapi_keystore.h:46
IFAPI_KEY::persistent_handle
UINT32 persistent_handle
Definition ifapi_keystore.h:30
IFAPI_KEY::creationData
TPM2B_CREATION_DATA creationData
Definition ifapi_keystore.h:36
IFAPI_KEY::delete_prohibited
TPMI_YES_NO delete_prohibited
Definition ifapi_keystore.h:45
IFAPI_KEY::with_auth
TPMI_YES_NO with_auth
Definition ifapi_keystore.h:43
IFAPI_KEY::nonce
TPM2B_DIGEST nonce
Definition ifapi_keystore.h:48
IFAPI_KEY::creationHash
TPM2B_DIGEST creationHash
Definition ifapi_keystore.h:35
IFAPI_KEY::description
char * description
Definition ifapi_keystore.h:38
IFAPI_KEY::reset_count
UINT32 reset_count
Definition ifapi_keystore.h:44
IFAPI_KEY::name
TPM2B_NAME name
Definition ifapi_keystore.h:42
IFAPI_KEY::appData
UINT8_ARY appData
Definition ifapi_keystore.h:39
IFAPI_KEY::certificate
char * certificate
Definition ifapi_keystore.h:40
IFAPI_KEY::creationTicket
TPMT_TK_CREATION creationTicket
Definition ifapi_keystore.h:37
IFAPI_KEY::signing_scheme
TPMT_SIG_SCHEME signing_scheme
Definition ifapi_keystore.h:41
IFAPI_KEYSTORE
Definition ifapi_keystore.h:121
IFAPI_NV
Definition ifapi_keystore.h:72
IFAPI_NV::policyInstance
char * policyInstance
Definition ifapi_keystore.h:76
IFAPI_NV::serialization
UINT8_ARY serialization
Definition ifapi_keystore.h:74
IFAPI_NV::with_auth
TPMI_YES_NO with_auth
Definition ifapi_keystore.h:79
IFAPI_NV::hierarchy
UINT32 hierarchy
Definition ifapi_keystore.h:75
IFAPI_NV::description
char * description
Definition ifapi_keystore.h:77
IFAPI_NV::appData
UINT8_ARY appData
Definition ifapi_keystore.h:78
IFAPI_NV::event_log
char * event_log
Definition ifapi_keystore.h:80
TPMS_POLICY
Definition ifapi_policy_types.h:275
UINT8_ARY
Definition fapi_types.h:15
IFAPI_OBJECT_UNION
Definition ifapi_keystore.h:97
IFAPI_OBJECT_UNION::hierarchy
IFAPI_HIERARCHY hierarchy
Definition ifapi_keystore.h:102
IFAPI_OBJECT_UNION::key
IFAPI_KEY key
Definition ifapi_keystore.h:99
IFAPI_OBJECT_UNION::ext_pub_key
IFAPI_EXT_PUB_KEY ext_pub_key
Definition ifapi_keystore.h:98
IFAPI_OBJECT_UNION::key_tree
IFAPI_DUPLICATE key_tree
Definition ifapi_keystore.h:101
IFAPI_OBJECT_UNION::nv
IFAPI_NV nv
Definition ifapi_keystore.h:100