32 IN UINT32 *FragmentCount
42 UINT16 ThisPlainMessageSize;
44 UINT16 ThisMessageSize;
55 RecordHeaderIn =
NULL;
56 TempRecordHeader =
NULL;
65 for (Index = 0; Index < *FragmentCount; Index++) {
66 BufferInSize += (*FragmentTable)[Index].FragmentLength;
73 if (BufferIn ==
NULL) {
74 Status = EFI_OUT_OF_RESOURCES;
81 for (Index = 0; Index < *FragmentCount; Index++) {
83 (BufferIn + BytesCopied),
84 (*FragmentTable)[Index].FragmentBuffer,
85 (*FragmentTable)[Index].FragmentLength
87 BytesCopied += (*FragmentTable)[Index].FragmentLength;
93 BufferInPtr = BufferIn;
94 while ((
UINTN)BufferInPtr < (
UINTN)BufferIn + BufferInSize) {
96 if ((RecordHeaderIn->ContentType != TlsContentTypeApplicationData) || (RecordHeaderIn->Length > TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH)) {
97 Status = EFI_INVALID_PARAMETER;
101 BufferInPtr += TLS_RECORD_HEADER_LENGTH + RecordHeaderIn->Length;
108 BufferOut =
AllocateZeroPool (RecordCount * (TLS_RECORD_HEADER_LENGTH + TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH));
109 if (BufferOut ==
NULL) {
110 Status = EFI_OUT_OF_RESOURCES;
117 BufferInPtr = BufferIn;
119 while ((
UINTN)BufferInPtr < (
UINTN)BufferIn + BufferInSize) {
122 ThisPlainMessageSize = RecordHeaderIn->Length;
124 TlsWrite (TlsInstance->TlsConn, (UINT8 *)(RecordHeaderIn + 1), ThisPlainMessageSize);
126 Ret =
TlsCtrlTrafficOut (TlsInstance->TlsConn, (UINT8 *)(TempRecordHeader), TLS_RECORD_HEADER_LENGTH + TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH);
129 ThisMessageSize = (UINT16)Ret;
134 DEBUG ((DEBUG_WARN,
"TlsEncryptPacket: No data read from TLS object.\n"));
139 BufferOutSize += ThisMessageSize;
141 BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
142 TempRecordHeader = (
TLS_RECORD_HEADER *)((UINT8 *)TempRecordHeader + ThisMessageSize);
152 if (*FragmentTable ==
NULL) {
153 Status = EFI_OUT_OF_RESOURCES;
157 (*FragmentTable)[0].FragmentBuffer = BufferOut;
158 (*FragmentTable)[0].FragmentLength = BufferOutSize;
165 if (BufferIn !=
NULL) {
170 if (BufferOut !=
NULL) {
198 IN UINT32 *FragmentCount
208 UINT16 ThisCipherMessageSize;
210 UINT16 ThisPlainMessageSize;
212 UINT32 BufferOutSize;
221 RecordHeaderIn =
NULL;
222 TempRecordHeader =
NULL;
231 for (Index = 0; Index < *FragmentCount; Index++) {
232 BufferInSize += (*FragmentTable)[Index].FragmentLength;
239 if (BufferIn ==
NULL) {
240 Status = EFI_OUT_OF_RESOURCES;
247 for (Index = 0; Index < *FragmentCount; Index++) {
249 (BufferIn + BytesCopied),
250 (*FragmentTable)[Index].FragmentBuffer,
251 (*FragmentTable)[Index].FragmentLength
253 BytesCopied += (*FragmentTable)[Index].FragmentLength;
259 BufferInPtr = BufferIn;
260 while ((
UINTN)BufferInPtr < (
UINTN)BufferIn + BufferInSize) {
262 if ((RecordHeaderIn->ContentType != TlsContentTypeApplicationData) || (NTOHS (RecordHeaderIn->Length) > TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH)) {
263 Status = EFI_INVALID_PARAMETER;
267 BufferInPtr += TLS_RECORD_HEADER_LENGTH + NTOHS (RecordHeaderIn->Length);
274 BufferOut =
AllocateZeroPool (RecordCount * (TLS_RECORD_HEADER_LENGTH + TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH));
275 if (BufferOut ==
NULL) {
276 Status = EFI_OUT_OF_RESOURCES;
283 BufferInPtr = BufferIn;
285 while ((
UINTN)BufferInPtr < (
UINTN)BufferIn + BufferInSize) {
288 ThisCipherMessageSize = NTOHS (RecordHeaderIn->Length);
290 Ret =
TlsCtrlTrafficIn (TlsInstance->TlsConn, (UINT8 *)(RecordHeaderIn), TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize);
291 if (Ret != TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize) {
293 Status = EFI_ABORTED;
298 Ret =
TlsRead (TlsInstance->TlsConn, (UINT8 *)(TempRecordHeader + 1), TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH);
301 ThisPlainMessageSize = (UINT16)Ret;
306 DEBUG ((DEBUG_WARN,
"TlsDecryptPacket: No data read from TLS object.\n"));
308 ThisPlainMessageSize = 0;
311 CopyMem (TempRecordHeader, RecordHeaderIn, TLS_RECORD_HEADER_LENGTH);
312 TempRecordHeader->Length = ThisPlainMessageSize;
313 BufferOutSize += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
315 BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize;
316 TempRecordHeader = (
TLS_RECORD_HEADER *)((UINT8 *)TempRecordHeader + TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize);
326 if (*FragmentTable ==
NULL) {
327 Status = EFI_OUT_OF_RESOURCES;
331 (*FragmentTable)[0].FragmentBuffer = BufferOut;
332 (*FragmentTable)[0].FragmentLength = BufferOutSize;
339 if (BufferIn !=
NULL) {
344 if (BufferOut !=
NULL) {
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
EFI_STATUS TlsDecryptPacket(IN TLS_INSTANCE *TlsInstance, IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable, IN UINT32 *FragmentCount)
EFI_STATUS TlsEncryptPacket(IN TLS_INSTANCE *TlsInstance, IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable, IN UINT32 *FragmentCount)
INTN EFIAPI TlsCtrlTrafficIn(IN VOID *Tls, IN VOID *Buffer, IN UINTN BufferSize)
INTN EFIAPI TlsCtrlTrafficOut(IN VOID *Tls, IN OUT VOID *Buffer, IN UINTN BufferSize)
INTN EFIAPI TlsRead(IN VOID *Tls, IN OUT VOID *Buffer, IN UINTN BufferSize)
INTN EFIAPI TlsWrite(IN VOID *Tls, IN VOID *Buffer, IN UINTN BufferSize)