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_Quote_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT signHandle,const TPM2B_DATA * qualifyingData,const TPMT_SIG_SCHEME * inScheme,const TPML_PCR_SELECTION * PCRselect)15 TSS2_RC Tss2_Sys_Quote_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT signHandle,
18 const TPM2B_DATA *qualifyingData,
19 const TPMT_SIG_SCHEME *inScheme,
20 const TPML_PCR_SELECTION *PCRselect)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx || !inScheme || !PCRselect)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = ValidateTPML_PCR_SELECTION(PCRselect);
29 if (rval)
30 return rval;
31
32 rval = CommonPreparePrologue(ctx, TPM2_CC_Quote);
33 if (rval)
34 return rval;
35
36 rval = Tss2_MU_UINT32_Marshal(signHandle, ctx->cmdBuffer,
37 ctx->maxCmdSize,
38 &ctx->nextData);
39 if (rval)
40 return rval;
41
42 if (!qualifyingData) {
43 ctx->decryptNull = 1;
44
45 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 } else {
49
50 rval = Tss2_MU_TPM2B_DATA_Marshal(qualifyingData, ctx->cmdBuffer,
51 ctx->maxCmdSize,
52 &ctx->nextData);
53 }
54
55 if (rval)
56 return rval;
57
58 rval = Tss2_MU_TPMT_SIG_SCHEME_Marshal(inScheme, ctx->cmdBuffer,
59 ctx->maxCmdSize,
60 &ctx->nextData);
61 if (rval)
62 return rval;
63
64 rval = Tss2_MU_TPML_PCR_SELECTION_Marshal(PCRselect, ctx->cmdBuffer,
65 ctx->maxCmdSize,
66 &ctx->nextData);
67 if (rval)
68 return rval;
69
70 ctx->decryptAllowed = 1;
71 ctx->encryptAllowed = 1;
72 ctx->authAllowed = 1;
73
74 return CommonPrepareEpilogue(ctx);
75 }
76
Tss2_Sys_Quote_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ATTEST * quoted,TPMT_SIGNATURE * signature)77 TSS2_RC Tss2_Sys_Quote_Complete(
78 TSS2_SYS_CONTEXT *sysContext,
79 TPM2B_ATTEST *quoted,
80 TPMT_SIGNATURE *signature)
81 {
82 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
83 TSS2_RC rval;
84
85 if (!ctx)
86 return TSS2_SYS_RC_BAD_REFERENCE;
87
88 rval = CommonComplete(ctx);
89 if (rval)
90 return rval;
91
92 rval = Tss2_MU_TPM2B_ATTEST_Unmarshal(ctx->cmdBuffer,
93 ctx->maxCmdSize,
94 &ctx->nextData, quoted);
95 if (rval)
96 return rval;
97
98 return Tss2_MU_TPMT_SIGNATURE_Unmarshal(ctx->cmdBuffer,
99 ctx->maxCmdSize,
100 &ctx->nextData, signature);
101 }
102
Tss2_Sys_Quote(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT signHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DATA * qualifyingData,const TPMT_SIG_SCHEME * inScheme,const TPML_PCR_SELECTION * PCRselect,TPM2B_ATTEST * quoted,TPMT_SIGNATURE * signature,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)103 TSS2_RC Tss2_Sys_Quote(
104 TSS2_SYS_CONTEXT *sysContext,
105 TPMI_DH_OBJECT signHandle,
106 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
107 const TPM2B_DATA *qualifyingData,
108 const TPMT_SIG_SCHEME *inScheme,
109 const TPML_PCR_SELECTION *PCRselect,
110 TPM2B_ATTEST *quoted,
111 TPMT_SIGNATURE *signature,
112 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
113 {
114 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
115 TSS2_RC rval;
116
117 if (!inScheme || !PCRselect)
118 return TSS2_SYS_RC_BAD_REFERENCE;
119
120 rval = Tss2_Sys_Quote_Prepare(sysContext, signHandle, qualifyingData,
121 inScheme, PCRselect);
122 if (rval)
123 return rval;
124
125 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
126 if (rval)
127 return rval;
128
129 return Tss2_Sys_Quote_Complete(sysContext, quoted, signature);
130 }
131