Leaked source code of windows server 2003
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.

486 lines
10 KiB

  1. #ifndef _SITECONFIG_HXX_
  2. #define _SITECONFIG_HXX_
  3. /*++
  4. Copyright (c) 1998 Microsoft Corporation
  5. Module Name :
  6. siteconfig.hxx
  7. Abstract:
  8. SSL configuration for a given site
  9. Author:
  10. Bilal Alam (BAlam) 29-March-2000
  11. Environment:
  12. Win32 - User Mode
  13. Project:
  14. Stream Filter Worker Process
  15. --*/
  16. class ENDPOINT_CONFIG_HASH;
  17. class SERVER_CERT;
  18. typedef ULONGLONG ENDPOINT_KEY;
  19. #define ENDPOINT_CONFIG_SIGNATURE (DWORD)'GFCS'
  20. #define ENDPOINT_CONFIG_SIGNATURE_FREE (DWORD)'gfcs'
  21. class ENDPOINT_CONFIG
  22. {
  23. public:
  24. const ENDPOINT_KEY*
  25. QueryEndpointKey(
  26. VOID
  27. ) const
  28. {
  29. return &_EndpointKey;
  30. }
  31. SERVER_CERT *
  32. QueryServerCert(
  33. VOID
  34. ) const
  35. {
  36. return _pServerCert;
  37. }
  38. IIS_CTL *
  39. QueryIisCtl(
  40. VOID
  41. ) const
  42. {
  43. return _pIisCtl;
  44. }
  45. BOOL
  46. CheckSignature(
  47. VOID
  48. ) const
  49. {
  50. return _dwSignature == ENDPOINT_CONFIG_SIGNATURE;
  51. }
  52. VOID
  53. ReferenceEndpointConfig(
  54. VOID
  55. )
  56. {
  57. InterlockedIncrement( &_cRefs );
  58. }
  59. VOID
  60. DereferenceEndpointConfig(
  61. VOID
  62. )
  63. {
  64. if ( InterlockedDecrement( &_cRefs ) == 0 )
  65. {
  66. delete this;
  67. }
  68. }
  69. BOOL
  70. QuerySslConfigured(
  71. VOID
  72. )
  73. {
  74. return _SiteCreds.QueryIsAvailable();
  75. }
  76. CredHandle *
  77. QueryCredentials(
  78. VOID
  79. )
  80. {
  81. return _SiteCreds.QueryCredentials();
  82. }
  83. BOOL
  84. QueryUseDSMapper(
  85. VOID
  86. )
  87. {
  88. if ( _pEndpointConfigData == NULL )
  89. {
  90. return FALSE;
  91. }
  92. else
  93. {
  94. return !!(_pEndpointConfigData->ParamDesc.DefaultFlags &
  95. HTTP_SERVICE_CONFIG_SSL_FLAG_USE_DS_MAPPER);
  96. }
  97. }
  98. BOOL
  99. QueryNegotiateClientCert(
  100. VOID
  101. )
  102. {
  103. //
  104. // _fRequireClientCert is used for SSL optimization
  105. // If RequireClientCert is set on the root level of the site
  106. // then IIS will ask for mutual authentication right away
  107. // That way the expensive renegotiation when the whole
  108. // ssl key exchange must be repeated is eliminated
  109. //
  110. if ( _pEndpointConfigData == NULL )
  111. {
  112. return FALSE;
  113. }
  114. else
  115. {
  116. return !!(_pEndpointConfigData->ParamDesc.DefaultFlags &
  117. HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT);
  118. }
  119. }
  120. BOOL
  121. QueryNoRawFilter(
  122. VOID
  123. )
  124. {
  125. if ( _pEndpointConfigData == NULL )
  126. {
  127. return FALSE;
  128. }
  129. else
  130. {
  131. return !!(_pEndpointConfigData->ParamDesc.DefaultFlags &
  132. HTTP_SERVICE_CONFIG_SSL_FLAG_NO_RAW_FILTER);
  133. }
  134. }
  135. BOOL
  136. IsCtlRequired(
  137. VOID
  138. )
  139. {
  140. if ( _pEndpointConfigData == NULL )
  141. {
  142. return FALSE;
  143. }
  144. else
  145. {
  146. return
  147. _pEndpointConfigData->ParamDesc.pDefaultSslCtlIdentifier != NULL &&
  148. _pEndpointConfigData->ParamDesc.pDefaultSslCtlIdentifier[0] != L'\0';
  149. }
  150. }
  151. DWORD
  152. QueryCertCheckMode(
  153. VOID
  154. )
  155. {
  156. if ( _pEndpointConfigData == NULL )
  157. {
  158. return 0;
  159. }
  160. else
  161. {
  162. return _pEndpointConfigData->ParamDesc.DefaultCertCheckMode;
  163. }
  164. }
  165. DWORD
  166. QueryRevocationFreshnessTime(
  167. VOID
  168. )
  169. {
  170. if ( _pEndpointConfigData == NULL )
  171. {
  172. return 0;
  173. }
  174. else
  175. {
  176. return _pEndpointConfigData->ParamDesc.DefaultRevocationFreshnessTime;
  177. }
  178. }
  179. DWORD
  180. QueryRevocationUrlRetrievalTimeout(
  181. VOID
  182. )
  183. {
  184. if ( _pEndpointConfigData == NULL )
  185. {
  186. return 0;
  187. }
  188. else
  189. {
  190. return _pEndpointConfigData->ParamDesc.DefaultRevocationUrlRetrievalTimeout;
  191. }
  192. }
  193. HRESULT
  194. AcquireCredentials(
  195. VOID
  196. );
  197. static
  198. HRESULT
  199. Initialize(
  200. VOID
  201. );
  202. static
  203. VOID
  204. Terminate(
  205. VOID
  206. );
  207. static
  208. HRESULT
  209. GetEndpointConfig(
  210. CONNECTION_INFO * pConnectionInfo,
  211. ENDPOINT_CONFIG ** ppEndpointConfig,
  212. BOOL fCreateEmptyIfNotFound = FALSE
  213. );
  214. static
  215. ENDPOINT_KEY
  216. GenerateEndpointKey(
  217. DWORD LocalAddress,
  218. USHORT LocalPort
  219. )
  220. {
  221. LARGE_INTEGER liKey;
  222. // CODEWORK: this will break for IPv6
  223. // Currently only wildcard IPs are supported for IPv6
  224. liKey.HighPart = LocalAddress;
  225. liKey.LowPart = LocalPort;
  226. return liKey.QuadPart;
  227. }
  228. static
  229. HRESULT
  230. FlushByServerCert(
  231. SERVER_CERT * pServerCert
  232. );
  233. static
  234. HRESULT
  235. FlushByIisCtl(
  236. IIS_CTL * pIisCtl
  237. );
  238. static
  239. HRESULT
  240. FlushByEndpoint(
  241. DWORD LocalAddress,
  242. USHORT LocalPort
  243. );
  244. static
  245. VOID
  246. Cleanup(
  247. VOID
  248. );
  249. static
  250. VOID
  251. WINAPI
  252. ConfigStoreChangeCallback(
  253. PVOID pParam,
  254. BOOL fWaitFired
  255. );
  256. private:
  257. // Constructor is private
  258. // GetEndpointConfig() is to be called to get reference to the object
  259. //
  260. ENDPOINT_CONFIG(
  261. DWORD LocalAddress,
  262. USHORT LocalPort,
  263. SERVER_CERT * pServerCert,
  264. IIS_CTL * pIisCtl,
  265. PHTTP_SERVICE_CONFIG_SSL_SET pEndpointConfigData
  266. )
  267. {
  268. _cRefs = 1;
  269. _dwSignature = ENDPOINT_CONFIG_SIGNATURE;
  270. _LocalAddress = LocalAddress;
  271. _LocalPort = LocalPort;
  272. _EndpointKey = GenerateEndpointKey( LocalAddress, LocalPort );
  273. _pServerCert = pServerCert;
  274. _pEndpointConfigData = pEndpointConfigData; // takes ownership of the memory
  275. _pIisCtl = pIisCtl;
  276. }
  277. // Destructor is private
  278. // DereferenceEndpointConfig() is to be called for cleanup
  279. //
  280. virtual ~ENDPOINT_CONFIG();
  281. static
  282. LK_PREDICATE
  283. ServerCertPredicate(
  284. ENDPOINT_CONFIG * pEndpointConfig,
  285. void * pvState
  286. );
  287. static
  288. LK_PREDICATE
  289. IisCtlPredicate(
  290. ENDPOINT_CONFIG * pEndpointConfig,
  291. void * pvState
  292. );
  293. static
  294. LK_PREDICATE
  295. SiteIdPredicate(
  296. ENDPOINT_CONFIG * pEndpointConfig,
  297. void * pvState
  298. );
  299. static
  300. LK_PREDICATE
  301. EndpointPredicate(
  302. ENDPOINT_CONFIG * pEndpointConfig,
  303. void * pvState
  304. );
  305. static
  306. HRESULT
  307. GetEndpointConfigData(
  308. IN DWORD LocalAddress,
  309. IN USHORT LocalPort,
  310. OUT PHTTP_SERVICE_CONFIG_SSL_SET * ppEndpointConfigData,
  311. OUT BOOL * pfWildcardMatch
  312. );
  313. private:
  314. DWORD _dwSignature;
  315. LONG _cRefs;
  316. // key representing IP:Port
  317. ENDPOINT_KEY _EndpointKey;
  318. //
  319. // we don't really need to store _LocalAddress and _LocalPort
  320. // but for the debugging or logging it may be convenient
  321. // to have the info available
  322. //
  323. DWORD _LocalAddress;
  324. USHORT _LocalPort;
  325. //
  326. // SSL specific objects
  327. //
  328. SERVER_CERT * _pServerCert;
  329. IIS_CTL * _pIisCtl;
  330. SITE_CREDENTIALS _SiteCreds;
  331. //
  332. // SSL config and Enable Raw Filter flag
  333. //
  334. PHTTP_SERVICE_CONFIG_SSL_SET _pEndpointConfigData;
  335. //
  336. // Hash table caching endpoint configuration
  337. //
  338. static ENDPOINT_CONFIG_HASH * sm_pEndpointConfigHash;
  339. //
  340. // Objects needed to handle persistent endpoint config store
  341. // change notification
  342. //
  343. static HANDLE sm_hHttpApiConfigChangeEvent;
  344. static HKEY sm_hHttpApiConfigKey;
  345. static HANDLE sm_hWaitHandle;
  346. enum INIT_STATE {
  347. INIT_NONE,
  348. INIT_HTTPAPI,
  349. INIT_HASH,
  350. INIT_CHANGE_NOTIF
  351. };
  352. // Initialization state
  353. static INIT_STATE sm_InitState;
  354. };
  355. class ENDPOINT_CONFIG_HASH
  356. : public CTypedHashTable<
  357. ENDPOINT_CONFIG_HASH,
  358. ENDPOINT_CONFIG,
  359. const ENDPOINT_KEY *
  360. >
  361. {
  362. public:
  363. ENDPOINT_CONFIG_HASH()
  364. : CTypedHashTable< ENDPOINT_CONFIG_HASH,
  365. ENDPOINT_CONFIG,
  366. const ENDPOINT_KEY * > ( "ENDPOINT_CONFIG_HASH" )
  367. {
  368. }
  369. static
  370. const ENDPOINT_KEY *
  371. ExtractKey(
  372. const ENDPOINT_CONFIG * pEndpointConfig
  373. )
  374. {
  375. return pEndpointConfig->QueryEndpointKey();
  376. }
  377. static
  378. DWORD
  379. CalcKeyHash(
  380. const ENDPOINT_KEY * pEndpointKey
  381. )
  382. {
  383. return HashBlob( pEndpointKey,
  384. sizeof( ENDPOINT_KEY ) );
  385. }
  386. static
  387. bool
  388. EqualKeys(
  389. const ENDPOINT_KEY * pEndpointKey1,
  390. const ENDPOINT_KEY * pEndpointKey2
  391. )
  392. {
  393. return *pEndpointKey1 == *pEndpointKey2;
  394. }
  395. static
  396. void
  397. AddRefRecord(
  398. ENDPOINT_CONFIG * pEndpointConfig,
  399. int nIncr
  400. )
  401. {
  402. if ( nIncr == +1 )
  403. {
  404. pEndpointConfig->ReferenceEndpointConfig();
  405. }
  406. else if ( nIncr == -1 )
  407. {
  408. pEndpointConfig->DereferenceEndpointConfig();
  409. }
  410. }
  411. private:
  412. //
  413. // Not implemented methods
  414. // Declarations present to prevent compiler
  415. // to generate default ones.
  416. //
  417. ENDPOINT_CONFIG_HASH( const ENDPOINT_CONFIG_HASH& );
  418. ENDPOINT_CONFIG_HASH& operator=( const ENDPOINT_CONFIG_HASH& );
  419. };
  420. #endif