1
2 /*
3 * Licensed Materials - Property of IBM
4 *
5 * trousers - An open source TCG Software Stack
6 *
7 * (C) Copyright International Business Machines Corp. 2004-2006
8 *
9 */
10
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <sys/mman.h>
18 #include <errno.h>
19
20 #include "trousers/tss.h"
21 #include "trousers/trousers.h"
22 #include "trousers_types.h"
23 #include "trousers_types.h"
24 #include "spi_utils.h"
25 #include "capabilities.h"
26 #include "tsplog.h"
27 #include "obj.h"
28
29
30 TSS_RESULT
get_tpm_flags(TSS_HCONTEXT tspContext,TSS_HTPM hTPM,UINT32 * volFlags,UINT32 * nonVolFlags)31 get_tpm_flags(TSS_HCONTEXT tspContext, TSS_HTPM hTPM, UINT32 *volFlags, UINT32 *nonVolFlags)
32 {
33 TCPA_DIGEST digest;
34 TPM_AUTH auth;
35 TCPA_VERSION version;
36 TSS_RESULT result;
37 TSS_HPOLICY hPolicy;
38 Trspi_HashCtx hashCtx;
39
40 if ((result = obj_tpm_get_policy(hTPM, TSS_POLICY_USAGE, &hPolicy)))
41 return result;
42
43 /* do an owner authorized get capability call */
44 result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
45 result |= Trspi_Hash_UINT32(&hashCtx, TPM_ORD_GetCapabilityOwner);
46 if ((result |= Trspi_HashFinal(&hashCtx, digest.digest)))
47 return result;
48
49 if ((result = secret_PerformAuth_OIAP(hTPM, TPM_ORD_GetCapabilityOwner, hPolicy, FALSE,
50 &digest, &auth)))
51 return result;
52
53 if ((result = TCS_API(tspContext)->GetCapabilityOwner(tspContext, &auth, &version,
54 nonVolFlags, volFlags)))
55 return result;
56
57 result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
58 result |= Trspi_Hash_UINT32(&hashCtx, result);
59 result |= Trspi_Hash_UINT32(&hashCtx, TPM_ORD_GetCapabilityOwner);
60 result |= Trspi_Hash_VERSION(&hashCtx, (TSS_VERSION *)&version);
61 result |= Trspi_Hash_UINT32(&hashCtx, *nonVolFlags);
62 result |= Trspi_Hash_UINT32(&hashCtx, *volFlags);
63 if ((result |= Trspi_HashFinal(&hashCtx, digest.digest)))
64 return result;
65
66 return obj_policy_validate_auth_oiap(hPolicy, &digest, &auth);
67 }
68