1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3 * Copyright (c) 2015 - 2017, Intel Corporation
4 * All rights reserved.
5 ***********************************************************************/
6
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include "tss2_tpm2_types.h"
12 #include "tss2_mu.h"
13 #include "sysapi_util.h"
14
Tss2_Sys_PolicyTicket_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,const TPM2B_TIMEOUT * timeout,const TPM2B_DIGEST * cpHashA,const TPM2B_NONCE * policyRef,const TPM2B_NAME * authName,const TPMT_TK_AUTH * ticket)15 TSS2_RC Tss2_Sys_PolicyTicket_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_SH_POLICY policySession,
18 const TPM2B_TIMEOUT *timeout,
19 const TPM2B_DIGEST *cpHashA,
20 const TPM2B_NONCE *policyRef,
21 const TPM2B_NAME *authName,
22 const TPMT_TK_AUTH *ticket)
23 {
24 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
25 TSS2_RC rval;
26
27 if (!ctx || !ticket)
28 return TSS2_SYS_RC_BAD_REFERENCE;
29
30 rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyTicket);
31 if (rval)
32 return rval;
33
34 rval = Tss2_MU_UINT32_Marshal(policySession, ctx->cmdBuffer,
35 ctx->maxCmdSize,
36 &ctx->nextData);
37 if (rval)
38 return rval;
39
40 if (!timeout) {
41 ctx->decryptNull = 1;
42
43 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
44 ctx->maxCmdSize,
45 &ctx->nextData);
46 } else {
47
48 rval = Tss2_MU_TPM2B_TIMEOUT_Marshal(timeout, ctx->cmdBuffer,
49 ctx->maxCmdSize,
50 &ctx->nextData);
51 }
52
53 if (rval)
54 return rval;
55
56 if (!cpHashA) {
57 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
58 ctx->maxCmdSize,
59 &ctx->nextData);
60
61 } else {
62
63 rval = Tss2_MU_TPM2B_DIGEST_Marshal(cpHashA, ctx->cmdBuffer,
64 ctx->maxCmdSize,
65 &ctx->nextData);
66 }
67
68 if (rval)
69 return rval;
70
71 if (!policyRef) {
72 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
73 ctx->maxCmdSize,
74 &ctx->nextData);
75
76 } else {
77
78 rval = Tss2_MU_TPM2B_NONCE_Marshal(policyRef, ctx->cmdBuffer,
79 ctx->maxCmdSize,
80 &ctx->nextData);
81 }
82
83 if (rval)
84 return rval;
85
86 if (!authName) {
87 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
88 ctx->maxCmdSize,
89 &ctx->nextData);
90
91 } else {
92
93 rval = Tss2_MU_TPM2B_NAME_Marshal(authName, ctx->cmdBuffer,
94 ctx->maxCmdSize,
95 &ctx->nextData);
96 }
97
98 if (rval)
99 return rval;
100
101 rval = Tss2_MU_TPMT_TK_AUTH_Marshal(ticket, ctx->cmdBuffer,
102 ctx->maxCmdSize,
103 &ctx->nextData);
104 if (rval)
105 return rval;
106
107 ctx->decryptAllowed = 1;
108 ctx->encryptAllowed = 0;
109 ctx->authAllowed = 1;
110
111 return CommonPrepareEpilogue(ctx);
112 }
113
Tss2_Sys_PolicyTicket_Complete(TSS2_SYS_CONTEXT * sysContext)114 TSS2_RC Tss2_Sys_PolicyTicket_Complete (
115 TSS2_SYS_CONTEXT *sysContext)
116 {
117 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
118
119 if (!ctx)
120 return TSS2_SYS_RC_BAD_REFERENCE;
121
122 return CommonComplete(ctx);
123 }
124
Tss2_Sys_PolicyTicket(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_TIMEOUT * timeout,const TPM2B_DIGEST * cpHashA,const TPM2B_NONCE * policyRef,const TPM2B_NAME * authName,const TPMT_TK_AUTH * ticket,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)125 TSS2_RC Tss2_Sys_PolicyTicket(
126 TSS2_SYS_CONTEXT *sysContext,
127 TPMI_SH_POLICY policySession,
128 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
129 const TPM2B_TIMEOUT *timeout,
130 const TPM2B_DIGEST *cpHashA,
131 const TPM2B_NONCE *policyRef,
132 const TPM2B_NAME *authName,
133 const TPMT_TK_AUTH *ticket,
134 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
135 {
136 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
137 TSS2_RC rval;
138
139 if (!ticket)
140 return TSS2_SYS_RC_BAD_REFERENCE;
141
142 rval = Tss2_Sys_PolicyTicket_Prepare(sysContext, policySession, timeout,
143 cpHashA, policyRef, authName, ticket);
144 if (rval)
145 return rval;
146
147 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
148 if (rval)
149 return rval;
150
151 return Tss2_Sys_PolicyTicket_Complete(sysContext);
152 }
153