3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2007
15
#include "trousers/tss.h"
16
#include "trousers/trousers.h"
17
#include "trousers_types.h"
18
#include "spi_utils.h"
19
#include "capabilities.h"
24
#ifdef TSS_BUILD_TRANSPORT
26
Transport_CertifyKey(TSS_HCONTEXT tspContext, /* in */
27
TCS_KEY_HANDLE certHandle, /* in */
28
TCS_KEY_HANDLE keyHandle, /* in */
29
TPM_NONCE * antiReplay, /* in */
30
TPM_AUTH * certAuth, /* in, out */
31
TPM_AUTH * keyAuth, /* in, out */
32
UINT32 * CertifyInfoSize, /* out */
33
BYTE ** CertifyInfo, /* out */
34
UINT32 * outDataSize, /* out */
35
BYTE ** outData) /* out */
38
UINT32 handlesLen, decLen;
39
TCS_HANDLE *handles, handle[2];
41
TPM_DIGEST pubKeyHash1, pubKeyHash2;
42
Trspi_HashCtx hashCtx;
44
BYTE data[sizeof(TPM_NONCE)];
47
if ((result = obj_context_transport_init(tspContext)))
50
LogDebugFn("Executing in a transport session");
52
if ((result = obj_tcskey_get_pubkeyhash(certHandle, pubKeyHash1.digest)))
55
if ((result = obj_tcskey_get_pubkeyhash(keyHandle, pubKeyHash2.digest)))
58
result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
59
result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash1.digest);
60
result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash2.digest);
61
if ((result |= Trspi_HashFinal(&hashCtx, pubKeyHash1.digest)))
65
handle[0] = certHandle;
66
handle[1] = keyHandle;
70
Trspi_LoadBlob_NONCE(&offset, data, antiReplay);
72
if ((result = obj_context_transport_execute(tspContext, TPM_ORD_CertifyKey, sizeof(data),
73
data, &pubKeyHash1, &handlesLen, &handles,
74
certAuth, keyAuth, &decLen, &dec)))
78
Trspi_UnloadBlob_CERTIFY_INFO(&offset, dec, NULL);
79
*CertifyInfoSize = offset;
81
if ((*CertifyInfo = malloc(*CertifyInfoSize)) == NULL) {
83
LogError("malloc of %u bytes failed", *CertifyInfoSize);
85
return TSPERR(TSS_E_OUTOFMEMORY);
89
Trspi_UnloadBlob(&offset, *CertifyInfoSize, dec, *CertifyInfo);
90
Trspi_UnloadBlob_UINT32(&offset, outDataSize, dec);
92
if ((*outData = malloc(*outDataSize)) == NULL) {
97
LogError("malloc of %u bytes failed", *outDataSize);
99
return TSPERR(TSS_E_OUTOFMEMORY);
101
Trspi_UnloadBlob(&offset, *outDataSize, dec, *outData);