-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprocfs_tpm.cc
executable file
·99 lines (89 loc) · 2.24 KB
/
procfs_tpm.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright 2003 IBM
* Source License: GNU GENERAL PUBLIC LICENSE (GPL)
*/
/*
* OSXFUSE-Based procfs
* TPM Files
*/
extern "C" {
#if OSXFUSE_PROCFS_ENABLE_TPM
#include "procfs_tpm.h"
uint32_t
TPM_GetCapability_Version(int *major, int *minor, int *version, int *rev)
{
unsigned char blob[4096] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 18, /* blob length, bytes */
0, 0, 0, 101, /* TPM_ORD_GetCapability */
0, 0, 0, 6, /* TCPA_CAP_VERSION */
0, 0, 0, 0 /* no sub capability */
};
uint32_t ret;
ret = TPM_Transmit(blob, "TPM_GetCapability_Version");
if (ret)
return (ret);
*major = (int) (blob[14]);
*minor = (int) (blob[15]);
*version = (int) (blob[16]);
*rev = (int) (blob[17]);
return (ret);
}
uint32_t
TPM_GetCapability_Slots(uint32_t * slots)
{
unsigned char blob[4096] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 22, /* blob length, bytes */
0, 0, 0, 101, /* TPM_ORD_GetCapability */
0, 0, 0, 5, /* TCPA_CAP_PROPERTY */
0, 0, 0, 4, /* SUB_CAP size, bytes */
0, 0, 1, 4 /* TCPA_CAP_PROP_SLOTS */
};
uint32_t ret;
ret = TPM_Transmit(blob, "TPM_GetCapability_Slots");
if (ret)
return (ret);
*slots = ntohl(*(uint32_t *) (blob + 14));
return (ret);
}
uint32_t
TPM_GetCapability_Pcrs(uint32_t * pcrs)
{
unsigned char blob[4096] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 22, /* blob length, bytes */
0, 0, 0, 101, /* TPM_ORD_GetCapability */
0, 0, 0, 5, /* TCPA_CAP_PROPERTY */
0, 0, 0, 4, /* SUB_CAP size, bytes */
0, 0, 1, 1 /* TCPA_CAP_PROP_PCR */
};
uint32_t ret;
ret = TPM_Transmit(blob, "TPM_GetCapability_Pcrs");
if (ret)
return (ret);
*pcrs = ntohl(*(uint32_t *) (blob + 14));
return (ret);
}
uint32_t
TPM_GetCapability_Key_Handle(uint16_t * num, uint32_t keys[])
{
unsigned char blob[4096] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 18, /* blob length, bytes */
0, 0, 0, 101, /* TPM_ORD_GetCapability */
0, 0, 0, 7, /* TCPA_CAP_KEY_HANDLE */
0, 0, 0, 0 /* no sub capability */
};
uint32_t ret;
int i;
ret = TPM_Transmit(blob, "TPM_GetCapability_Handle_List");
if (ret)
return (ret);
*num = ntohs(*(uint16_t *) (blob + 14));
for (i = 0; i < *num; i++)
keys[i] = ntohl(*(uint32_t *) (blob + 16 + 4 * i));
return (ret);
}
#endif /* OSXFUSE_PROCFS_ENABLE_TPM */
}