1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2017-2020, Linaro Limited
4  */
5 
6 #ifndef PKCS11_TA_OBJECT_H
7 #define PKCS11_TA_OBJECT_H
8 
9 #include <pkcs11_ta.h>
10 #include <sys/queue.h>
11 #include <tee_internal_api.h>
12 
13 struct ck_token;
14 struct obj_attrs;
15 struct pkcs11_client;
16 struct pkcs11_session;
17 
18 /*
19  * link: objects are referenced in a double-linked list
20  * attributes: pointer to the serialized object attributes
21  * key_handle: GPD TEE object handle if used in an operation
22  * key_type: GPD TEE key type (shortcut used for processing)
23  * token: associated token for the object
24  * uuid: object UUID in the persistent database if a persistent object, or NULL
25  * attribs_hdl: GPD TEE attributes handles if persistent object
26  */
27 struct pkcs11_object {
28 	LIST_ENTRY(pkcs11_object) link;
29 	struct obj_attrs *attributes;
30 	TEE_ObjectHandle key_handle;
31 	uint32_t key_type;
32 	struct ck_token *token;
33 	TEE_UUID *uuid;
34 	TEE_ObjectHandle attribs_hdl;
35 };
36 
37 LIST_HEAD(object_list, pkcs11_object);
38 
39 struct pkcs11_object *pkcs11_handle2object(uint32_t client_handle,
40 					   struct pkcs11_session *session);
41 
42 uint32_t pkcs11_object2handle(struct pkcs11_object *obj,
43 			      struct pkcs11_session *session);
44 
45 struct pkcs11_object *create_token_object(struct obj_attrs *head,
46 					  TEE_UUID *uuid,
47 					  struct ck_token *token);
48 
49 enum pkcs11_rc create_object(void *session, struct obj_attrs *attributes,
50 			     uint32_t *handle);
51 
52 void cleanup_persistent_object(struct pkcs11_object *obj,
53 			       struct ck_token *token);
54 
55 void destroy_object(struct pkcs11_session *session,
56 		    struct pkcs11_object *object, bool session_object_only);
57 
58 /*
59  * Entry function called from the PKCS11 command parser
60  */
61 enum pkcs11_rc entry_create_object(struct pkcs11_client *client,
62 				   uint32_t ptypes, TEE_Param *params);
63 
64 enum pkcs11_rc entry_destroy_object(struct pkcs11_client *client,
65 				    uint32_t ptypes, TEE_Param *params);
66 
67 enum pkcs11_rc entry_find_objects_init(struct pkcs11_client *client,
68 				       uint32_t ptypes, TEE_Param *params);
69 
70 enum pkcs11_rc entry_find_objects(struct pkcs11_client *client,
71 				  uint32_t ptypes, TEE_Param *params);
72 
73 enum pkcs11_rc entry_find_objects_final(struct pkcs11_client *client,
74 					uint32_t ptypes, TEE_Param *params);
75 
76 enum pkcs11_rc entry_get_attribute_value(struct pkcs11_client *client,
77 					 uint32_t ptypes, TEE_Param *params);
78 
79 enum pkcs11_rc entry_get_object_size(struct pkcs11_client *client,
80 				     uint32_t ptypes, TEE_Param *params);
81 
82 enum pkcs11_rc entry_set_attribute_value(struct pkcs11_client *client,
83 					 uint32_t ptypes, TEE_Param *params);
84 
85 enum pkcs11_rc entry_copy_object(struct pkcs11_client *client, uint32_t ptypes,
86 				 TEE_Param *params);
87 
88 void release_session_find_obj_context(struct pkcs11_session *session);
89 
90 #endif /*PKCS11_TA_OBJECT_H*/
91