Skip to content

Commit 0934093

Browse files
author
kyoder
committed
added support for sealing to PCRs 16-23 when a TSS 1.2 lib is available at build time; support -h, -v, etc without needing to connect to a tcsd
1 parent 60a4c9c commit 0934093

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

‎src/cmds/tpm_sealdata.c

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ static char in_filename[PATH_MAX] = "", out_filename[PATH_MAX] = "";
4343
static TSS_HPCRS hPcrs = NULL_HPCRS;
4444
static TSS_HCONTEXT hContext;
4545
static TSS_HTPM hTpm;
46+
static UINT32 selectedPcrs[24];
47+
static UINT32 selectedPcrsLen = 0;
4648

4749
static int parse(const int aOpt, const char *aArg)
4850
{
4951
int rc = -1;
50-
UINT32 pcr_idx;
51-
BYTE *pcr_idx_val;
52-
UINT32 pcr_siz;
5352

5453
switch (aOpt) {
5554
case 'i':
@@ -66,25 +65,7 @@ static int parse(const int aOpt, const char *aArg)
6665
break;
6766
case 'p':
6867
if (aArg) {
69-
if (hPcrs == NULL_HPCRS) {
70-
if (Tspi_Context_CreateObject(hContext,
71-
TSS_OBJECT_TYPE_PCRS,
72-
0,
73-
&hPcrs) !=
74-
TSS_SUCCESS)
75-
break;
76-
}
77-
pcr_idx = atoi(aArg);
78-
if (Tspi_TPM_PcrRead(hTpm, pcr_idx, &pcr_siz,
79-
&pcr_idx_val) != TSS_SUCCESS)
80-
break;
81-
82-
if (Tspi_PcrComposite_SetPcrValue(hPcrs, pcr_idx,
83-
pcr_siz,
84-
pcr_idx_val)
85-
!= TSS_SUCCESS)
86-
break;
87-
68+
selectedPcrs[selectedPcrsLen++] = atoi(aArg);
8869
rc = 0;
8970
}
9071
break;
@@ -109,7 +90,7 @@ int main(int argc, char **argv)
10990
int lineLen;
11091
unsigned char encData[sizeof(line) + EVP_CIPHER_block_size(EVP_aes_256_cbc())];
11192
int encDataLen;
112-
UINT32 encLen;
93+
UINT32 encLen, i;
11394
BYTE *encKey;
11495
BYTE *randKey = NULL;
11596
UINT32 sealKeyLen;
@@ -152,6 +133,50 @@ int main(int argc, char **argv)
152133
goto out_close;
153134
}
154135

136+
/* Create the PCRs object. If any PCRs above 15 are selected, this will need to be
137+
* a 1.2 TSS/TPM */
138+
if (selectedPcrsLen) {
139+
TSS_FLAG initFlag = 0;
140+
UINT32 pcrSize;
141+
BYTE *pcrValue;
142+
143+
for (i = 0; i < selectedPcrsLen; i++) {
144+
if (selectedPcrs[i] > 15) {
145+
#ifdef TSS_LIB_IS_12
146+
initFlag |= TSS_PCRS_STRUCT_INFO_LONG;
147+
#else
148+
logError(_("This version of %s was compiled for a v1.1 TSS, which "
149+
"can only seal\n data to PCRs 0-15. PCR %u is out of range"
150+
"\n"), argv[0], selectedPcrs[i]);
151+
goto out_close;
152+
#endif
153+
}
154+
}
155+
156+
if (contextCreateObject(hContext, TSS_OBJECT_TYPE_PCRS, initFlag,
157+
&hPcrs) != TSS_SUCCESS)
158+
goto out_close;
159+
160+
for (i = 0; i < selectedPcrsLen; i++) {
161+
if (tpmPcrRead(hTpm, selectedPcrs[i], &pcrSize, &pcrValue) != TSS_SUCCESS)
162+
goto out_close;
163+
164+
if (pcrcompositeSetPcrValue(hPcrs, selectedPcrs[i], pcrSize, pcrValue)
165+
!= TSS_SUCCESS)
166+
goto out_close;
167+
}
168+
#ifdef TSS_LIB_IS_12
169+
if (initFlag) {
170+
UINT32 localityValue =
171+
TPM_LOC_ZERO | TPM_LOC_ONE | TPM_LOC_TWO | TPM_LOC_THREE |
172+
TPM_LOC_FOUR;
173+
174+
if (pcrcompositeSetPcrLocality(hPcrs, localityValue) != TSS_SUCCESS)
175+
goto out_close;
176+
}
177+
#endif
178+
}
179+
155180
/* Retrieve random data to be used as the symmetric key
156181
(this key will encrypt the input file contents) */
157182
if (tpmGetRandom(hTpm, EVP_CIPHER_key_length(EVP_aes_256_cbc()),

0 commit comments

Comments
 (0)