TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm2DictionaryAttack.c
Go to the documentation of this file.
1
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
20 TPMI_RH_LOCKOUT LockHandle;
21 UINT32 AuthSessionSize;
22 TPMS_AUTH_COMMAND AuthSession;
24
25typedef struct {
27 UINT32 AuthSessionSize;
28 TPMS_AUTH_RESPONSE AuthSession;
30
31typedef struct {
33 TPMI_RH_LOCKOUT LockHandle;
34 UINT32 AuthSessionSize;
35 TPMS_AUTH_COMMAND AuthSession;
36 UINT32 NewMaxTries;
37 UINT32 NewRecoveryTime;
38 UINT32 LockoutRecovery;
40
41typedef struct {
43 UINT32 AuthSessionSize;
44 TPMS_AUTH_RESPONSE AuthSession;
46
47#pragma pack()
48
60EFIAPI
62 IN TPMI_RH_LOCKOUT LockHandle,
63 IN TPMS_AUTH_COMMAND *AuthSession
64 )
65{
66 EFI_STATUS Status;
69 UINT32 SendBufferSize;
70 UINT32 RecvBufferSize;
71 UINT8 *Buffer;
72 UINT32 SessionInfoSize;
73
74 //
75 // Construct command
76 //
77 SendBuffer.Header.tag = SwapBytes16 (TPM_ST_SESSIONS);
78 SendBuffer.Header.commandCode = SwapBytes32 (TPM_CC_DictionaryAttackLockReset);
79
80 SendBuffer.LockHandle = SwapBytes32 (LockHandle);
81
82 //
83 // Add in Auth session
84 //
85 Buffer = (UINT8 *)&SendBuffer.AuthSession;
86
87 // sessionInfoSize
88 SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer);
89 Buffer += SessionInfoSize;
90 SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize);
91
92 SendBufferSize = (UINT32)((UINTN)Buffer - (UINTN)&SendBuffer);
93 SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);
94
95 //
96 // send Tpm command
97 //
98 RecvBufferSize = sizeof (RecvBuffer);
99 Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
100 if (EFI_ERROR (Status)) {
101 goto Done;
102 }
103
104 if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
105 DEBUG ((DEBUG_ERROR, "Tpm2DictionaryAttackLockReset - RecvBufferSize Error - %x\n", RecvBufferSize));
106 Status = EFI_DEVICE_ERROR;
107 goto Done;
108 }
109
110 if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
111 DEBUG ((DEBUG_ERROR, "Tpm2DictionaryAttackLockReset - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));
112 Status = EFI_DEVICE_ERROR;
113 goto Done;
114 }
115
116Done:
117 //
118 // Clear AuthSession Content
119 //
120 ZeroMem (&SendBuffer, sizeof (SendBuffer));
121 ZeroMem (&RecvBuffer, sizeof (RecvBuffer));
122 return Status;
123}
124
139EFIAPI
141 IN TPMI_RH_LOCKOUT LockHandle,
142 IN TPMS_AUTH_COMMAND *AuthSession,
143 IN UINT32 NewMaxTries,
144 IN UINT32 NewRecoveryTime,
145 IN UINT32 LockoutRecovery
146 )
147{
148 EFI_STATUS Status;
151 UINT32 SendBufferSize;
152 UINT32 RecvBufferSize;
153 UINT8 *Buffer;
154 UINT32 SessionInfoSize;
155
156 //
157 // Construct command
158 //
159 SendBuffer.Header.tag = SwapBytes16 (TPM_ST_SESSIONS);
160 SendBuffer.Header.commandCode = SwapBytes32 (TPM_CC_DictionaryAttackParameters);
161
162 SendBuffer.LockHandle = SwapBytes32 (LockHandle);
163
164 //
165 // Add in Auth session
166 //
167 Buffer = (UINT8 *)&SendBuffer.AuthSession;
168
169 // sessionInfoSize
170 SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer);
171 Buffer += SessionInfoSize;
172 SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize);
173
174 //
175 // Real data
176 //
177 WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (NewMaxTries));
178 Buffer += sizeof (UINT32);
179 WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (NewRecoveryTime));
180 Buffer += sizeof (UINT32);
181 WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (LockoutRecovery));
182 Buffer += sizeof (UINT32);
183
184 SendBufferSize = (UINT32)((UINTN)Buffer - (UINTN)&SendBuffer);
185 SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);
186
187 //
188 // send Tpm command
189 //
190 RecvBufferSize = sizeof (RecvBuffer);
191 Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
192 if (EFI_ERROR (Status)) {
193 goto Done;
194 }
195
196 if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
197 DEBUG ((DEBUG_ERROR, "Tpm2DictionaryAttackParameters - RecvBufferSize Error - %x\n", RecvBufferSize));
198 Status = EFI_DEVICE_ERROR;
199 goto Done;
200 }
201
202 if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
203 DEBUG ((DEBUG_ERROR, "Tpm2DictionaryAttackParameters - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));
204 Status = EFI_DEVICE_ERROR;
205 goto Done;
206 }
207
208Done:
209 //
210 // Clear AuthSession Content
211 //
212 ZeroMem (&SendBufferSize, sizeof (SendBufferSize));
213 ZeroMem (&RecvBuffer, sizeof (RecvBuffer));
214 return Status;
215}
UINT64 UINTN
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI CopyAuthSessionCommand(IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL, OUT UINT8 *AuthSessionOut)
Definition: Tpm2Help.c:88
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS EFIAPI Tpm2DictionaryAttackParameters(IN TPMI_RH_LOCKOUT LockHandle, IN TPMS_AUTH_COMMAND *AuthSession, IN UINT32 NewMaxTries, IN UINT32 NewRecoveryTime, IN UINT32 LockoutRecovery)
EFI_STATUS EFIAPI Tpm2DictionaryAttackLockReset(IN TPMI_RH_LOCKOUT LockHandle, IN TPMS_AUTH_COMMAND *AuthSession)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29