IScsiCHAP.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /** @file
  2. The header file of CHAP configuration.
  3. Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _ISCSI_CHAP_H_
  7. #define _ISCSI_CHAP_H_
  8. #define ISCSI_AUTH_METHOD_CHAP "CHAP"
  9. #define ISCSI_KEY_CHAP_ALGORITHM "CHAP_A"
  10. #define ISCSI_KEY_CHAP_IDENTIFIER "CHAP_I"
  11. #define ISCSI_KEY_CHAP_CHALLENGE "CHAP_C"
  12. #define ISCSI_KEY_CHAP_NAME "CHAP_N"
  13. #define ISCSI_KEY_CHAP_RESPONSE "CHAP_R"
  14. //
  15. // Identifiers of supported CHAP hash algorithms:
  16. // https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml#ppp-numbers-9
  17. //
  18. #define ISCSI_CHAP_ALGORITHM_MD5 5
  19. #define ISCSI_CHAP_ALGORITHM_SHA256 7
  20. //
  21. // Byte count of the largest digest over the above-listed
  22. // ISCSI_CHAP_ALGORITHM_* hash algorithms.
  23. //
  24. #define ISCSI_CHAP_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
  25. #define ISCSI_CHAP_STEP_ONE 1
  26. #define ISCSI_CHAP_STEP_TWO 2
  27. #define ISCSI_CHAP_STEP_THREE 3
  28. #define ISCSI_CHAP_STEP_FOUR 4
  29. #pragma pack(1)
  30. typedef struct _ISCSI_CHAP_AUTH_CONFIG_NVDATA {
  31. UINT8 CHAPType;
  32. CHAR8 CHAPName[ISCSI_CHAP_NAME_STORAGE];
  33. CHAR8 CHAPSecret[ISCSI_CHAP_SECRET_STORAGE];
  34. CHAR8 ReverseCHAPName[ISCSI_CHAP_NAME_STORAGE];
  35. CHAR8 ReverseCHAPSecret[ISCSI_CHAP_SECRET_STORAGE];
  36. } ISCSI_CHAP_AUTH_CONFIG_NVDATA;
  37. #pragma pack()
  38. //
  39. // Typedefs for collecting sets of hash APIs from BaseCryptLib.
  40. //
  41. typedef
  42. UINTN
  43. (EFIAPI *CHAP_HASH_GET_CONTEXT_SIZE)(
  44. VOID
  45. );
  46. typedef
  47. BOOLEAN
  48. (EFIAPI *CHAP_HASH_INIT)(
  49. OUT VOID *Context
  50. );
  51. typedef
  52. BOOLEAN
  53. (EFIAPI *CHAP_HASH_UPDATE)(
  54. IN OUT VOID *Context,
  55. IN CONST VOID *Data,
  56. IN UINTN DataSize
  57. );
  58. typedef
  59. BOOLEAN
  60. (EFIAPI *CHAP_HASH_FINAL)(
  61. IN OUT VOID *Context,
  62. OUT UINT8 *HashValue
  63. );
  64. typedef struct {
  65. UINT8 Algorithm; // ISCSI_CHAP_ALGORITHM_*, CHAP_A
  66. UINT32 DigestSize;
  67. CHAP_HASH_GET_CONTEXT_SIZE GetContextSize;
  68. CHAP_HASH_INIT Init;
  69. CHAP_HASH_UPDATE Update;
  70. CHAP_HASH_FINAL Final;
  71. } CHAP_HASH;
  72. ///
  73. /// ISCSI CHAP Authentication Data
  74. ///
  75. typedef struct _ISCSI_CHAP_AUTH_DATA {
  76. ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;
  77. UINT32 InIdentifier;
  78. UINT8 InChallenge[1024];
  79. UINT32 InChallengeLength;
  80. //
  81. // The hash algorithm (CHAP_A) that the target selects in
  82. // ISCSI_CHAP_STEP_TWO.
  83. //
  84. CONST CHAP_HASH *Hash;
  85. //
  86. // Calculated CHAP Response (CHAP_R) value.
  87. //
  88. UINT8 CHAPResponse[ISCSI_CHAP_MAX_DIGEST_SIZE];
  89. //
  90. // Auth-data to be sent out for mutual authentication.
  91. //
  92. // While the challenge size is technically independent of the hashing
  93. // algorithm, it is good practice to avoid hashing *fewer bytes* than the
  94. // digest size. In other words, it's good practice to feed *at least as many
  95. // bytes* to the hashing algorithm as the hashing algorithm will output.
  96. //
  97. UINT32 OutIdentifier;
  98. UINT8 OutChallenge[ISCSI_CHAP_MAX_DIGEST_SIZE];
  99. } ISCSI_CHAP_AUTH_DATA;
  100. /**
  101. This function checks the received iSCSI Login Response during the security
  102. negotiation stage.
  103. @param[in] Conn The iSCSI connection.
  104. @retval EFI_SUCCESS The Login Response passed the CHAP validation.
  105. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
  106. @retval EFI_PROTOCOL_ERROR Some kind of protocol error occurred.
  107. @retval Others Other errors as indicated.
  108. **/
  109. EFI_STATUS
  110. IScsiCHAPOnRspReceived (
  111. IN ISCSI_CONNECTION *Conn
  112. );
  113. /**
  114. This function fills the CHAP authentication information into the login PDU
  115. during the security negotiation stage in the iSCSI connection login.
  116. @param[in] Conn The iSCSI connection.
  117. @param[in, out] Pdu The PDU to send out.
  118. @retval EFI_SUCCESS All check passed and the phase-related CHAP
  119. authentication info is filled into the iSCSI
  120. PDU.
  121. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
  122. @retval EFI_PROTOCOL_ERROR Some kind of protocol error occurred.
  123. **/
  124. EFI_STATUS
  125. IScsiCHAPToSendReq (
  126. IN ISCSI_CONNECTION *Conn,
  127. IN OUT NET_BUF *Pdu
  128. );
  129. /**
  130. Initialize the CHAP_A=<A1,A2...> *value* string for the entire driver, to be
  131. sent by the initiator in ISCSI_CHAP_STEP_ONE.
  132. This function sanity-checks the internal table of supported CHAP hashing
  133. algorithms, as well.
  134. **/
  135. VOID
  136. IScsiCHAPInitHashList (
  137. VOID
  138. );
  139. #endif