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.

369 lines
8.9 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: valproxy.cpp
  4. //
  5. // Synopsis: Implementation of CValProxy class methods
  6. //
  7. //
  8. // History: 9/23/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-2001 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "valproxy.h"
  16. #include "radpkt.h"
  17. //++--------------------------------------------------------------
  18. //
  19. // Function: CValProxy
  20. //
  21. // Synopsis: This is the constructor of the CValProxy
  22. // class
  23. //
  24. // Arguments: NONE
  25. //
  26. // Returns: NONE
  27. //
  28. //
  29. // History: MKarki Created 9/28/97
  30. //
  31. //----------------------------------------------------------------
  32. CValProxy::CValProxy(
  33. VOID
  34. )
  35. : m_pCProxyState (NULL),
  36. m_pCSendToPipe (NULL)
  37. {
  38. } // end of CValProxy constructor
  39. //++--------------------------------------------------------------
  40. //
  41. // Function: ~CValProxy
  42. //
  43. // Synopsis: This is the destructor of the CValProxy
  44. // class
  45. //
  46. // Arguments: NONE
  47. //
  48. // Returns: NONE
  49. //
  50. //
  51. // History: MKarki Created 9/28/97
  52. //
  53. //----------------------------------------------------------------
  54. CValProxy::~CValProxy(
  55. VOID
  56. )
  57. {
  58. } // end of CValProxy destructor
  59. //++--------------------------------------------------------------
  60. //
  61. // Function: Init
  62. //
  63. // Synopsis: This is the CValProxy public method used
  64. // in initialization of the class object
  65. //
  66. // Arguments: NONE
  67. //
  68. // Returns: status
  69. //
  70. //
  71. // History: MKarki Created 9/28/97
  72. //
  73. //----------------------------------------------------------------
  74. BOOL
  75. CValProxy::Init (
  76. CValAttributes *pCValAttributes,
  77. CPreProcessor *pCPreProcessor,
  78. CClients *pCClients,
  79. CHashMD5 *pCHashMD5,
  80. CProxyState *pCProxyState,
  81. CSendToPipe *pCSendToPipe,
  82. CReportEvent *pCReportEvent
  83. )
  84. {
  85. BOOL bRetVal = FALSE;
  86. BOOL bStatus = FALSE;
  87. __try
  88. {
  89. //
  90. // call the base classes init method
  91. //
  92. bStatus = CValidator::Init (
  93. pCValAttributes,
  94. pCPreProcessor,
  95. pCClients,
  96. pCHashMD5,
  97. pCReportEvent
  98. );
  99. if (FALSE == bStatus) { __leave; }
  100. //
  101. // set the proxy state
  102. //
  103. m_pCProxyState = pCProxyState;
  104. m_pCSendToPipe = pCSendToPipe;
  105. //
  106. // initalization complete
  107. //
  108. bRetVal = TRUE;
  109. }
  110. __finally
  111. {
  112. //
  113. // nothing here for now
  114. //
  115. }
  116. return (bRetVal);
  117. } // end of CValProxy::Init method
  118. //++--------------------------------------------------------------
  119. //
  120. // Function: ValidateInPacket
  121. //
  122. // Synopsis: This is CValProxy class public method
  123. // that validates inbound Access Request packet
  124. //
  125. // Arguments: [IN] - CPacketRadius*
  126. //
  127. // Returns: HRESULT - status
  128. //
  129. //
  130. // History: MKarki Created 9/28/97
  131. //
  132. // Calleed By: CPreValidator class method
  133. //
  134. //----------------------------------------------------------------
  135. HRESULT
  136. CValProxy::ValidateInPacket(
  137. CPacketRadius * pCPacketRadius
  138. )
  139. {
  140. BOOL bRetVal = FALSE;
  141. HRESULT hr = S_OK;
  142. __try
  143. {
  144. //
  145. // validate the attributes
  146. //
  147. hr = m_pCValAttributes->Validate (pCPacketRadius);
  148. if (FAILED(hr)) { __leave; }
  149. //
  150. // get the proxy state value out
  151. //
  152. BYTE ReqAuthenticator[AUTHENTICATOR_SIZE];
  153. BOOL bStatus = m_pCProxyState->ValidateProxyState (
  154. pCPacketRadius,
  155. ReqAuthenticator
  156. );
  157. if (FALSE == bStatus) { __leave; }
  158. //
  159. // authenticate packet now
  160. //
  161. hr = AuthenticatePacket (
  162. pCPacketRadius,
  163. ReqAuthenticator
  164. );
  165. if (FAILED(hr)) { __leave; }
  166. //
  167. // now give the packet for processing
  168. //
  169. hr = m_pCPreProcessor->StartInProcessing (pCPacketRadius);
  170. if (FAILED(hr)) { __leave; }
  171. //
  172. // successfully processed packet
  173. //
  174. bRetVal = TRUE;
  175. }
  176. __finally
  177. {
  178. //
  179. // nothing here for now
  180. //
  181. }
  182. if (bRetVal)
  183. {
  184. return S_OK;
  185. }
  186. else
  187. {
  188. if (FAILED(hr))
  189. {
  190. return hr;
  191. }
  192. else
  193. {
  194. return E_FAIL;
  195. }
  196. }
  197. } // end of CValProxy::ValidateInPacket method
  198. //++--------------------------------------------------------------
  199. //
  200. // Function: ValidateOutPacket
  201. //
  202. // Synopsis: This is CValProxy class public method
  203. // that validates outbound Access Request packet
  204. //
  205. // Arguments: NONE
  206. //
  207. // Returns: HRESULT - status
  208. //
  209. //
  210. // History: MKarki Created 9/28/97
  211. //
  212. // Calleed By: CPreValidator class method
  213. //
  214. //----------------------------------------------------------------
  215. HRESULT
  216. CValProxy::ValidateOutPacket(
  217. CPacketRadius * pCPacketRadius
  218. )
  219. {
  220. return S_OK;
  221. } // end of CValProxy::ValidateOutPacket method
  222. //++--------------------------------------------------------------
  223. //
  224. // Function: AuthenticatePacket
  225. //
  226. // Synopsis: This is CValProxy class private method
  227. // that authenticates the packet, by generating a
  228. // response authenticator with the packet and then
  229. // comparing it with the request authenticator
  230. //
  231. // Arguments: [in] - CPacketRadius*
  232. //
  233. // Returns: BOOL - status
  234. //
  235. //
  236. // History: MKarki Created 9/28/97
  237. //
  238. // Called By: CValProxy::ValidateInPacket method
  239. //
  240. //----------------------------------------------------------------
  241. HRESULT
  242. CValProxy::AuthenticatePacket (
  243. CPacketRadius *pCPacketRadius,
  244. PBYTE pbyAuthenticator
  245. )
  246. {
  247. BOOL bRetVal = FALSE;
  248. BOOL bStatus = FALSE;
  249. PRADIUSPACKET pPacketRadius = NULL;
  250. DWORD dwPacketHeaderSize = 0;
  251. DWORD dwAttributesLength = 0;
  252. BYTE HashResult[AUTHENTICATOR_SIZE];
  253. BYTE bySecret[MAX_SECRET_SIZE];
  254. IIasClient *pIIasClient = NULL;
  255. DWORD dwSecretSize = MAX_SECRET_SIZE;
  256. HRESULT hr = S_OK;
  257. __try
  258. {
  259. //
  260. // check that the arguments passed in are correct
  261. //
  262. if ((NULL == pCPacketRadius) || (NULL == pbyAuthenticator))
  263. __leave;
  264. //
  265. // get a pointer to the raw packet
  266. //
  267. pPacketRadius = reinterpret_cast <PRADIUSPACKET>
  268. (pCPacketRadius->GetInPacket ());
  269. //
  270. // get the size of the packet without the attributes and
  271. // request authenticator
  272. //
  273. dwPacketHeaderSize = sizeof (RADIUSPACKET)
  274. - sizeof (BYTE)
  275. - AUTHENTICATOR_SIZE;
  276. //
  277. // get the total attributes length now
  278. //
  279. dwAttributesLength = ntohs (pPacketRadius->wLength)
  280. - (dwPacketHeaderSize + AUTHENTICATOR_SIZE);
  281. //
  282. // get the CClients object
  283. //
  284. hr = pCPacketRadius->GetClient (&pIIasClient);
  285. if (FAILED (hr)) { __leave; }
  286. //
  287. // get the shared secret from the client object
  288. //
  289. hr = pIIasClient->GetSecret (bySecret, &dwSecretSize);
  290. if (FAILED (hr)) { __leave; }
  291. //
  292. // do the hashing here
  293. //
  294. m_pCHashMD5->HashIt (
  295. reinterpret_cast <PBYTE> (&HashResult),
  296. NULL,
  297. 0,
  298. reinterpret_cast <PBYTE> (pPacketRadius),
  299. dwPacketHeaderSize,
  300. pbyAuthenticator,
  301. AUTHENTICATOR_SIZE,
  302. pPacketRadius->AttributeStart,
  303. dwAttributesLength,
  304. reinterpret_cast <PBYTE> (bySecret),
  305. dwSecretSize,
  306. 0,
  307. 0
  308. );
  309. if (memcmp (
  310. HashResult,
  311. pPacketRadius->Authenticator,
  312. AUTHENTICATOR_SIZE
  313. )
  314. != 0
  315. )
  316. __leave;
  317. //
  318. // we have successfully authenticated this packet
  319. //
  320. bRetVal = TRUE;
  321. }
  322. __finally
  323. {
  324. if (NULL != pIIasClient)
  325. {
  326. pIIasClient->Release ();
  327. }
  328. }
  329. return S_OK;
  330. } // end of CValProxy::AuthenticatePacket method