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
|
/** @file
This is DCS configuration, TPM
Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov
Copyright (c) 2016. VeraCrypt, Mounir IDRASSI
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the GNU Lesser General Public License, version 3.0 (LGPL-3.0).
The full text of the license may be found at
https://opensource.org/licenses/LGPL-3.0
**/
#include <Library/CommonLib.h>
#include <Library/DcsTpmLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DcsCfgLib.h>
#include "DcsVeraCrypt.h"
EFI_STATUS
Tpm12ListPcrs(
UINT32 sPcr,
UINT32 ePcr
) {
EFI_STATUS res;
res = InitTpm12();
if (EFI_ERROR(res)) {
ERR_PRINT(L"%r\n", res);
return res;
}
return Tpm12DumpPcrs(sPcr, ePcr);
}
EFI_STATUS
Tpm12NvList(
) {
EFI_STATUS res;
UINT32 count;
UINT32 i;
UINT32 nv[256];
res = InitTpm12();
if (EFI_ERROR(res)) {
ERR_PRINT(L"%r\n", res);
return res;
}
count = sizeof(nv);
res = Tpm12GetNvList(&count, nv);
if (EFI_ERROR(res)) {
ERR_PRINT(L"%r\n", res);
return res;
}
count = count >> 2;
for (i = 0; i < count; ++i) {
UINT32 index = SwapBytes32(nv[i]);
UINT32 attr = 0;
UINT32 dataSz = 0;
UINT32 pcrR = 0;
UINT32 pcrW = 0;
OUT_PRINT(L"%H%08x%N ", index);
res = Tpm12NvDetails(index, &attr, &dataSz, &pcrR, &pcrW);
if (EFI_ERROR(res)) {
ERR_PRINT(L"%r\n", res);
continue;
}
OUT_PRINT(L"Attr[%08x] PcrR[%08x] PcrW[%08x] [%d] ", attr, pcrR, pcrW, dataSz);
OUT_PRINT(L"\n");
}
return res;
}
EFI_STATUS
Tpm12DcsConfigure(
) {
EFI_STATUS res;
Password pwd;
ZeroMem(&pwd, sizeof(pwd));
CE(GetTpm());
CE(RndInit(RndTypeTpm, NULL, 0, &gRnd));
CE(gTpm->Configure(gTpm));
CE(gTpm->Apply(gTpm, &pwd));
return res;
err:
ERR_PRINT(L"%r, line %d", res, gCELine);
return res;
}
|