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