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_MakeCredential_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT handle,const TPM2B_DIGEST * credential,const TPM2B_NAME * objectName)15 TSS2_RC Tss2_Sys_MakeCredential_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_DH_OBJECT handle,
18 const TPM2B_DIGEST *credential,
19 const TPM2B_NAME *objectName)
20 {
21 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22 TSS2_RC rval;
23
24 if (!ctx)
25 return TSS2_SYS_RC_BAD_REFERENCE;
26
27 rval = CommonPreparePrologue(ctx, TPM2_CC_MakeCredential);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(handle, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 if (!credential) {
38 ctx->decryptNull = 1;
39
40 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
41 ctx->maxCmdSize,
42 &ctx->nextData);
43 } else {
44
45 rval = Tss2_MU_TPM2B_DIGEST_Marshal(credential, ctx->cmdBuffer,
46 ctx->maxCmdSize,
47 &ctx->nextData);
48 }
49
50 if (rval)
51 return rval;
52
53 if (!objectName) {
54 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
55 ctx->maxCmdSize,
56 &ctx->nextData);
57
58 } else {
59
60 rval = Tss2_MU_TPM2B_NAME_Marshal(objectName, ctx->cmdBuffer,
61 ctx->maxCmdSize,
62 &ctx->nextData);
63 }
64
65 if (rval)
66 return rval;
67
68 ctx->decryptAllowed = 1;
69 ctx->encryptAllowed = 1;
70 ctx->authAllowed = 1;
71
72 return CommonPrepareEpilogue(ctx);
73 }
74
Tss2_Sys_MakeCredential_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_ID_OBJECT * credentialBlob,TPM2B_ENCRYPTED_SECRET * secret)75 TSS2_RC Tss2_Sys_MakeCredential_Complete(
76 TSS2_SYS_CONTEXT *sysContext,
77 TPM2B_ID_OBJECT *credentialBlob,
78 TPM2B_ENCRYPTED_SECRET *secret)
79 {
80 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
81 TSS2_RC rval;
82
83 if (!ctx)
84 return TSS2_SYS_RC_BAD_REFERENCE;
85
86 rval = CommonComplete(ctx);
87 if (rval)
88 return rval;
89
90 rval = Tss2_MU_TPM2B_ID_OBJECT_Unmarshal(ctx->cmdBuffer,
91 ctx->maxCmdSize,
92 &ctx->nextData,
93 credentialBlob);
94 if (rval)
95 return rval;
96
97 return Tss2_MU_TPM2B_ENCRYPTED_SECRET_Unmarshal(ctx->cmdBuffer,
98 ctx->maxCmdSize,
99 &ctx->nextData,
100 secret);
101 }
102
Tss2_Sys_MakeCredential(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT handle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * credential,const TPM2B_NAME * objectName,TPM2B_ID_OBJECT * credentialBlob,TPM2B_ENCRYPTED_SECRET * secret,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)103 TSS2_RC Tss2_Sys_MakeCredential(
104 TSS2_SYS_CONTEXT *sysContext,
105 TPMI_DH_OBJECT handle,
106 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
107 const TPM2B_DIGEST *credential,
108 const TPM2B_NAME *objectName,
109 TPM2B_ID_OBJECT *credentialBlob,
110 TPM2B_ENCRYPTED_SECRET *secret,
111 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
112 {
113 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
114 TSS2_RC rval;
115
116 rval = Tss2_Sys_MakeCredential_Prepare(sysContext, handle, credential, objectName);
117 if (rval)
118 return rval;
119
120 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
121 if (rval)
122 return rval;
123
124 return Tss2_Sys_MakeCredential_Complete(sysContext, credentialBlob, secret);
125 }
126