Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
13 KiB

  1. //============================================================================//
  2. // MODULE: eapol.c //
  3. // //
  4. // Description: EAPOL/802.1X Parser //
  5. // //
  6. // Note: info for this parsers was gleaned from :
  7. // IEEE 802.1X
  8. // //
  9. // Modification History //
  10. // //
  11. // timmoore 04/04/2000 Created //
  12. //===========================================================================//
  13. #include "eapol.h"
  14. // the type of EAPOL packet
  15. LABELED_BYTE lbEAPOLCode[] =
  16. {
  17. { EAPOL_PACKET, "Packet" },
  18. { EAPOL_START, "Start" },
  19. { EAPOL_LOGOFF, "Logoff" },
  20. { EAPOL_KEY, "Key" },
  21. };
  22. SET EAPOLCodeSET = {(sizeof(lbEAPOLCode)/sizeof(LABELED_BYTE)), lbEAPOLCode };
  23. // property table
  24. PROPERTYINFO EAPOL_Prop[] = {
  25. //EAPOL_SUMMARY
  26. { 0, 0,
  27. "Summary",
  28. "Summary of EAPOL packet",
  29. PROP_TYPE_SUMMARY,
  30. PROP_QUAL_NONE,
  31. NULL,
  32. 80,
  33. EAPOL_FormatSummary
  34. },
  35. //EAPOL_VERSION
  36. { 0, 0,
  37. "Version",
  38. "EAPOL packet type",
  39. PROP_TYPE_BYTE,
  40. PROP_QUAL_NONE,
  41. NULL,
  42. 80,
  43. FormatPropertyInstance
  44. },
  45. //EAPOL_TYPE
  46. { 0, 0,
  47. "Type",
  48. "EAPOL packet type",
  49. PROP_TYPE_BYTE,
  50. PROP_QUAL_LABELED_SET,
  51. &EAPOLCodeSET,
  52. 80,
  53. FormatPropertyInstance
  54. },
  55. //EAPOL_LENGTH
  56. { 0, 0,
  57. "Length",
  58. "EAPOL length",
  59. PROP_TYPE_BYTESWAPPED_WORD,
  60. PROP_QUAL_NONE,
  61. NULL,
  62. 80,
  63. FormatPropertyInstance
  64. },
  65. //EAPOL_KEY_SIGNTYPE
  66. { 0, 0,
  67. "Signature Type",
  68. "EAPOL Signature Type",
  69. PROP_TYPE_BYTE,
  70. PROP_QUAL_NONE,
  71. NULL,
  72. 80,
  73. FormatPropertyInstance
  74. },
  75. //EAPOL_KEY_KEYTYPE
  76. { 0, 0,
  77. "Key Type",
  78. "EAPOL Key Type",
  79. PROP_TYPE_BYTE,
  80. PROP_QUAL_NONE,
  81. NULL,
  82. 80,
  83. FormatPropertyInstance
  84. },
  85. //EAPOL_KEY_KEYLENGTH
  86. { 0, 0,
  87. "Length",
  88. "EAPOL Key length",
  89. PROP_TYPE_BYTESWAPPED_WORD,
  90. PROP_QUAL_NONE,
  91. NULL,
  92. 80,
  93. FormatPropertyInstance
  94. },
  95. //EAPOL_KEY_REPLAY
  96. { 0, 0,
  97. "Replay",
  98. "EAPOL Replay Counter",
  99. PROP_TYPE_BYTE,
  100. PROP_QUAL_ARRAY,
  101. NULL,
  102. 80,
  103. FormatPropertyInstance
  104. },
  105. //EAPOL_KEY_KEYIV
  106. { 0, 0,
  107. "Key IV",
  108. "EAPOL Key IV",
  109. PROP_TYPE_BYTE,
  110. PROP_QUAL_ARRAY,
  111. NULL,
  112. 80,
  113. FormatPropertyInstance
  114. },
  115. //EAPOL_KEY_KEYINDEX
  116. { 0, 0,
  117. "Index",
  118. "EAPOL Key Index",
  119. PROP_TYPE_BYTE,
  120. PROP_QUAL_NONE,
  121. NULL,
  122. 80,
  123. FormatPropertyInstance
  124. },
  125. //EAPOL_KEY_KEYSIGN
  126. { 0, 0,
  127. "Key Signature",
  128. "EAPOL Key Signature",
  129. PROP_TYPE_BYTE,
  130. PROP_QUAL_ARRAY,
  131. NULL,
  132. 80,
  133. FormatPropertyInstance
  134. },
  135. //EAPOL_KEY_KEY
  136. { 0, 0,
  137. "Key",
  138. "EAPOL Key",
  139. PROP_TYPE_BYTE,
  140. PROP_QUAL_ARRAY,
  141. NULL,
  142. 80,
  143. FormatPropertyInstance
  144. },
  145. };
  146. WORD NUM_EAPOL_PROPERTIES = sizeof(EAPOL_Prop) / sizeof(PROPERTYINFO);
  147. // Define the entry points that we will pass back at dll entry time...
  148. ENTRYPOINTS EAPOLEntryPoints =
  149. {
  150. // EAPOL Entry Points
  151. EAPOL_Register,
  152. EAPOL_Deregister,
  153. EAPOL_RecognizeFrame,
  154. EAPOL_AttachProperties,
  155. EAPOL_FormatProperties
  156. };
  157. // Globals -------------------------------------------------------------------
  158. HPROTOCOL hEAPOL = NULL;
  159. HPROTOCOL hEAP = NULL;
  160. //============================================================================
  161. // Function: EAPOL_Register
  162. //
  163. // Description: Create our property database and handoff sets.
  164. //
  165. // Modification History
  166. //
  167. // timmoore 04/04/2000 Created //
  168. //============================================================================
  169. void BHAPI EAPOL_Register( HPROTOCOL hEAPOL)
  170. {
  171. WORD i;
  172. // tell the kernel to make reserve some space for our property table
  173. CreatePropertyDatabase( hEAPOL, NUM_EAPOL_PROPERTIES);
  174. // add our properties to the kernel's database
  175. for( i = 0; i < NUM_EAPOL_PROPERTIES; i++)
  176. {
  177. AddProperty( hEAPOL, &EAPOL_Prop[i]);
  178. }
  179. hEAP = GetProtocolFromName("EAP");
  180. }
  181. //============================================================================
  182. // Function: EAPOL_Deregister
  183. //
  184. // Description: Destroy our property database and handoff set
  185. //
  186. // Modification History
  187. //
  188. // timmoore 04/04/2000 Created //
  189. //============================================================================
  190. VOID WINAPI EAPOL_Deregister( HPROTOCOL hEAPOL)
  191. {
  192. // tell the kernel that it may now free our database
  193. DestroyPropertyDatabase( hEAPOL);
  194. }
  195. //============================================================================
  196. // Function: EAPOL_RecognizeFrame
  197. //
  198. // Description: Determine whether we exist in the frame at the spot
  199. // indicated. We also indicate who (if anyone) follows us
  200. // and how much of the frame we claim.
  201. //
  202. // Modification History
  203. //
  204. // timmoore 04/04/2000 Created //
  205. //============================================================================
  206. ULPBYTE BHAPI EAPOL_RecognizeFrame( HFRAME hFrame,
  207. ULPBYTE pMacFrame,
  208. ULPBYTE pEAPOLFrame,
  209. DWORD MacType,
  210. DWORD BytesLeft,
  211. HPROTOCOL hPrevProtocol,
  212. DWORD nPrevProtOffset,
  213. LPDWORD pProtocolStatus,
  214. LPHPROTOCOL phNextProtocol,
  215. PDWORD_PTR InstData)
  216. {
  217. ULPEAPHDR pEAPOLHeader = (ULPEAPHDR)pEAPOLFrame;
  218. if(pEAPOLHeader->bType == EAPOL_START || pEAPOLHeader->bType == EAPOL_LOGOFF
  219. || pEAPOLHeader->bType == EAPOL_KEY) {
  220. *pProtocolStatus = PROTOCOL_STATUS_CLAIMED;
  221. return NULL;
  222. }
  223. else {
  224. *phNextProtocol = hEAP;
  225. *pProtocolStatus = PROTOCOL_STATUS_NEXT_PROTOCOL;
  226. return pEAPOLFrame + 4;
  227. }
  228. }
  229. //============================================================================
  230. // Function: EAPOL_AttachProperties
  231. //
  232. // Description: Indicate where in the frame each of our properties live.
  233. //
  234. // Modification History
  235. //
  236. // timmoore 04/04/2000 Created //
  237. //============================================================================
  238. ULPBYTE BHAPI EAPOL_AttachProperties( HFRAME hFrame,
  239. ULPBYTE pMacFrame,
  240. ULPBYTE pEAPOLFrame,
  241. DWORD MacType,
  242. DWORD BytesLeft,
  243. HPROTOCOL hPrevProtocol,
  244. DWORD nPrevProtOffset,
  245. DWORD_PTR InstData)
  246. {
  247. ULPEAPHDR pEAPOLHeader = (ULPEAPHDR)pEAPOLFrame;
  248. // summary line
  249. AttachPropertyInstance( hFrame,
  250. EAPOL_Prop[EAPOL_SUMMARY].hProperty,
  251. (WORD)BytesLeft,
  252. (ULPBYTE)pEAPOLFrame,
  253. 0, 0, 0);
  254. // Version
  255. AttachPropertyInstance( hFrame,
  256. EAPOL_Prop[EAPOL_VERSION].hProperty,
  257. sizeof(BYTE),
  258. &(pEAPOLHeader->bVersion),
  259. 0, 1, 0);
  260. // EAPOL Type
  261. AttachPropertyInstance( hFrame,
  262. EAPOL_Prop[EAPOL_TYPE].hProperty,
  263. sizeof(BYTE),
  264. &(pEAPOLHeader->bType),
  265. 0, 1, 0);
  266. // Length
  267. AttachPropertyInstance( hFrame,
  268. EAPOL_Prop[EAPOL_LENGTH].hProperty,
  269. sizeof(WORD),
  270. &(pEAPOLHeader->wLength),
  271. 0, 1, 0);
  272. if(pEAPOLHeader->bType == EAPOL_KEY)
  273. {
  274. ULPEAPOLKEY pEAPOLKey = (ULPEAPOLKEY)&(pEAPOLHeader->pEAPPacket[0]);
  275. AttachPropertyInstance( hFrame,
  276. EAPOL_Prop[EAPOL_KEY_SIGNTYPE].hProperty,
  277. sizeof(BYTE),
  278. &(pEAPOLKey->bSignType),
  279. 0, 1, 0);
  280. AttachPropertyInstance( hFrame,
  281. EAPOL_Prop[EAPOL_KEY_KEYTYPE].hProperty,
  282. sizeof(BYTE),
  283. &(pEAPOLKey->bKeyType),
  284. 0, 1, 0);
  285. AttachPropertyInstance( hFrame,
  286. EAPOL_Prop[EAPOL_KEY_KEYLENGTH].hProperty,
  287. sizeof(WORD),
  288. &(pEAPOLKey->wKeyLength),
  289. 0, 1, 0);
  290. AttachPropertyInstance( hFrame,
  291. EAPOL_Prop[EAPOL_KEY_KEYREPLAY].hProperty,
  292. 16,
  293. &(pEAPOLKey->bKeyReplay),
  294. 0, 1, 0);
  295. AttachPropertyInstance( hFrame,
  296. EAPOL_Prop[EAPOL_KEY_KEYIV].hProperty,
  297. 16,
  298. &(pEAPOLKey->bKeyIV),
  299. 0, 1, 0);
  300. AttachPropertyInstance( hFrame,
  301. EAPOL_Prop[EAPOL_KEY_KEYINDEX].hProperty,
  302. sizeof(BYTE),
  303. &(pEAPOLKey->bKeyIndex),
  304. 0, 1, 0);
  305. AttachPropertyInstance( hFrame,
  306. EAPOL_Prop[EAPOL_KEY_KEYSIGN].hProperty,
  307. 16,
  308. &(pEAPOLKey->bKeySign),
  309. 0, 1, 0);
  310. AttachPropertyInstance( hFrame,
  311. EAPOL_Prop[EAPOL_KEY_KEY].hProperty,
  312. XCHG(pEAPOLKey->wKeyLength),
  313. &(pEAPOLKey->bKey),
  314. 0, 1, 0);
  315. }
  316. return NULL;
  317. }
  318. //============================================================================
  319. // Function: EAPOL_FormatProperties
  320. //
  321. // Description: Format the given properties on the given frame.
  322. //
  323. // Modification History
  324. //
  325. // timmoore 04/04/2000 Created //
  326. //============================================================================
  327. DWORD BHAPI EAPOL_FormatProperties( HFRAME hFrame,
  328. ULPBYTE pMacFrame,
  329. ULPBYTE pEAPOLFrame,
  330. DWORD nPropertyInsts,
  331. LPPROPERTYINST p)
  332. {
  333. // loop through the property instances
  334. while( nPropertyInsts-- > 0)
  335. {
  336. // and call the formatter for each
  337. ( (FORMAT)(p->lpPropertyInfo->InstanceData) )( p);
  338. p++;
  339. }
  340. return NMERR_SUCCESS;
  341. }
  342. //============================================================================
  343. // Function: EAPOL_FormatSummary
  344. //
  345. // Description: The custom formatter for the summary property
  346. //
  347. // Modification History
  348. //
  349. // timmoore 04/04/2000 Created //
  350. //============================================================================
  351. VOID WINAPIV EAPOL_FormatSummary( LPPROPERTYINST pPropertyInst)
  352. {
  353. ULPBYTE pReturnedString = pPropertyInst->szPropertyText;
  354. ULPEAPHDR pEAPOLHeader = (ULPEAPHDR)(pPropertyInst->lpData);
  355. char* szTempString;
  356. // fetch the message type
  357. szTempString = LookupByteSetString( &EAPOLCodeSET, pEAPOLHeader->bType );
  358. if( szTempString == NULL )
  359. {
  360. wsprintf( pReturnedString, "Packet Type: Unknown");
  361. }
  362. else
  363. {
  364. pReturnedString += wsprintf( pReturnedString, "Packet: %s", szTempString );
  365. }
  366. }