20 ISCSI_CHAP_ALGORITHM_SHA256,
27 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
33 ISCSI_CHAP_ALGORITHM_MD5,
48STATIC CHAR8 mChapHashListString[
86 IN UINT32 ChapIdentifier,
88 IN UINT32 SecretLength,
89 IN UINT8 *ChapChallenge,
90 IN UINT32 ChallengeLength,
92 OUT UINT8 *ChapResponse
100 if (SecretLength < ISCSI_CHAP_SECRET_MIN_LEN) {
101 return EFI_PROTOCOL_ERROR;
104 ASSERT (Hash !=
NULL);
106 ContextSize = Hash->GetContextSize ();
109 return EFI_OUT_OF_RESOURCES;
112 Status = EFI_PROTOCOL_ERROR;
114 if (!Hash->Init (Ctx)) {
121 IdByte[0] = (CHAR8)ChapIdentifier;
122 if (!Hash->Update (Ctx, IdByte, 1)) {
129 if (!Hash->Update (Ctx, ChapSecret, SecretLength)) {
136 if (!Hash->Update (Ctx, ChapChallenge, ChallengeLength)) {
140 if (Hash->Final (Ctx, ChapResponse)) {
166 IN UINT8 *TargetResponse
171 UINT8 VerifyRsp[ISCSI_CHAP_MAX_DIGEST_SIZE];
176 SecretSize = (UINT32)
AsciiStrLen (AuthData->AuthConfig->ReverseCHAPSecret);
178 ASSERT (AuthData->Hash !=
NULL);
181 AuthData->OutIdentifier,
182 AuthData->AuthConfig->ReverseCHAPSecret,
184 AuthData->OutChallenge,
185 AuthData->Hash->DigestSize,
193 AuthData->Hash->DigestSize
196 Status = EFI_SECURITY_VIOLATION;
231 UINT8 TargetRsp[ISCSI_CHAP_MAX_DIGEST_SIZE];
236 ASSERT (Conn->CurrentStage == ISCSI_SECURITY_NEGOTIATION);
237 ASSERT (Conn->RspQue.BufNum != 0);
239 Session = Conn->Session;
240 AuthData = &Session->AuthData.CHAP;
241 Len = Conn->RspQue.BufSize;
244 return EFI_OUT_OF_RESOURCES;
256 if (KeyValueList ==
NULL) {
257 Status = EFI_OUT_OF_RESOURCES;
261 Status = EFI_PROTOCOL_ERROR;
263 switch (Conn->AuthStep) {
264 case ISCSI_AUTH_INITIAL:
270 ISCSI_KEY_TARGET_PORTAL_GROUP_TAG
277 if (Result > 0xFFFF) {
281 Session->TargetPortalGroupTag = (UINT16)Result;
285 ISCSI_KEY_AUTH_METHOD
296 if (Session->AuthType == ISCSI_AUTH_TYPE_NONE) {
297 if (
AsciiStrCmp (Value, ISCSI_KEY_VALUE_NONE) != 0) {
300 }
else if (Session->AuthType == ISCSI_AUTH_TYPE_CHAP) {
301 if (
AsciiStrCmp (Value, ISCSI_AUTH_METHOD_CHAP) != 0) {
311 Conn->AuthStep = ISCSI_CHAP_STEP_ONE;
315 case ISCSI_CHAP_STEP_TWO:
321 ISCSI_KEY_CHAP_ALGORITHM
328 for (HashIndex = 0; HashIndex <
ARRAY_SIZE (mChapHash); HashIndex++) {
329 if (Algorithm == mChapHash[HashIndex].Algorithm) {
344 ASSERT (AuthData->Hash ==
NULL);
345 AuthData->Hash = &mChapHash[HashIndex];
349 ISCSI_KEY_CHAP_IDENTIFIER
351 if (Identifier ==
NULL) {
357 ISCSI_KEY_CHAP_CHALLENGE
359 if (Challenge ==
NULL) {
372 AuthData->InIdentifier = (UINT32)Result;
373 AuthData->InChallengeLength = (UINT32)
sizeof (AuthData->InChallenge);
375 (UINT8 *)AuthData->InChallenge,
376 &AuthData->InChallengeLength,
379 if (EFI_ERROR (Status)) {
380 Status = EFI_PROTOCOL_ERROR;
385 AuthData->InIdentifier,
386 AuthData->AuthConfig->CHAPSecret,
387 (UINT32)
AsciiStrLen (AuthData->AuthConfig->CHAPSecret),
388 AuthData->InChallenge,
389 AuthData->InChallengeLength,
391 AuthData->CHAPResponse
397 Conn->AuthStep = ISCSI_CHAP_STEP_THREE;
400 case ISCSI_CHAP_STEP_THREE:
408 case ISCSI_CHAP_STEP_FOUR:
409 ASSERT (AuthData->AuthConfig->CHAPType == ISCSI_CHAP_MUTUAL);
420 ISCSI_KEY_CHAP_RESPONSE
422 if (Response ==
NULL) {
426 ASSERT (AuthData->Hash !=
NULL);
427 RspLen = AuthData->Hash->DigestSize;
429 if (EFI_ERROR (Status) || (RspLen != AuthData->Hash->DigestSize)) {
430 Status = EFI_PROTOCOL_ERROR;
446 if (KeyValueList !=
NULL) {
487 ASSERT (Conn->CurrentStage == ISCSI_SECURITY_NEGOTIATION);
489 Session = Conn->Session;
490 AuthData = &Session->AuthData.CHAP;
492 if (LoginReq ==
NULL) {
493 return EFI_PROTOCOL_ERROR;
498 RspLen = 2 * ISCSI_CHAP_MAX_DIGEST_SIZE + 3;
500 if (Response ==
NULL) {
501 return EFI_OUT_OF_RESOURCES;
504 ChallengeLen = 2 * ISCSI_CHAP_MAX_DIGEST_SIZE + 3;
506 if (Challenge ==
NULL) {
508 return EFI_OUT_OF_RESOURCES;
511 switch (Conn->AuthStep) {
512 case ISCSI_AUTH_INITIAL:
519 ISCSI_KEY_INITIATOR_NAME,
520 mPrivate->InitiatorName
525 ISCSI_KEY_TARGET_NAME,
526 Session->ConfigData->SessionConfigData.TargetName
529 if (Session->AuthType == ISCSI_AUTH_TYPE_NONE) {
530 Value = ISCSI_KEY_VALUE_NONE;
531 ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT);
533 Value = ISCSI_AUTH_METHOD_CHAP;
540 case ISCSI_CHAP_STEP_ONE:
547 Conn->AuthStep = ISCSI_CHAP_STEP_TWO;
550 case ISCSI_CHAP_STEP_THREE:
561 (CHAR8 *)&AuthData->AuthConfig->CHAPName
566 ASSERT (AuthData->Hash !=
NULL);
568 (UINT8 *)AuthData->CHAPResponse,
569 AuthData->Hash->DigestSize,
576 if (AuthData->AuthConfig->CHAPType == ISCSI_CHAP_MUTUAL) {
581 if (EFI_ERROR (Status)) {
585 AsciiSPrint (ValueStr,
sizeof (ValueStr),
"%d", AuthData->OutIdentifier);
591 (UINT8 *)AuthData->OutChallenge,
592 AuthData->Hash->DigestSize
594 if (EFI_ERROR (Status)) {
599 (UINT8 *)AuthData->OutChallenge,
600 AuthData->Hash->DigestSize,
607 Conn->AuthStep = ISCSI_CHAP_STEP_FOUR;
613 ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT);
617 Status = EFI_PROTOCOL_ERROR;
645 Position = mChapHashListString;
646 Left =
sizeof (mChapHashListString);
647 for (HashIndex = 0; HashIndex <
ARRAY_SIZE (mChapHash); HashIndex++) {
648 Hash = &mChapHash[HashIndex];
661 (HashIndex == 0) ?
"" :
",",
672 ASSERT (Printed + 1 < Left);
680 ASSERT (Hash->DigestSize <= ISCSI_CHAP_MAX_DIGEST_SIZE);
UINTN EFIAPI Sha256GetContextSize(VOID)
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN EFIAPI Md5Final(IN OUT VOID *Md5Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Md5Update(IN OUT VOID *Md5Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI Md5Init(OUT VOID *Md5Context)
UINTN EFIAPI Md5GetContextSize(VOID)
EFI_STATUS IScsiCHAPAuthTarget(IN ISCSI_CHAP_AUTH_DATA *AuthData, IN UINT8 *TargetResponse)
EFI_STATUS IScsiCHAPToSendReq(IN ISCSI_CONNECTION *Conn, IN OUT NET_BUF *Pdu)
VOID IScsiCHAPInitHashList(VOID)
EFI_STATUS IScsiCHAPOnRspReceived(IN ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiCHAPCalculateResponse(IN UINT32 ChapIdentifier, IN CHAR8 *ChapSecret, IN UINT32 SecretLength, IN UINT8 *ChapChallenge, IN UINT32 ChallengeLength, IN CONST CHAP_HASH *Hash, OUT UINT8 *ChapResponse)
UINTN IScsiNetNtoi(IN CHAR8 *Str)
EFI_STATUS IScsiHexToBin(IN OUT UINT8 *BinBuffer, IN OUT UINT32 *BinLength, IN CHAR8 *HexStr)
EFI_STATUS IScsiGenRandom(IN OUT UINT8 *Rand, IN UINTN RandLength)
EFI_STATUS IScsiBinToHex(IN UINT8 *BinBuffer, IN UINT32 BinLength, IN OUT CHAR8 *HexStr, IN OUT UINT32 *HexLength)
VOID IScsiFreeKeyValueList(IN LIST_ENTRY *KeyValueList)
CHAR8 * IScsiGetValueByKeyFromList(IN OUT LIST_ENTRY *KeyValueList, IN CHAR8 *Key)
LIST_ENTRY * IScsiBuildKeyValueList(IN CHAR8 *Data, IN UINT32 Len)
EFI_STATUS IScsiAddKeyValuePair(IN OUT NET_BUF *Pdu, IN CHAR8 *Key, IN CHAR8 *Value)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ARRAY_SIZE(Array)
#define ASSERT_EFI_ERROR(StatusParameter)
UINT32 EFIAPI NetbufQueCopy(IN NET_BUF_QUEUE *NbufQue, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest)
UINT8 *EFIAPI NetbufGetByte(IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID EFIAPI Exit(IN EFI_STATUS Status)