NetworkPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the NetworkPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:07 -08:00
committed by mergify[bot]
parent 2f88bd3a12
commit d1050b9dff
294 changed files with 29888 additions and 30440 deletions

View File

@@ -43,13 +43,13 @@ TlsConfigurationSetData (
IN UINTN DataSize
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
if (This == NULL || Data == NULL || DataSize == 0) {
if ((This == NULL) || (Data == NULL) || (DataSize == 0)) {
return EFI_INVALID_PARAMETER;
}
@@ -58,20 +58,20 @@ TlsConfigurationSetData (
Instance = TLS_INSTANCE_FROM_CONFIGURATION (This);
switch (DataType) {
case EfiTlsConfigDataTypeCACertificate:
Status = TlsSetCaCertificate (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPublicCert:
Status = TlsSetHostPublicCert (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPrivateKey:
Status = TlsSetHostPrivateKey (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeCertRevocationList:
Status = TlsSetCertRevocationList (Data, DataSize);
break;
default:
Status = EFI_UNSUPPORTED;
case EfiTlsConfigDataTypeCACertificate:
Status = TlsSetCaCertificate (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPublicCert:
Status = TlsSetHostPublicCert (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPrivateKey:
Status = TlsSetHostPrivateKey (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeCertRevocationList:
Status = TlsSetCertRevocationList (Data, DataSize);
break;
default:
Status = EFI_UNSUPPORTED;
}
gBS->RestoreTPL (OldTpl);
@@ -109,14 +109,14 @@ TlsConfigurationGetData (
IN OUT UINTN *DataSize
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
if (This == NULL || DataSize == NULL || (Data == NULL && *DataSize != 0)) {
if ((This == NULL) || (DataSize == NULL) || ((Data == NULL) && (*DataSize != 0))) {
return EFI_INVALID_PARAMETER;
}
@@ -125,20 +125,20 @@ TlsConfigurationGetData (
Instance = TLS_INSTANCE_FROM_CONFIGURATION (This);
switch (DataType) {
case EfiTlsConfigDataTypeCACertificate:
Status = TlsGetCaCertificate (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPublicCert:
Status = TlsGetHostPublicCert (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPrivateKey:
Status = TlsGetHostPrivateKey (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeCertRevocationList:
Status = TlsGetCertRevocationList (Data, DataSize);
break;
default:
Status = EFI_UNSUPPORTED;
case EfiTlsConfigDataTypeCACertificate:
Status = TlsGetCaCertificate (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPublicCert:
Status = TlsGetHostPublicCert (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeHostPrivateKey:
Status = TlsGetHostPrivateKey (Instance->TlsConn, Data, DataSize);
break;
case EfiTlsConfigDataTypeCertRevocationList:
Status = TlsGetCertRevocationList (Data, DataSize);
break;
default:
Status = EFI_UNSUPPORTED;
}
gBS->RestoreTPL (OldTpl);

View File

@@ -9,7 +9,7 @@
#include "TlsImpl.h"
EFI_SERVICE_BINDING_PROTOCOL mTlsServiceBinding = {
EFI_SERVICE_BINDING_PROTOCOL mTlsServiceBinding = {
TlsServiceBindingCreateChild,
TlsServiceBindingDestroyChild
};
@@ -22,7 +22,7 @@ EFI_SERVICE_BINDING_PROTOCOL mTlsServiceBinding = {
**/
VOID
TlsCleanInstance (
IN TLS_INSTANCE *Instance
IN TLS_INSTANCE *Instance
)
{
if (Instance != NULL) {
@@ -46,11 +46,11 @@ TlsCleanInstance (
**/
EFI_STATUS
TlsCreateInstance (
IN TLS_SERVICE *Service,
OUT TLS_INSTANCE **Instance
IN TLS_SERVICE *Service,
OUT TLS_INSTANCE **Instance
)
{
TLS_INSTANCE *TlsInstance;
TLS_INSTANCE *TlsInstance;
*Instance = NULL;
@@ -82,7 +82,7 @@ TlsCreateInstance (
**/
VOID
TlsCleanService (
IN TLS_SERVICE *Service
IN TLS_SERVICE *Service
)
{
if (Service != NULL) {
@@ -106,11 +106,11 @@ TlsCleanService (
**/
EFI_STATUS
TlsCreateService (
IN EFI_HANDLE Image,
OUT TLS_SERVICE **Service
IN EFI_HANDLE Image,
OUT TLS_SERVICE **Service
)
{
TLS_SERVICE *TlsService;
TLS_SERVICE *TlsService;
ASSERT (Service != NULL);
@@ -127,11 +127,11 @@ TlsCreateService (
//
// Initialize TLS Service Data
//
TlsService->Signature = TLS_SERVICE_SIGNATURE;
TlsService->Signature = TLS_SERVICE_SIGNATURE;
CopyMem (&TlsService->ServiceBinding, &mTlsServiceBinding, sizeof (TlsService->ServiceBinding));
TlsService->TlsChildrenNum = 0;
TlsService->TlsChildrenNum = 0;
InitializeListHead (&TlsService->TlsChildrenList);
TlsService->ImageHandle = Image;
TlsService->ImageHandle = Image;
*Service = TlsService;
@@ -153,12 +153,12 @@ TlsUnload (
IN EFI_HANDLE ImageHandle
)
{
EFI_STATUS Status;
UINTN HandleNum;
EFI_HANDLE *HandleBuffer;
UINT32 Index;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
TLS_SERVICE *TlsService;
EFI_STATUS Status;
UINTN HandleNum;
EFI_HANDLE *HandleBuffer;
UINT32 Index;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
TLS_SERVICE *TlsService;
HandleBuffer = NULL;
ServiceBinding = NULL;
@@ -185,7 +185,7 @@ TlsUnload (
Status = gBS->OpenProtocol (
HandleBuffer[Index],
&gEfiTlsServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
(VOID **)&ServiceBinding,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
@@ -201,7 +201,8 @@ TlsUnload (
//
Status = gBS->UninstallMultipleProtocolInterfaces (
HandleBuffer[Index],
&gEfiTlsServiceBindingProtocolGuid, ServiceBinding,
&gEfiTlsServiceBindingProtocolGuid,
ServiceBinding,
NULL
);
if (EFI_ERROR (Status)) {
@@ -236,9 +237,9 @@ TlsDriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_STATUS Status;
TLS_SERVICE *TlsService;
TLS_SERVICE *TlsService;
//
// Create TLS Service
@@ -312,10 +313,10 @@ TlsServiceBindingCreateChild (
IN EFI_HANDLE *ChildHandle
)
{
TLS_SERVICE *TlsService;
TLS_INSTANCE *TlsInstance;
EFI_STATUS Status;
EFI_TPL OldTpl;
TLS_SERVICE *TlsService;
TLS_INSTANCE *TlsInstance;
EFI_STATUS Status;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -406,13 +407,13 @@ TlsServiceBindingDestroyChild (
IN EFI_HANDLE ChildHandle
)
{
TLS_SERVICE *TlsService;
TLS_INSTANCE *TlsInstance;
TLS_SERVICE *TlsService;
TLS_INSTANCE *TlsInstance;
EFI_TLS_PROTOCOL *Tls;
EFI_TLS_CONFIGURATION_PROTOCOL *TlsConfig;
EFI_STATUS Status;
EFI_TPL OldTpl;
EFI_TLS_PROTOCOL *Tls;
EFI_TLS_CONFIGURATION_PROTOCOL *TlsConfig;
EFI_STATUS Status;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -426,7 +427,7 @@ TlsServiceBindingDestroyChild (
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiTlsProtocolGuid,
(VOID **) &Tls,
(VOID **)&Tls,
TlsService->ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
@@ -441,7 +442,7 @@ TlsServiceBindingDestroyChild (
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiTlsConfigurationProtocolGuid,
(VOID **) &TlsConfig,
(VOID **)&TlsConfig,
TlsService->ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
@@ -450,7 +451,7 @@ TlsServiceBindingDestroyChild (
return Status;
}
TlsInstance = TLS_INSTANCE_FROM_PROTOCOL (Tls);
TlsInstance = TLS_INSTANCE_FROM_PROTOCOL (Tls);
if (TlsInstance->Service != TlsService) {
return EFI_INVALID_PARAMETER;
@@ -488,4 +489,3 @@ TlsServiceBindingDestroyChild (
return EFI_SUCCESS;
}

View File

@@ -22,21 +22,20 @@
//
#define TLS_VERSION 0x00000000
#define TLS_SERVICE_SIGNATURE SIGNATURE_32 ('T', 'L', 'S', 'S')
#define TLS_SERVICE_SIGNATURE SIGNATURE_32 ('T', 'L', 'S', 'S')
#define TLS_INSTANCE_SIGNATURE SIGNATURE_32 ('T', 'L', 'S', 'I')
#define TLS_INSTANCE_SIGNATURE SIGNATURE_32 ('T', 'L', 'S', 'I')
///
/// TLS Service Data
///
typedef struct _TLS_SERVICE TLS_SERVICE;
typedef struct _TLS_SERVICE TLS_SERVICE;
///
/// TLS Instance Data
///
typedef struct _TLS_INSTANCE TLS_INSTANCE;
struct _TLS_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
@@ -59,27 +58,26 @@ struct _TLS_SERVICE {
};
struct _TLS_INSTANCE {
UINT32 Signature;
LIST_ENTRY Link;
UINT32 Signature;
LIST_ENTRY Link;
BOOLEAN InDestroy;
BOOLEAN InDestroy;
TLS_SERVICE *Service;
EFI_HANDLE ChildHandle;
TLS_SERVICE *Service;
EFI_HANDLE ChildHandle;
EFI_TLS_PROTOCOL Tls;
EFI_TLS_CONFIGURATION_PROTOCOL TlsConfig;
EFI_TLS_PROTOCOL Tls;
EFI_TLS_CONFIGURATION_PROTOCOL TlsConfig;
EFI_TLS_SESSION_STATE TlsSessionState;
EFI_TLS_SESSION_STATE TlsSessionState;
//
// Main SSL Connection which is created by a server or a client
// per established connection.
//
VOID *TlsConn;
VOID *TlsConn;
};
#define TLS_SERVICE_FROM_THIS(a) \
CR (a, TLS_SERVICE, ServiceBinding, TLS_SERVICE_SIGNATURE)
@@ -89,7 +87,6 @@ struct _TLS_INSTANCE {
#define TLS_INSTANCE_FROM_CONFIGURATION(a) \
CR (a, TLS_INSTANCE, TlsConfig, TLS_INSTANCE_SIGNATURE)
/**
Release all the resources used by the TLS instance.
@@ -98,7 +95,7 @@ struct _TLS_INSTANCE {
**/
VOID
TlsCleanInstance (
IN TLS_INSTANCE *Instance
IN TLS_INSTANCE *Instance
);
/**
@@ -113,8 +110,8 @@ TlsCleanInstance (
**/
EFI_STATUS
TlsCreateInstance (
IN TLS_SERVICE *Service,
OUT TLS_INSTANCE **Instance
IN TLS_SERVICE *Service,
OUT TLS_INSTANCE **Instance
);
/**
@@ -125,7 +122,7 @@ TlsCreateInstance (
**/
VOID
TlsCleanService (
IN TLS_SERVICE *Service
IN TLS_SERVICE *Service
);
/**
@@ -140,8 +137,8 @@ TlsCleanService (
**/
EFI_STATUS
TlsCreateService (
IN EFI_HANDLE Image,
OUT TLS_SERVICE **Service
IN EFI_HANDLE Image,
OUT TLS_SERVICE **Service
);
/**
@@ -229,4 +226,3 @@ TlsServiceBindingDestroyChild (
);
#endif

View File

@@ -27,25 +27,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
TlsEncryptPacket (
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
)
{
EFI_STATUS Status;
UINTN Index;
UINT32 BytesCopied;
UINT32 BufferInSize;
UINT8 *BufferIn;
UINT8 *BufferInPtr;
TLS_RECORD_HEADER *RecordHeaderIn;
UINT16 ThisPlainMessageSize;
TLS_RECORD_HEADER *TempRecordHeader;
UINT16 ThisMessageSize;
UINT32 BufferOutSize;
UINT8 *BufferOut;
UINT32 RecordCount;
INTN Ret;
EFI_STATUS Status;
UINTN Index;
UINT32 BytesCopied;
UINT32 BufferInSize;
UINT8 *BufferIn;
UINT8 *BufferInPtr;
TLS_RECORD_HEADER *RecordHeaderIn;
UINT16 ThisPlainMessageSize;
TLS_RECORD_HEADER *TempRecordHeader;
UINT16 ThisMessageSize;
UINT32 BufferOutSize;
UINT8 *BufferOut;
UINT32 RecordCount;
INTN Ret;
Status = EFI_SUCCESS;
BytesCopied = 0;
@@ -91,14 +91,15 @@ TlsEncryptPacket (
// Count TLS record number.
//
BufferInPtr = BufferIn;
while ((UINTN) BufferInPtr < (UINTN) BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *) BufferInPtr;
if (RecordHeaderIn->ContentType != TlsContentTypeApplicationData || RecordHeaderIn->Length > TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH) {
while ((UINTN)BufferInPtr < (UINTN)BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *)BufferInPtr;
if ((RecordHeaderIn->ContentType != TlsContentTypeApplicationData) || (RecordHeaderIn->Length > TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH)) {
Status = EFI_INVALID_PARAMETER;
goto ERROR;
}
BufferInPtr += TLS_RECORD_HEADER_LENGTH + RecordHeaderIn->Length;
RecordCount ++;
RecordCount++;
}
//
@@ -113,19 +114,19 @@ TlsEncryptPacket (
//
// Parsing buffer. Received packet may have multiple TLS record messages.
//
BufferInPtr = BufferIn;
TempRecordHeader = (TLS_RECORD_HEADER *) BufferOut;
while ((UINTN) BufferInPtr < (UINTN) BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *) BufferInPtr;
BufferInPtr = BufferIn;
TempRecordHeader = (TLS_RECORD_HEADER *)BufferOut;
while ((UINTN)BufferInPtr < (UINTN)BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *)BufferInPtr;
ThisPlainMessageSize = RecordHeaderIn->Length;
TlsWrite (TlsInstance->TlsConn, (UINT8 *) (RecordHeaderIn + 1), ThisPlainMessageSize);
TlsWrite (TlsInstance->TlsConn, (UINT8 *)(RecordHeaderIn + 1), ThisPlainMessageSize);
Ret = TlsCtrlTrafficOut (TlsInstance->TlsConn, (UINT8 *)(TempRecordHeader), TLS_RECORD_HEADER_LENGTH + TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH);
if (Ret > 0) {
ThisMessageSize = (UINT16) Ret;
ThisMessageSize = (UINT16)Ret;
} else {
//
// No data was successfully encrypted, continue to encrypt other messages.
@@ -137,7 +138,7 @@ TlsEncryptPacket (
BufferOutSize += ThisMessageSize;
BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
TempRecordHeader = (TLS_RECORD_HEADER *)((UINT8 *)TempRecordHeader + ThisMessageSize);
}
@@ -153,9 +154,9 @@ TlsEncryptPacket (
goto ERROR;
}
(*FragmentTable)[0].FragmentBuffer = BufferOut;
(*FragmentTable)[0].FragmentLength = BufferOutSize;
*FragmentCount = 1;
(*FragmentTable)[0].FragmentBuffer = BufferOut;
(*FragmentTable)[0].FragmentLength = BufferOutSize;
*FragmentCount = 1;
return Status;
@@ -192,25 +193,25 @@ ERROR:
**/
EFI_STATUS
TlsDecryptPacket (
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
)
{
EFI_STATUS Status;
UINTN Index;
UINT32 BytesCopied;
UINT8 *BufferIn;
UINT32 BufferInSize;
UINT8 *BufferInPtr;
TLS_RECORD_HEADER *RecordHeaderIn;
UINT16 ThisCipherMessageSize;
TLS_RECORD_HEADER *TempRecordHeader;
UINT16 ThisPlainMessageSize;
UINT8 *BufferOut;
UINT32 BufferOutSize;
UINT32 RecordCount;
INTN Ret;
EFI_STATUS Status;
UINTN Index;
UINT32 BytesCopied;
UINT8 *BufferIn;
UINT32 BufferInSize;
UINT8 *BufferInPtr;
TLS_RECORD_HEADER *RecordHeaderIn;
UINT16 ThisCipherMessageSize;
TLS_RECORD_HEADER *TempRecordHeader;
UINT16 ThisPlainMessageSize;
UINT8 *BufferOut;
UINT32 BufferOutSize;
UINT32 RecordCount;
INTN Ret;
Status = EFI_SUCCESS;
BytesCopied = 0;
@@ -256,14 +257,15 @@ TlsDecryptPacket (
// Count TLS record number.
//
BufferInPtr = BufferIn;
while ((UINTN) BufferInPtr < (UINTN) BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *) BufferInPtr;
if (RecordHeaderIn->ContentType != TlsContentTypeApplicationData || NTOHS (RecordHeaderIn->Length) > TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH) {
while ((UINTN)BufferInPtr < (UINTN)BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *)BufferInPtr;
if ((RecordHeaderIn->ContentType != TlsContentTypeApplicationData) || (NTOHS (RecordHeaderIn->Length) > TLS_CIPHERTEXT_RECORD_MAX_PAYLOAD_LENGTH)) {
Status = EFI_INVALID_PARAMETER;
goto ERROR;
}
BufferInPtr += TLS_RECORD_HEADER_LENGTH + NTOHS (RecordHeaderIn->Length);
RecordCount ++;
RecordCount++;
}
//
@@ -278,25 +280,25 @@ TlsDecryptPacket (
//
// Parsing buffer. Received packet may have multiple TLS record messages.
//
BufferInPtr = BufferIn;
TempRecordHeader = (TLS_RECORD_HEADER *) BufferOut;
while ((UINTN) BufferInPtr < (UINTN) BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *) BufferInPtr;
BufferInPtr = BufferIn;
TempRecordHeader = (TLS_RECORD_HEADER *)BufferOut;
while ((UINTN)BufferInPtr < (UINTN)BufferIn + BufferInSize) {
RecordHeaderIn = (TLS_RECORD_HEADER *)BufferInPtr;
ThisCipherMessageSize = NTOHS (RecordHeaderIn->Length);
Ret = TlsCtrlTrafficIn (TlsInstance->TlsConn, (UINT8 *) (RecordHeaderIn), TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize);
Ret = TlsCtrlTrafficIn (TlsInstance->TlsConn, (UINT8 *)(RecordHeaderIn), TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize);
if (Ret != TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize) {
TlsInstance->TlsSessionState = EfiTlsSessionError;
Status = EFI_ABORTED;
Status = EFI_ABORTED;
goto ERROR;
}
Ret = 0;
Ret = TlsRead (TlsInstance->TlsConn, (UINT8 *) (TempRecordHeader + 1), TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH);
Ret = TlsRead (TlsInstance->TlsConn, (UINT8 *)(TempRecordHeader + 1), TLS_PLAINTEXT_RECORD_MAX_PAYLOAD_LENGTH);
if (Ret > 0) {
ThisPlainMessageSize = (UINT16) Ret;
ThisPlainMessageSize = (UINT16)Ret;
} else {
//
// No data was successfully decrypted, continue to decrypt other messages.
@@ -308,9 +310,9 @@ TlsDecryptPacket (
CopyMem (TempRecordHeader, RecordHeaderIn, TLS_RECORD_HEADER_LENGTH);
TempRecordHeader->Length = ThisPlainMessageSize;
BufferOutSize += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
BufferOutSize += TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize;
BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize;
BufferInPtr += TLS_RECORD_HEADER_LENGTH + ThisCipherMessageSize;
TempRecordHeader = (TLS_RECORD_HEADER *)((UINT8 *)TempRecordHeader + TLS_RECORD_HEADER_LENGTH + ThisPlainMessageSize);
}
@@ -326,9 +328,9 @@ TlsDecryptPacket (
goto ERROR;
}
(*FragmentTable)[0].FragmentBuffer = BufferOut;
(*FragmentTable)[0].FragmentLength = BufferOutSize;
*FragmentCount = 1;
(*FragmentTable)[0].FragmentBuffer = BufferOut;
(*FragmentTable)[0].FragmentLength = BufferOutSize;
*FragmentCount = 1;
return Status;

View File

@@ -58,9 +58,9 @@ extern EFI_TLS_CONFIGURATION_PROTOCOL mTlsConfigurationProtocol;
**/
EFI_STATUS
TlsEncryptPacket (
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
);
/**
@@ -81,9 +81,9 @@ TlsEncryptPacket (
**/
EFI_STATUS
TlsDecryptPacket (
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
IN TLS_INSTANCE *TlsInstance,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount
);
/**
@@ -114,10 +114,10 @@ TlsDecryptPacket (
EFI_STATUS
EFIAPI
TlsSetSessionData (
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN VOID *Data,
IN UINTN DataSize
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN VOID *Data,
IN UINTN DataSize
);
/**
@@ -146,10 +146,10 @@ TlsSetSessionData (
EFI_STATUS
EFIAPI
TlsGetSessionData (
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN OUT VOID *Data OPTIONAL,
IN OUT UINTN *DataSize
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN OUT VOID *Data OPTIONAL,
IN OUT UINTN *DataSize
);
/**
@@ -193,11 +193,11 @@ TlsGetSessionData (
EFI_STATUS
EFIAPI
TlsBuildResponsePacket (
IN EFI_TLS_PROTOCOL *This,
IN UINT8 *RequestBuffer OPTIONAL,
IN UINTN RequestSize OPTIONAL,
OUT UINT8 *Buffer OPTIONAL,
IN OUT UINTN *BufferSize
IN EFI_TLS_PROTOCOL *This,
IN UINT8 *RequestBuffer OPTIONAL,
IN UINTN RequestSize OPTIONAL,
OUT UINT8 *Buffer OPTIONAL,
IN OUT UINTN *BufferSize
);
/**
@@ -237,10 +237,10 @@ TlsBuildResponsePacket (
EFI_STATUS
EFIAPI
TlsProcessPacket (
IN EFI_TLS_PROTOCOL *This,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount,
IN EFI_TLS_CRYPT_MODE CryptMode
IN EFI_TLS_PROTOCOL *This,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount,
IN EFI_TLS_CRYPT_MODE CryptMode
);
/**

View File

@@ -45,29 +45,29 @@ EFI_TLS_PROTOCOL mTlsProtocol = {
EFI_STATUS
EFIAPI
TlsSetSessionData (
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN VOID *Data,
IN UINTN DataSize
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN VOID *Data,
IN UINTN DataSize
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
UINT16 *CipherId;
CONST EFI_TLS_CIPHER *TlsCipherList;
UINTN CipherCount;
CONST EFI_TLS_VERIFY_HOST *TlsVerifyHost;
EFI_TLS_VERIFY VerifyMethod;
UINTN VerifyMethodSize;
UINTN Index;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
UINT16 *CipherId;
CONST EFI_TLS_CIPHER *TlsCipherList;
UINTN CipherCount;
CONST EFI_TLS_VERIFY_HOST *TlsVerifyHost;
EFI_TLS_VERIFY VerifyMethod;
UINTN VerifyMethodSize;
UINTN Index;
EFI_TPL OldTpl;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
CipherId = NULL;
VerifyMethodSize = sizeof (EFI_TLS_VERIFY);
if (This == NULL || Data == NULL || DataSize == 0) {
if ((This == NULL) || (Data == NULL) || (DataSize == 0)) {
return EFI_INVALID_PARAMETER;
}
@@ -75,155 +75,157 @@ TlsSetSessionData (
Instance = TLS_INSTANCE_FROM_PROTOCOL (This);
if (DataType != EfiTlsSessionState && Instance->TlsSessionState != EfiTlsSessionNotStarted){
if ((DataType != EfiTlsSessionState) && (Instance->TlsSessionState != EfiTlsSessionNotStarted)) {
Status = EFI_NOT_READY;
goto ON_EXIT;
}
switch (DataType) {
//
// Session Configuration
//
case EfiTlsVersion:
if (DataSize != sizeof (EFI_TLS_VERSION)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetVersion (Instance->TlsConn, ((EFI_TLS_VERSION *) Data)->Major, ((EFI_TLS_VERSION *) Data)->Minor);
break;
case EfiTlsConnectionEnd:
if (DataSize != sizeof (EFI_TLS_CONNECTION_END)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetConnectionEnd (Instance->TlsConn, *((EFI_TLS_CONNECTION_END *) Data));
break;
case EfiTlsCipherList:
if (DataSize % sizeof (EFI_TLS_CIPHER) != 0) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
CipherId = AllocatePool (DataSize);
if (CipherId == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
TlsCipherList = (CONST EFI_TLS_CIPHER *) Data;
CipherCount = DataSize / sizeof (EFI_TLS_CIPHER);
for (Index = 0; Index < CipherCount; Index++) {
CipherId[Index] = ((TlsCipherList[Index].Data1 << 8) |
TlsCipherList[Index].Data2);
}
Status = TlsSetCipherList (Instance->TlsConn, CipherId, CipherCount);
FreePool (CipherId);
break;
case EfiTlsCompressionMethod:
//
// TLS seems only define one CompressionMethod.null, which specifies that data exchanged via the
// record protocol will not be compressed.
// More information from OpenSSL: http://www.openssl.org/docs/manmaster/ssl/SSL_COMP_add_compression_method.html
// The TLS RFC does however not specify compression methods or their corresponding identifiers,
// so there is currently no compatible way to integrate compression with unknown peers.
// It is therefore currently not recommended to integrate compression into applications.
// Applications for non-public use may agree on certain compression methods.
// Using different compression methods with the same identifier will lead to connection failure.
// Session Configuration
//
for (Index = 0; Index < DataSize / sizeof (EFI_TLS_COMPRESSION); Index++) {
Status = TlsSetCompressionMethod (*((UINT8 *) Data + Index));
if (EFI_ERROR (Status)) {
break;
case EfiTlsVersion:
if (DataSize != sizeof (EFI_TLS_VERSION)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
}
break;
case EfiTlsExtensionData:
Status = EFI_UNSUPPORTED;
goto ON_EXIT;
case EfiTlsVerifyMethod:
if (DataSize != sizeof (EFI_TLS_VERIFY)) {
Status = EFI_INVALID_PARAMETER;
Status = TlsSetVersion (Instance->TlsConn, ((EFI_TLS_VERSION *)Data)->Major, ((EFI_TLS_VERSION *)Data)->Minor);
break;
case EfiTlsConnectionEnd:
if (DataSize != sizeof (EFI_TLS_CONNECTION_END)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetConnectionEnd (Instance->TlsConn, *((EFI_TLS_CONNECTION_END *)Data));
break;
case EfiTlsCipherList:
if (DataSize % sizeof (EFI_TLS_CIPHER) != 0) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
CipherId = AllocatePool (DataSize);
if (CipherId == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
TlsCipherList = (CONST EFI_TLS_CIPHER *)Data;
CipherCount = DataSize / sizeof (EFI_TLS_CIPHER);
for (Index = 0; Index < CipherCount; Index++) {
CipherId[Index] = ((TlsCipherList[Index].Data1 << 8) |
TlsCipherList[Index].Data2);
}
Status = TlsSetCipherList (Instance->TlsConn, CipherId, CipherCount);
FreePool (CipherId);
break;
case EfiTlsCompressionMethod:
//
// TLS seems only define one CompressionMethod.null, which specifies that data exchanged via the
// record protocol will not be compressed.
// More information from OpenSSL: http://www.openssl.org/docs/manmaster/ssl/SSL_COMP_add_compression_method.html
// The TLS RFC does however not specify compression methods or their corresponding identifiers,
// so there is currently no compatible way to integrate compression with unknown peers.
// It is therefore currently not recommended to integrate compression into applications.
// Applications for non-public use may agree on certain compression methods.
// Using different compression methods with the same identifier will lead to connection failure.
//
for (Index = 0; Index < DataSize / sizeof (EFI_TLS_COMPRESSION); Index++) {
Status = TlsSetCompressionMethod (*((UINT8 *)Data + Index));
if (EFI_ERROR (Status)) {
break;
}
}
break;
case EfiTlsExtensionData:
Status = EFI_UNSUPPORTED;
goto ON_EXIT;
}
case EfiTlsVerifyMethod:
if (DataSize != sizeof (EFI_TLS_VERIFY)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
TlsSetVerify (Instance->TlsConn, *((UINT32 *) Data));
break;
case EfiTlsVerifyHost:
if (DataSize != sizeof (EFI_TLS_VERIFY_HOST)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
TlsSetVerify (Instance->TlsConn, *((UINT32 *)Data));
break;
case EfiTlsVerifyHost:
if (DataSize != sizeof (EFI_TLS_VERIFY_HOST)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
TlsVerifyHost = (CONST EFI_TLS_VERIFY_HOST *) Data;
TlsVerifyHost = (CONST EFI_TLS_VERIFY_HOST *)Data;
if ((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_ALWAYS_CHECK_SUBJECT) != 0 &&
(TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NEVER_CHECK_SUBJECT) != 0) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
if (((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_ALWAYS_CHECK_SUBJECT) != 0) &&
((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NEVER_CHECK_SUBJECT) != 0))
{
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
if ((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NO_WILDCARDS) != 0 &&
((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NO_PARTIAL_WILDCARDS) != 0 ||
(TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_MULTI_LABEL_WILDCARDS) != 0)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
if (((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NO_WILDCARDS) != 0) &&
(((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_NO_PARTIAL_WILDCARDS) != 0) ||
((TlsVerifyHost->Flags & EFI_TLS_VERIFY_FLAG_MULTI_LABEL_WILDCARDS) != 0)))
{
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = This->GetSessionData (This, EfiTlsVerifyMethod, &VerifyMethod, &VerifyMethodSize);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
Status = This->GetSessionData (This, EfiTlsVerifyMethod, &VerifyMethod, &VerifyMethodSize);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
if ((VerifyMethod & EFI_TLS_VERIFY_PEER) == 0) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
if ((VerifyMethod & EFI_TLS_VERIFY_PEER) == 0) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetVerifyHost (Instance->TlsConn, TlsVerifyHost->Flags, TlsVerifyHost->HostName);
Status = TlsSetVerifyHost (Instance->TlsConn, TlsVerifyHost->Flags, TlsVerifyHost->HostName);
break;
case EfiTlsSessionID:
if (DataSize != sizeof (EFI_TLS_SESSION_ID)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
break;
case EfiTlsSessionID:
if (DataSize != sizeof (EFI_TLS_SESSION_ID)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetSessionId (
Instance->TlsConn,
((EFI_TLS_SESSION_ID *) Data)->Data,
((EFI_TLS_SESSION_ID *) Data)->Length
);
break;
case EfiTlsSessionState:
if (DataSize != sizeof (EFI_TLS_SESSION_STATE)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = TlsSetSessionId (
Instance->TlsConn,
((EFI_TLS_SESSION_ID *)Data)->Data,
((EFI_TLS_SESSION_ID *)Data)->Length
);
break;
case EfiTlsSessionState:
if (DataSize != sizeof (EFI_TLS_SESSION_STATE)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Instance->TlsSessionState = *(EFI_TLS_SESSION_STATE *) Data;
break;
//
// Session information
//
case EfiTlsClientRandom:
Status = EFI_ACCESS_DENIED;
break;
case EfiTlsServerRandom:
Status = EFI_ACCESS_DENIED;
break;
case EfiTlsKeyMaterial:
Status = EFI_ACCESS_DENIED;
break;
//
// Unsupported type.
//
default:
Status = EFI_UNSUPPORTED;
Instance->TlsSessionState = *(EFI_TLS_SESSION_STATE *)Data;
break;
//
// Session information
//
case EfiTlsClientRandom:
Status = EFI_ACCESS_DENIED;
break;
case EfiTlsServerRandom:
Status = EFI_ACCESS_DENIED;
break;
case EfiTlsKeyMaterial:
Status = EFI_ACCESS_DENIED;
break;
//
// Unsupported type.
//
default:
Status = EFI_UNSUPPORTED;
}
ON_EXIT:
@@ -257,20 +259,20 @@ ON_EXIT:
EFI_STATUS
EFIAPI
TlsGetSessionData (
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN OUT VOID *Data OPTIONAL,
IN OUT UINTN *DataSize
IN EFI_TLS_PROTOCOL *This,
IN EFI_TLS_SESSION_DATA_TYPE DataType,
IN OUT VOID *Data OPTIONAL,
IN OUT UINTN *DataSize
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
if (This == NULL || DataSize == NULL || (Data == NULL && *DataSize != 0)) {
if ((This == NULL) || (DataSize == NULL) || ((Data == NULL) && (*DataSize != 0))) {
return EFI_INVALID_PARAMETER;
}
@@ -278,123 +280,134 @@ TlsGetSessionData (
Instance = TLS_INSTANCE_FROM_PROTOCOL (This);
if (Instance->TlsSessionState == EfiTlsSessionNotStarted &&
(DataType == EfiTlsSessionID || DataType == EfiTlsClientRandom ||
DataType == EfiTlsServerRandom || DataType == EfiTlsKeyMaterial)) {
if ((Instance->TlsSessionState == EfiTlsSessionNotStarted) &&
((DataType == EfiTlsSessionID) || (DataType == EfiTlsClientRandom) ||
(DataType == EfiTlsServerRandom) || (DataType == EfiTlsKeyMaterial)))
{
Status = EFI_NOT_READY;
goto ON_EXIT;
}
switch (DataType) {
case EfiTlsVersion:
if (*DataSize < sizeof (EFI_TLS_VERSION)) {
*DataSize = sizeof (EFI_TLS_VERSION);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_VERSION);
*((UINT16 *) Data) = HTONS (TlsGetVersion (Instance->TlsConn));
break;
case EfiTlsConnectionEnd:
if (*DataSize < sizeof (EFI_TLS_CONNECTION_END)) {
*DataSize = sizeof (EFI_TLS_CONNECTION_END);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_CONNECTION_END);
*((UINT8 *) Data) = TlsGetConnectionEnd (Instance->TlsConn);
break;
case EfiTlsCipherList:
//
// Get the current session cipher suite.
//
if (*DataSize < sizeof (EFI_TLS_CIPHER)) {
*DataSize = sizeof (EFI_TLS_CIPHER);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof(EFI_TLS_CIPHER);
Status = TlsGetCurrentCipher (Instance->TlsConn, (UINT16 *) Data);
*((UINT16 *) Data) = HTONS (*((UINT16 *) Data));
break;
case EfiTlsCompressionMethod:
//
// Get the current session compression method.
//
if (*DataSize < sizeof (EFI_TLS_COMPRESSION)) {
case EfiTlsVersion:
if (*DataSize < sizeof (EFI_TLS_VERSION)) {
*DataSize = sizeof (EFI_TLS_VERSION);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_VERSION);
*((UINT16 *)Data) = HTONS (TlsGetVersion (Instance->TlsConn));
break;
case EfiTlsConnectionEnd:
if (*DataSize < sizeof (EFI_TLS_CONNECTION_END)) {
*DataSize = sizeof (EFI_TLS_CONNECTION_END);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_CONNECTION_END);
*((UINT8 *)Data) = TlsGetConnectionEnd (Instance->TlsConn);
break;
case EfiTlsCipherList:
//
// Get the current session cipher suite.
//
if (*DataSize < sizeof (EFI_TLS_CIPHER)) {
*DataSize = sizeof (EFI_TLS_CIPHER);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_CIPHER);
Status = TlsGetCurrentCipher (Instance->TlsConn, (UINT16 *)Data);
*((UINT16 *)Data) = HTONS (*((UINT16 *)Data));
break;
case EfiTlsCompressionMethod:
//
// Get the current session compression method.
//
if (*DataSize < sizeof (EFI_TLS_COMPRESSION)) {
*DataSize = sizeof (EFI_TLS_COMPRESSION);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_COMPRESSION);
Status = EFI_BUFFER_TOO_SMALL;
Status = TlsGetCurrentCompressionId (Instance->TlsConn, (UINT8 *)Data);
break;
case EfiTlsExtensionData:
Status = EFI_UNSUPPORTED;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_COMPRESSION);
Status = TlsGetCurrentCompressionId (Instance->TlsConn, (UINT8 *) Data);
break;
case EfiTlsExtensionData:
Status = EFI_UNSUPPORTED;
goto ON_EXIT;
case EfiTlsVerifyMethod:
if (*DataSize < sizeof (EFI_TLS_VERIFY)) {
*DataSize = sizeof (EFI_TLS_VERIFY);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_VERIFY);
*((UINT32 *) Data) = TlsGetVerify (Instance->TlsConn);
break;
case EfiTlsSessionID:
if (*DataSize < sizeof (EFI_TLS_SESSION_ID)) {
case EfiTlsVerifyMethod:
if (*DataSize < sizeof (EFI_TLS_VERIFY)) {
*DataSize = sizeof (EFI_TLS_VERIFY);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_VERIFY);
*((UINT32 *)Data) = TlsGetVerify (Instance->TlsConn);
break;
case EfiTlsSessionID:
if (*DataSize < sizeof (EFI_TLS_SESSION_ID)) {
*DataSize = sizeof (EFI_TLS_SESSION_ID);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_SESSION_ID);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_SESSION_ID);
Status = TlsGetSessionId (
Instance->TlsConn,
((EFI_TLS_SESSION_ID *) Data)->Data,
&(((EFI_TLS_SESSION_ID *) Data)->Length)
);
break;
case EfiTlsSessionState:
if (*DataSize < sizeof (EFI_TLS_SESSION_STATE)) {
Status = TlsGetSessionId (
Instance->TlsConn,
((EFI_TLS_SESSION_ID *)Data)->Data,
&(((EFI_TLS_SESSION_ID *)Data)->Length)
);
break;
case EfiTlsSessionState:
if (*DataSize < sizeof (EFI_TLS_SESSION_STATE)) {
*DataSize = sizeof (EFI_TLS_SESSION_STATE);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_SESSION_STATE);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_SESSION_STATE);
CopyMem (Data, &Instance->TlsSessionState, *DataSize);
break;
case EfiTlsClientRandom:
if (*DataSize < sizeof (EFI_TLS_RANDOM)) {
CopyMem (Data, &Instance->TlsSessionState, *DataSize);
break;
case EfiTlsClientRandom:
if (*DataSize < sizeof (EFI_TLS_RANDOM)) {
*DataSize = sizeof (EFI_TLS_RANDOM);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_RANDOM);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_RANDOM);
TlsGetClientRandom (Instance->TlsConn, (UINT8 *) Data);
break;
case EfiTlsServerRandom:
if (*DataSize < sizeof (EFI_TLS_RANDOM)) {
TlsGetClientRandom (Instance->TlsConn, (UINT8 *)Data);
break;
case EfiTlsServerRandom:
if (*DataSize < sizeof (EFI_TLS_RANDOM)) {
*DataSize = sizeof (EFI_TLS_RANDOM);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_RANDOM);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_RANDOM);
TlsGetServerRandom (Instance->TlsConn, (UINT8 *) Data);
break;
case EfiTlsKeyMaterial:
if (*DataSize < sizeof (EFI_TLS_MASTER_SECRET)) {
TlsGetServerRandom (Instance->TlsConn, (UINT8 *)Data);
break;
case EfiTlsKeyMaterial:
if (*DataSize < sizeof (EFI_TLS_MASTER_SECRET)) {
*DataSize = sizeof (EFI_TLS_MASTER_SECRET);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_MASTER_SECRET);
Status = EFI_BUFFER_TOO_SMALL;
goto ON_EXIT;
}
*DataSize = sizeof (EFI_TLS_MASTER_SECRET);
Status = TlsGetKeyMaterial (Instance->TlsConn, (UINT8 *) Data);
break;
//
// Unsupported type.
//
default:
Status = EFI_UNSUPPORTED;
Status = TlsGetKeyMaterial (Instance->TlsConn, (UINT8 *)Data);
break;
//
// Unsupported type.
//
default:
Status = EFI_UNSUPPORTED;
}
ON_EXIT:
@@ -443,23 +456,24 @@ ON_EXIT:
EFI_STATUS
EFIAPI
TlsBuildResponsePacket (
IN EFI_TLS_PROTOCOL *This,
IN UINT8 *RequestBuffer OPTIONAL,
IN UINTN RequestSize OPTIONAL,
OUT UINT8 *Buffer OPTIONAL,
IN OUT UINTN *BufferSize
IN EFI_TLS_PROTOCOL *This,
IN UINT8 *RequestBuffer OPTIONAL,
IN UINTN RequestSize OPTIONAL,
OUT UINT8 *Buffer OPTIONAL,
IN OUT UINTN *BufferSize
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
if ((This == NULL) || (BufferSize == NULL) ||
(RequestBuffer == NULL && RequestSize != 0) ||
(RequestBuffer != NULL && RequestSize == 0) ||
(Buffer == NULL && *BufferSize !=0)) {
((RequestBuffer == NULL) && (RequestSize != 0)) ||
((RequestBuffer != NULL) && (RequestSize == 0)) ||
((Buffer == NULL) && (*BufferSize != 0)))
{
return EFI_INVALID_PARAMETER;
}
@@ -467,78 +481,78 @@ TlsBuildResponsePacket (
Instance = TLS_INSTANCE_FROM_PROTOCOL (This);
if(RequestBuffer == NULL && RequestSize == 0) {
if ((RequestBuffer == NULL) && (RequestSize == 0)) {
switch (Instance->TlsSessionState) {
case EfiTlsSessionNotStarted:
//
// ClientHello.
//
Status = TlsDoHandshake (
Instance->TlsConn,
NULL,
0,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
case EfiTlsSessionNotStarted:
//
// ClientHello.
//
Status = TlsDoHandshake (
Instance->TlsConn,
NULL,
0,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
//
// *BufferSize should not be zero when ClientHello.
//
if (*BufferSize == 0) {
Status = EFI_ABORTED;
goto ON_EXIT;
}
//
// *BufferSize should not be zero when ClientHello.
//
if (*BufferSize == 0) {
Status = EFI_ABORTED;
goto ON_EXIT;
}
Instance->TlsSessionState = EfiTlsSessionHandShaking;
Instance->TlsSessionState = EfiTlsSessionHandShaking;
break;
case EfiTlsSessionClosing:
//
// TLS session will be closed and response packet needs to be CloseNotify.
//
Status = TlsCloseNotify (
Instance->TlsConn,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
break;
case EfiTlsSessionClosing:
//
// TLS session will be closed and response packet needs to be CloseNotify.
//
Status = TlsCloseNotify (
Instance->TlsConn,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
//
// *BufferSize should not be zero when build CloseNotify message.
//
if (*BufferSize == 0) {
Status = EFI_ABORTED;
goto ON_EXIT;
}
//
// *BufferSize should not be zero when build CloseNotify message.
//
if (*BufferSize == 0) {
Status = EFI_ABORTED;
goto ON_EXIT;
}
break;
case EfiTlsSessionError:
//
// TLS session has errors and the response packet needs to be Alert
// message based on error type.
//
Status = TlsHandleAlert (
Instance->TlsConn,
NULL,
0,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
break;
case EfiTlsSessionError:
//
// TLS session has errors and the response packet needs to be Alert
// message based on error type.
//
Status = TlsHandleAlert (
Instance->TlsConn,
NULL,
0,
Buffer,
BufferSize
);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
break;
default:
//
// Current TLS session state is NOT ready to build ResponsePacket.
//
Status = EFI_NOT_READY;
break;
default:
//
// Current TLS session state is NOT ready to build ResponsePacket.
//
Status = EFI_NOT_READY;
}
} else {
//
@@ -566,7 +580,7 @@ TlsBuildResponsePacket (
//
// Must be alert message, Decrypt it and build the ResponsePacket.
//
ASSERT (((TLS_RECORD_HEADER *) RequestBuffer)->ContentType == TlsContentTypeAlert);
ASSERT (((TLS_RECORD_HEADER *)RequestBuffer)->ContentType == TlsContentTypeAlert);
Status = TlsHandleAlert (
Instance->TlsConn,
@@ -627,20 +641,20 @@ ON_EXIT:
EFI_STATUS
EFIAPI
TlsProcessPacket (
IN EFI_TLS_PROTOCOL *This,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount,
IN EFI_TLS_CRYPT_MODE CryptMode
IN EFI_TLS_PROTOCOL *This,
IN OUT EFI_TLS_FRAGMENT_DATA **FragmentTable,
IN UINT32 *FragmentCount,
IN EFI_TLS_CRYPT_MODE CryptMode
)
{
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_STATUS Status;
TLS_INSTANCE *Instance;
EFI_TPL OldTpl;
EFI_TPL OldTpl;
Status = EFI_SUCCESS;
if (This == NULL || FragmentTable == NULL || FragmentCount == NULL) {
if ((This == NULL) || (FragmentTable == NULL) || (FragmentCount == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -659,14 +673,14 @@ TlsProcessPacket (
// on output these fragments also contain the TLS header and TLS APP payload.
//
switch (CryptMode) {
case EfiTlsEncrypt:
Status = TlsEncryptPacket (Instance, FragmentTable, FragmentCount);
break;
case EfiTlsDecrypt:
Status = TlsDecryptPacket (Instance, FragmentTable, FragmentCount);
break;
default:
return EFI_INVALID_PARAMETER;
case EfiTlsEncrypt:
Status = TlsEncryptPacket (Instance, FragmentTable, FragmentCount);
break;
case EfiTlsDecrypt:
Status = TlsDecryptPacket (Instance, FragmentTable, FragmentCount);
break;
default:
return EFI_INVALID_PARAMETER;
}
ON_EXIT: