1
2 /*
3 * Licensed Materials - Property of IBM
4 *
5 * trousers - An open source TCG Software Stack
6 *
7 * (C) Copyright International Business Machines Corp. 2004-2007
8 *
9 */
10
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <time.h>
16 #include <errno.h>
17
18 #include "trousers/tss.h"
19 #include "trousers/trousers.h"
20 #include "trousers_types.h"
21 #include "trousers_types.h"
22 #include "spi_utils.h"
23 #include "capabilities.h"
24 #include "tsplog.h"
25 #include "obj.h"
26
27
28 TSS_RESULT
Tspi_GetPolicyObject(TSS_HOBJECT hObject,TSS_FLAG policyType,TSS_HPOLICY * phPolicy)29 Tspi_GetPolicyObject(TSS_HOBJECT hObject, /* in */
30 TSS_FLAG policyType, /* in */
31 TSS_HPOLICY * phPolicy) /* out */
32 {
33 TSS_RESULT result;
34
35 if (phPolicy == NULL)
36 return TSPERR(TSS_E_BAD_PARAMETER);
37
38 if (obj_is_tpm(hObject)) {
39 result = obj_tpm_get_policy(hObject, policyType, phPolicy);
40 #ifdef TSS_BUILD_NV
41 } else if (obj_is_nvstore(hObject)) {
42 result = obj_nvstore_get_policy(hObject, policyType, phPolicy);
43 #endif
44 #ifdef TSS_BUILD_RSAKEY_LIST
45 } else if (obj_is_rsakey(hObject)) {
46 result = obj_rsakey_get_policy(hObject, policyType, phPolicy, NULL);
47 #endif
48 #ifdef TSS_BUILD_ENCDATA_LIST
49 } else if (obj_is_encdata(hObject)) {
50 result = obj_encdata_get_policy(hObject, policyType, phPolicy);
51 #endif
52 } else {
53 if (obj_is_policy(hObject) || obj_is_hash(hObject) ||
54 obj_is_pcrs(hObject) || obj_is_context(hObject))
55 result = TSPERR(TSS_E_BAD_PARAMETER);
56 else
57 result = TSPERR(TSS_E_INVALID_HANDLE);
58 }
59
60 if (result == TSS_SUCCESS && *phPolicy == NULL_HPOLICY)
61 result = TSPERR(TSS_E_INTERNAL_ERROR);
62
63 return result;
64 }
65
66 TSS_RESULT
Tspi_Policy_SetSecret(TSS_HPOLICY hPolicy,TSS_FLAG secretMode,UINT32 ulSecretLength,BYTE * rgbSecret)67 Tspi_Policy_SetSecret(TSS_HPOLICY hPolicy, /* in */
68 TSS_FLAG secretMode, /* in */
69 UINT32 ulSecretLength, /* in */
70 BYTE * rgbSecret) /* in */
71 {
72 TSS_RESULT result;
73 TSS_HCONTEXT tspContext;
74
75 if ((result = obj_policy_get_tsp_context(hPolicy, &tspContext)))
76 return result;
77
78 if (obj_context_is_silent(tspContext) && secretMode == TSS_SECRET_MODE_POPUP)
79 return TSPERR(TSS_E_SILENT_CONTEXT);
80
81 return obj_policy_set_secret(hPolicy, secretMode, ulSecretLength, rgbSecret);
82 }
83
84 TSS_RESULT
Tspi_Policy_FlushSecret(TSS_HPOLICY hPolicy)85 Tspi_Policy_FlushSecret(TSS_HPOLICY hPolicy) /* in */
86 {
87 return obj_policy_flush_secret(hPolicy);
88 }
89
90 TSS_RESULT
Tspi_Policy_AssignToObject(TSS_HPOLICY hPolicy,TSS_HOBJECT hObject)91 Tspi_Policy_AssignToObject(TSS_HPOLICY hPolicy, /* in */
92 TSS_HOBJECT hObject) /* in */
93 {
94 TSS_RESULT result;
95
96 if (obj_is_tpm(hObject)) {
97 result = obj_tpm_set_policy(hObject, hPolicy);
98 #ifdef TSS_BUILD_NV
99 } else if (obj_is_nvstore(hObject)) {
100 result = obj_nvstore_set_policy(hObject, hPolicy);
101 #endif
102 #ifdef TSS_BUILD_RSAKEY_LIST
103 } else if (obj_is_rsakey(hObject)) {
104 result = obj_rsakey_set_policy(hObject, hPolicy);
105 #endif
106 #ifdef TSS_BUILD_ENCDATA_LIST
107 } else if (obj_is_encdata(hObject)) {
108 result = obj_encdata_set_policy(hObject, hPolicy);
109 #endif
110 } else {
111 result = TSPERR(TSS_E_BAD_PARAMETER);
112 }
113
114 return result;
115 }
116