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.

765 lines
33 KiB

  1. /****************************************************************************/
  2. /* sl.h */
  3. /* */
  4. /* Security Layer class */
  5. /* */
  6. /* Copyright (C) 1997-1999 Microsoft Corporation */
  7. /****************************************************************************/
  8. #ifndef _H_SL
  9. #define _H_SL
  10. extern "C" {
  11. #include <adcgdata.h>
  12. #include <at120ex.h>
  13. }
  14. #include "cd.h"
  15. #include "nl.h"
  16. #include "cchan.h"
  17. #include "objs.h"
  18. #include "capienc.h"
  19. #define SL_DBG_INIT_CALLED 0x00001
  20. #define SL_DBG_INIT_DONE 0x00002
  21. #define SL_DBG_TERM_CALLED 0x00004
  22. #define SL_DBG_TERM_DONE 0x00008
  23. #define SL_DBG_CONNECT_CALLED 0x00010
  24. #define SL_DBG_CONNECT_DONE 0x00020
  25. #define SL_DBG_DISCONNECT_CALLED 0x00040
  26. #define SL_DBG_DISCONNECT_DONE1 0x00080
  27. #define SL_DBG_DISCONNECT_DONE2 0x00100
  28. #define SL_DBG_ONINIT_CALLED 0x00200
  29. #define SL_DBG_ONINIT_DONE1 0x00400
  30. #define SL_DBG_ONINIT_DONE2 0x00800
  31. #define SL_DBG_ONDISC_CALLED 0x01000
  32. #define SL_DBG_ONDISC_DONE1 0x02000
  33. #define SL_DBG_ONDISC_DONE2 0x04000
  34. #define SL_DBG_ONTERM_CALLED 0x08000
  35. #define SL_DBG_ONTERM_DONE1 0x10000
  36. #define SL_DBG_ONTERM_DONE2 0x20000
  37. #define SL_DBG_TERM_DONE1 0x40000
  38. extern DWORD g_dwSLDbgStatus;
  39. #define SL_DBG_SETINFO(x) g_dwSLDbgStatus |= x;
  40. /****************************************************************************/
  41. /* Protocol type(s) */
  42. /****************************************************************************/
  43. #define SL_PROTOCOL_T128 NL_PROTOCOL_T128
  44. /****************************************************************************/
  45. /* Network transport types. */
  46. /****************************************************************************/
  47. #define SL_TRANSPORT_TCP NL_TRANSPORT_TCP
  48. #ifdef DC_LOOPBACK
  49. /****************************************************************************/
  50. /* Loopback testing constants */
  51. /****************************************************************************/
  52. /****************************************************************************/
  53. /* Test string: Put two pad bytes at the front, since MG will overwrite */
  54. /* these with a length field on the server. Check only subsequent parts of */
  55. /* the string. */
  56. /* Ensure that the whole thing is a multiple of 4 bytes (including the null */
  57. /* terminator) to avoid padding inconsistencies. */
  58. /****************************************************************************/
  59. #define SL_LB_RETURN_STRING \
  60. {'L','o','o','p','b','a','c','k',' ','t','e','s','t',' '}
  61. #define SL_LB_RETURN_STRING_SIZE 14
  62. #define SL_LB_STR_CORRUPT_LENGTH 2
  63. #define SL_LB_STRING_SIZE \
  64. (SL_LB_STR_CORRUPT_LENGTH + SL_LB_RETURN_STRING_SIZE)
  65. #define SL_LB_HDR_SIZE sizeof(SL_LB_PACKET)
  66. #define SL_LB_SIZE_INC 1
  67. #define SL_LB_MAX_PACKETS 6000
  68. #define SL_LB_MAX_SIZE 4000
  69. #define SL_LB_MIN_SIZE (SL_LB_HDR_SIZE + SL_LB_SIZE_INC)
  70. #endif /* DC_LOOPBACK */
  71. /****************************************************************************/
  72. /* Structure: SL_BUFHND */
  73. /* */
  74. /* Description: Buffer Handle */
  75. /****************************************************************************/
  76. typedef NL_BUFHND SL_BUFHND;
  77. typedef SL_BUFHND DCPTR PSL_BUFHND;
  78. /****************************************************************************/
  79. /* Structure: SL_CALLBACKS */
  80. /* */
  81. /* Description: list of callbacks passed to SL_Init(). */
  82. /****************************************************************************/
  83. typedef NL_CALLBACKS SL_CALLBACKS;
  84. typedef SL_CALLBACKS DCPTR PSL_CALLBACKS;
  85. //
  86. // For internal functions
  87. //
  88. /****************************************************************************/
  89. /* Constants */
  90. /****************************************************************************/
  91. /****************************************************************************/
  92. /* Multiplier to turn a default string format byte count into a Unicode */
  93. /* string byte count. */
  94. /* For 32-bit, the default is Unicode, so the multiplier is a NOP, ie 1. */
  95. /* For 16-bit, the default is ANSI, so multiply by 2 to give Unicode */
  96. /* (assumes security package names always use single byte chars). */
  97. /****************************************************************************/
  98. #ifdef UNICODE
  99. #define SL_DEFAULT_TO_UNICODE_FACTOR 1
  100. #else
  101. #define SL_DEFAULT_TO_UNICODE_FACTOR 2
  102. #endif
  103. /****************************************************************************/
  104. /* States */
  105. /****************************************************************************/
  106. #define SL_STATE_TERMINATED 0
  107. #define SL_STATE_INITIALIZING 1
  108. #define SL_STATE_INITIALIZED 2
  109. #define SL_STATE_NL_CONNECTING 3
  110. #define SL_STATE_SL_CONNECTING 4
  111. #define SL_STATE_LICENSING 5
  112. #define SL_STATE_CONNECTED 6
  113. #define SL_STATE_DISCONNECTING 7
  114. #define SL_STATE_TERMINATING 8
  115. #define SL_NUMSTATES 9
  116. /****************************************************************************/
  117. /* Events */
  118. /****************************************************************************/
  119. #define SL_EVENT_SL_INIT 0
  120. #define SL_EVENT_SL_TERM 1
  121. #define SL_EVENT_SL_CONNECT 2
  122. #define SL_EVENT_SL_DISCONNECT 3
  123. #define SL_EVENT_SL_SENDPACKET 4
  124. #define SL_EVENT_SL_GETBUFFER 5
  125. #define SL_EVENT_ON_INITIALIZED 6
  126. #define SL_EVENT_ON_TERMINATING 7
  127. #define SL_EVENT_ON_CONNECTED 8
  128. #define SL_EVENT_ON_DISCONNECTED 9
  129. #define SL_EVENT_ON_RECEIVED_SEC_PACKET 10
  130. #define SL_EVENT_ON_RECEIVED_LIC_PACKET 11
  131. #define SL_EVENT_ON_RECEIVED_DATA_PACKET 12
  132. #define SL_EVENT_ON_BUFFERAVAILABLE 13
  133. #define SL_NUMEVENTS 14
  134. /****************************************************************************/
  135. /* Values in the state table */
  136. /****************************************************************************/
  137. #define SL_TABLE_OK 0
  138. #define SL_TABLE_WARN 1
  139. #define SL_TABLE_ERROR 2
  140. /****************************************************************************/
  141. /* Macros */
  142. /****************************************************************************/
  143. /****************************************************************************/
  144. /* SL_CHECK_STATE - check SL is in the right state for an event. */
  145. /****************************************************************************/
  146. #define SL_CHECK_STATE(event) \
  147. { \
  148. TRC_DBG((TB, _T("Test event %s in state %s"), \
  149. slEvent[event], slState[_SL.state])); \
  150. if (slStateTable[event][_SL.state] != SL_TABLE_OK) \
  151. { \
  152. if (slStateTable[event][_SL.state] == SL_TABLE_WARN) \
  153. { \
  154. TRC_ALT((TB, _T("Unusual event %s in state %s"), \
  155. slEvent[event], slState[_SL.state])); \
  156. } \
  157. else \
  158. { \
  159. TRC_ABORT((TB, _T("Invalid event %s in state %s"), \
  160. slEvent[event], slState[_SL.state])); \
  161. } \
  162. DC_QUIT; \
  163. } \
  164. }
  165. /****************************************************************************/
  166. /* SL_SET_STATE - set the SL state */
  167. /****************************************************************************/
  168. #define SL_SET_STATE(newstate) \
  169. { \
  170. TRC_NRM((TB, _T("Set state from %s to %s"), \
  171. slState[_SL.state], slState[newstate])); \
  172. _SL.state = newstate; \
  173. }
  174. #ifdef DC_LOOPBACK
  175. /****************************************************************************/
  176. /* Loopback testing structures and functions */
  177. /****************************************************************************/
  178. /**STRUCT+*******************************************************************/
  179. /* Structure: SL_LB_PACKET */
  180. /* */
  181. /* Description: template for building up the packet to be sent */
  182. /****************************************************************************/
  183. typedef struct tagSL_LB_PACKET
  184. {
  185. DCUINT8 testString[SL_LB_STRING_SIZE]; /* multiple of 4 bytes */
  186. DCUINT32 sequenceNumber; /* Chosen to ensure data begins on word */
  187. /* boundary */
  188. } SL_LB_PACKET, DCPTR PSL_LB_PACKET;
  189. /**STRUCT-*******************************************************************/
  190. /**STRUCT+*******************************************************************/
  191. /* Structure: SL_LB_Q_ELEMENT */
  192. /* */
  193. /* Description: Elements in sent and received queues of loopback packets */
  194. /****************************************************************************/
  195. typedef struct tagSL_LB_Q_ELEMENT SL_LB_Q_ELEMENT, DCPTR PSL_LB_Q_ELEMENT;
  196. struct tagSL_LB_Q_ELEMENT
  197. {
  198. PSL_LB_PACKET pCurrent;
  199. SL_LB_Q_ELEMENT *pNext;
  200. };
  201. /**STRUCT-*******************************************************************/
  202. #endif //DC_LOOPBACK
  203. //
  204. // Data
  205. //
  206. /****************************************************************************/
  207. /* Structure: SL_GLOBAL_DATA */
  208. /* */
  209. /* Description: Security Layer global data */
  210. /****************************************************************************/
  211. typedef struct tagSL_GLOBAL_DATA
  212. {
  213. /************************************************************************/
  214. /* List of callbacks to the Core */
  215. /************************************************************************/
  216. SL_CALLBACKS callbacks;
  217. /************************************************************************/
  218. /* Flags and State information */
  219. /************************************************************************/
  220. DCUINT state;
  221. /************************************************************************/
  222. /* Encryption flags and data. */
  223. /************************************************************************/
  224. DCBOOL encrypting;
  225. DCBOOL encryptionEnabled;
  226. DCBOOL decryptFailed;
  227. DCUINT32 encryptionMethodsSupported;
  228. DCUINT32 encryptionMethodSelected;
  229. DCUINT32 encryptionLevel;
  230. RANDOM_KEYS_PAIR keyPair;
  231. DCUINT32 keyLength;
  232. DCUINT32 encryptCount; // reset every 4K packets
  233. DCUINT32 totalEncryptCount; // cumulative count
  234. DCUINT8 startEncryptKey[MAX_SESSION_KEY_SIZE];
  235. DCUINT8 currentEncryptKey[MAX_SESSION_KEY_SIZE];
  236. struct RC4_KEYSTRUCT rc4EncryptKey;
  237. DCUINT32 decryptCount; // reset every 4K packets
  238. DCUINT32 totalDecryptCount; // cumulative count
  239. DCUINT8 startDecryptKey[MAX_SESSION_KEY_SIZE];
  240. DCUINT8 currentDecryptKey[MAX_SESSION_KEY_SIZE];
  241. struct RC4_KEYSTRUCT rc4DecryptKey;
  242. DCUINT8 macSaltKey[MAX_SESSION_KEY_SIZE];
  243. /************************************************************************/
  244. /* Server certificate and public key data */
  245. /************************************************************************/
  246. PDCUINT8 pbCertificate;
  247. DCUINT cbCertificate;
  248. PHydra_Server_Cert pServerCert;
  249. PDCUINT8 pbServerPubKey;
  250. DCUINT32 cbServerPubKey;
  251. #ifdef USE_LICENSE
  252. /************************************************************************/
  253. /* License Manager handle */
  254. /************************************************************************/
  255. HANDLE hLicenseHandle;
  256. #endif //USE_LICENSE
  257. /************************************************************************/
  258. /* ID of MCS broadcast channel */
  259. /************************************************************************/
  260. DCUINT channelID;
  261. /************************************************************************/
  262. /* User data to be passed to the Core (saved in SLOnConnected() and */
  263. /* passed to Core's OnReceived callback by SLOnPacketReceived()) */
  264. /************************************************************************/
  265. PDCUINT8 pSCUserData;
  266. DCUINT SCUserDataLength;
  267. /************************************************************************/
  268. /* User data to be passed to the Server (saved in SLInitSecurity() and */
  269. /* passed to NL_Connect() by SL_Connect()). */
  270. /************************************************************************/
  271. PDCUINT8 pCSUserData;
  272. DCUINT CSUserDataLength;
  273. /************************************************************************/
  274. /* Disconnection reason code. This may be used to override the NL */
  275. /* disconnection reason code. */
  276. /************************************************************************/
  277. DCUINT disconnectErrorCode;
  278. /************************************************************************/
  279. /* Server version (once connected) */
  280. /************************************************************************/
  281. DCUINT32 serverVersion;
  282. //
  283. // Safe checksum enabled
  284. //
  285. BOOL fEncSafeChecksumCS;
  286. BOOL fEncSafeChecksumSC;
  287. CAPIData SLCapiData;
  288. } SL_GLOBAL_DATA, DCPTR PSL_GLOBAL_DATA;
  289. /****************************************************************************/
  290. /* SL State Table */
  291. /****************************************************************************/
  292. static unsigned slStateTable[SL_NUMEVENTS][SL_NUMSTATES]
  293. = {
  294. /********************************************************************/
  295. /* This is not a state table in the strict sense. It simply shows */
  296. /* which events are valid in which states. It is not used to drive */
  297. /* _SL. */
  298. /* */
  299. /* Values mean */
  300. /* - 0 event OK in this state. */
  301. /* - 1 warning - event should not occur in this state, but does in */
  302. /* some race conditions - ignore it. */
  303. /* - 2 error - event should not occur in ths state at all. */
  304. /* */
  305. /* These values are hard-coded here in order to make the table */
  306. /* readable. They correspond to the constants SL_TABLE_OK, */
  307. /* SL_TABLE_WARN & SL_TABLE_ERROR. */
  308. /* */
  309. /* SL may enter Initialized state after issuing a Disconnect */
  310. /* reqeest, but before the OnDisconnected indication is received. */
  311. /* In this state, the Sender thread may issue SL_GetBuffer or */
  312. /* SL_Disconnect (as it has not yet received the OnDisconnected */
  313. /* callback). */
  314. /* Also, if the security exchange fails, we can enter Initialized */
  315. /* state before the NL is disconnected, and so could receive */
  316. /* packets from the network. */
  317. /* */
  318. /* When SL is in Disconnecting state, the Sender Thread may still */
  319. /* issue GetBuffer and SendPacket calls. If disconnect is */
  320. /* requested during security exchange, then packets may be received */
  321. /* (until OnDisconnected is called). */
  322. /* Also, may get OnConnected in Disconnecting state if a Disconnect */
  323. /* is before the connection is complete (cross-over). */
  324. /* */
  325. /* Terminated */
  326. /* | Initializing */
  327. /* | | Initialized */
  328. /* | | | NL Connecting */
  329. /* | | | | SL Connecting */
  330. /* | | | | | Licensing */
  331. /* | | | | | | Connected */
  332. /* | | | | | | | Disconnecting */
  333. /* | | | | | | | | Terminating */
  334. /********************************************************************/
  335. { 0, 2, 2, 2, 2, 2, 2, 2, 2}, /* SL_Init */
  336. { 2, 0, 0, 0, 0, 0, 0, 0, 2}, /* SL_Term */
  337. { 2, 2, 0, 2, 2, 2, 2, 2, 2}, /* SL_Connect */
  338. { 2, 2, 1, 0, 0, 0, 0, 1, 2}, /* SL_Disconnect */
  339. { 2, 2, 1, 2, 0, 0, 0, 1, 2}, /* SL_SendPacket */
  340. { 2, 2, 1, 1, 1, 0, 0, 1, 2}, /* SL_GetBuffer */
  341. { 2, 0, 2, 2, 2, 2, 2, 2, 2}, /* SL_OnInitialized */
  342. { 2, 2, 2, 2, 2, 2, 2, 2, 0}, /* SL_OnTerminating */
  343. { 2, 2, 2, 0, 2, 2, 2, 1, 2}, /* SL_OnConnected */
  344. { 2, 2, 1, 0, 0, 0, 0, 0, 0}, /* SL_OnDisconnected*/
  345. { 2, 2, 1, 2, 0, 2, 2, 1, 2}, /* SL_OnPktRec(Sec) */
  346. { 2, 2, 1, 2, 2, 0, 2, 1, 2}, /* SL_OnPktRec(Lic) */
  347. { 2, 2, 1, 1, 2, 2, 0, 1, 2}, /* SL_OnPktRec(Data)*/
  348. { 1, 1, 1, 1, 0, 0, 0, 0, 1} /* SL_OnBufferAvail */
  349. };
  350. #ifdef DC_DEBUG
  351. /****************************************************************************/
  352. /* State and event descriptions (debug build only) */
  353. /****************************************************************************/
  354. static const DCTCHAR slState[SL_NUMSTATES][25]
  355. //#ifdef DC_DEFINE_GLOBAL_DATA
  356. = {
  357. _T("SL_STATE_TERMINATED"),
  358. _T("SL_STATE_INITIALIZING"),
  359. _T("SL_STATE_INITIALIZED"),
  360. _T("SL_STATE_NL_CONNECTING"),
  361. _T("SL_STATE_SL_CONNECTING"),
  362. _T("SL_STATE_LICENSING"),
  363. _T("SL_STATE_CONNECTED"),
  364. _T("SL_STATE_DISCONNECTING"),
  365. _T("SL_STATE_TERMINATING")
  366. }
  367. //#endif /* DC_DEFINE_GLOBAL_DATA */
  368. ;
  369. static const DCTCHAR slEvent[SL_NUMEVENTS][35]
  370. //#ifdef DC_DEFINE_GLOBAL_DATA
  371. = {
  372. _T("SL_EVENT_SL_INIT"),
  373. _T("SL_EVENT_SL_TERM"),
  374. _T("SL_EVENT_SL_CONNECT"),
  375. _T("SL_EVENT_SL_DISCONNECT"),
  376. _T("SL_EVENT_SL_SENDPACKET"),
  377. _T("SL_EVENT_SL_GETBUFFER"),
  378. _T("SL_EVENT_ON_INITIALIZED"),
  379. _T("SL_EVENT_ON_TERMINATING"),
  380. _T("SL_EVENT_ON_CONNECTED"),
  381. _T("SL_EVENT_ON_DISCONNECTED"),
  382. _T("SL_EVENT_ON_RECEIVED_SEC_PACKET"),
  383. _T("SL_EVENT_ON_RECEIVED_LIC_PACKET"),
  384. _T("SL_EVENT_ON_RECEIVED_DATA_PACKET"),
  385. _T("SL_EVENT_ON_BUFFERAVAILABLE")
  386. }
  387. //#endif /* DC_DEFINE_GLOBAL_DATA */
  388. ;
  389. #endif /* DC_DEBUG */
  390. class CUI;
  391. class CUH;
  392. class CRCV;
  393. class CCD;
  394. class CSND;
  395. class CCC;
  396. class CIH;
  397. class COR;
  398. class CSP;
  399. class CNL;
  400. class CMCS;
  401. class CTD;
  402. class CCO;
  403. class CCLX;
  404. class CLic;
  405. class CChan;
  406. class CSL
  407. {
  408. public:
  409. CSL(CObjs* objs);
  410. ~CSL();
  411. public:
  412. //
  413. // API
  414. //
  415. DCVOID DCAPI SL_Init(PSL_CALLBACKS pCallbacks);
  416. DCVOID DCAPI SL_Term(DCVOID);
  417. DCVOID DCAPI SL_Connect(BOOL bInitateConnect,
  418. PDCTCHAR pServerAddress,
  419. DCUINT transportType,
  420. PDCTCHAR pProtocolName,
  421. PDCUINT8 pUserData,
  422. DCUINT userDataLength);
  423. DCVOID DCAPI SL_Disconnect(DCVOID);
  424. DCVOID DCAPI SL_SendPacket(PDCUINT8 pData,
  425. DCUINT dataLen,
  426. DCUINT flags,
  427. SL_BUFHND bufHandle,
  428. DCUINT userID,
  429. DCUINT channel,
  430. DCUINT priority);
  431. void DCAPI SL_SendFastPathInputPacket(BYTE FAR *, unsigned, unsigned,
  432. SL_BUFHND);
  433. DCBOOL DCAPI SL_GetBufferRtl(DCUINT dataLen,
  434. PPDCUINT8 pBuffer,
  435. PSL_BUFHND pBufHandle);
  436. DCBOOL DCAPI SL_GetBufferDbg(DCUINT dataLen,
  437. PPDCUINT8 pBuffer,
  438. PSL_BUFHND pBufHandle,
  439. PDCTCHAR pCaller);
  440. /****************************************************************************/
  441. /* Debug and retail versions of SL_GetBuffer */
  442. /****************************************************************************/
  443. #ifdef DC_DEBUG
  444. #define SL_GetBuffer(dataLen, pBuffer, pBufHandle) \
  445. SL_GetBufferDbg(dataLen, pBuffer, pBufHandle, trc_fn)
  446. #else
  447. #define SL_GetBuffer(dataLen, pBuffer, pBufHandle) \
  448. SL_GetBufferRtl(dataLen, pBuffer, pBufHandle)
  449. #endif
  450. DCVOID DCAPI SL_FreeBuffer(SL_BUFHND bufHandle);
  451. DCVOID DCAPI SL_SendSecurityPacket(PDCVOID pData,
  452. DCUINT dataLength);
  453. EXPOSE_CD_NOTIFICATION_FN(CSL, SL_SendSecurityPacket);
  454. DCVOID DCAPI SL_SendSecInfoPacket(PDCVOID pData,
  455. DCUINT dataLength);
  456. EXPOSE_CD_NOTIFICATION_FN(CSL, SL_SendSecInfoPacket);
  457. DCVOID DCAPI SL_EnableEncryption(ULONG_PTR pEnableEncryption);
  458. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CSL, SL_EnableEncryption);
  459. /****************************************************************************/
  460. /* Loopback testing */
  461. /****************************************************************************/
  462. #ifdef DC_LOOPBACK
  463. DCVOID DCAPI SL_LoopBack(DCBOOL start);
  464. DCVOID DCAPI SL_LoopbackLoop(DCUINT ignored);
  465. #endif /* DC_LOOPBACK */
  466. public:
  467. //
  468. // Data members
  469. //
  470. SL_GLOBAL_DATA _SL;
  471. public:
  472. /****************************************************************************/
  473. /* Callbacks from NL (passed on NL_Init()) */
  474. /****************************************************************************/
  475. DCVOID DCCALLBACK SL_OnInitialized(DCVOID);
  476. DCVOID DCCALLBACK SL_OnTerminating(DCVOID);
  477. DCVOID DCCALLBACK SL_OnConnected(DCUINT channelID,
  478. PDCVOID pUserData,
  479. DCUINT userDataLength,
  480. DCUINT32 serverVersion);
  481. DCVOID DCCALLBACK SL_OnDisconnected(DCUINT reason);
  482. HRESULT DCCALLBACK SL_OnPacketReceived(PDCUINT8 pData,
  483. DCUINT dataLen,
  484. DCUINT flags,
  485. DCUINT channelID,
  486. DCUINT priority);
  487. DCVOID DCCALLBACK SL_OnBufferAvailable(DCVOID);
  488. HRESULT DCAPI SL_OnFastPathOutputReceived(BYTE FAR *, unsigned,
  489. BOOL, BOOL);
  490. //
  491. // Immediately drop the link
  492. //
  493. HRESULT SL_DropLinkImmediate(UINT reason);
  494. //
  495. // Static inline versions
  496. //
  497. static void DCCALLBACK SL_StaticOnInitialized(PVOID inst)
  498. {
  499. ((CSL*)inst)->SL_OnInitialized();
  500. }
  501. static void DCCALLBACK SL_StaticOnTerminating(PVOID inst)
  502. {
  503. ((CSL*)inst)->SL_OnTerminating();
  504. }
  505. static void DCCALLBACK SL_StaticOnConnected(
  506. PVOID inst,
  507. unsigned channelID,
  508. PVOID pUserData,
  509. unsigned userDataLength,
  510. UINT32 serverVersion)
  511. {
  512. ((CSL*)inst)->SL_OnConnected( channelID, pUserData, userDataLength, serverVersion);
  513. }
  514. static void DCCALLBACK SL_StaticOnDisconnected(PVOID inst, unsigned reason)
  515. {
  516. ((CSL*)inst)->SL_OnDisconnected( reason);
  517. }
  518. static HRESULT DCCALLBACK SL_StaticOnPacketReceived(
  519. PVOID inst,
  520. BYTE *pData,
  521. unsigned dataLen,
  522. unsigned flags,
  523. unsigned channelID,
  524. unsigned priority)
  525. {
  526. return ((CSL*)inst)->SL_OnPacketReceived(pData, dataLen, flags, channelID, priority);
  527. }
  528. static void DCCALLBACK SL_StaticOnBufferAvailable(PVOID inst)
  529. {
  530. ((CSL*)inst)->SL_OnBufferAvailable();
  531. }
  532. DCVOID DCAPI SLIssueDisconnectedCallback(ULONG_PTR reason);
  533. EXPOSE_CD_SIMPLE_NOTIFICATION_FN( CSL, SLIssueDisconnectedCallback);
  534. DCVOID DCAPI SLSetReasonAndDisconnect(ULONG_PTR reason);
  535. EXPOSE_CD_SIMPLE_NOTIFICATION_FN( CSL, SLSetReasonAndDisconnect);
  536. DCVOID DCAPI SLLicenseData(PDCVOID pData, DCUINT dataLen);
  537. EXPOSE_CD_NOTIFICATION_FN( CSL, SLLicenseData);
  538. DCVOID DCAPI SL_SetEncSafeChecksumCS(ULONG_PTR f)
  539. {
  540. _SL.fEncSafeChecksumCS = (BOOL)f;
  541. }
  542. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CSL, SL_SetEncSafeChecksumCS);
  543. BOOL SL_GetEncSafeChecksumCS()
  544. {
  545. return _SL.fEncSafeChecksumCS;
  546. }
  547. DCVOID DCAPI SL_SetEncSafeChecksumSC(BOOL f)
  548. {
  549. _SL.fEncSafeChecksumSC = f;
  550. }
  551. BOOL SL_GetEncSafeChecksumSC()
  552. {
  553. return _SL.fEncSafeChecksumSC;
  554. }
  555. private:
  556. /****************************************************************************/
  557. /* Internal functions */
  558. /****************************************************************************/
  559. DCVOID DCINTERNAL SLInitSecurity(DCVOID);
  560. DCVOID DCINTERNAL SLInitCSUserData(DCVOID);
  561. DCVOID DCINTERNAL SLSendSecInfoPacket(DCVOID);
  562. DCBOOL DCINTERNAL SLSendSecurityPacket(PDCUINT8 serverPublicKey,
  563. DCUINT32 serverPublicKeyLen);
  564. HRESULT DCINTERNAL SLReceivedDataPacket(PDCUINT8 pData,
  565. DCUINT dataLen,
  566. DCUINT flags,
  567. DCUINT channelID,
  568. DCUINT priority);
  569. DCBOOL DCINTERNAL SLDecryptRedirectionPacket(PDCUINT8 *ppData,
  570. DCUINT *pdataLen);
  571. DCBOOL DCINTERNAL SL_DecryptHelper(PDCUINT8 pData,
  572. DCUINT *pdataLen);
  573. DCVOID DCINTERNAL SLReceivedSecPacket(PDCUINT8 pData,
  574. DCUINT dataLen,
  575. DCUINT flags,
  576. DCUINT channelID,
  577. DCUINT priority);
  578. DCVOID DCINTERNAL SLReceivedLicPacket(PDCUINT8 pData,
  579. DCUINT dataLen,
  580. DCUINT flags,
  581. DCUINT channelID,
  582. DCUINT priority);
  583. DCVOID DCINTERNAL SLFreeConnectResources(DCVOID);
  584. DCVOID DCINTERNAL SLFreeInitResources(DCVOID);
  585. DCBOOL DCINTERNAL SLValidateServerCert( PDCUINT8 pbCert,
  586. DCUINT32 cbCert,
  587. CERT_TYPE * pCertType );
  588. #ifdef DC_LOOPBACK
  589. DCVOID DCINTERNAL SLLoopbackSendPacket(PDCUINT8 pData,
  590. DCUINT dataLen,
  591. SL_BUFHND bufHandle,
  592. PDCUINT8 pRefData);
  593. DCVOID DCINTERNAL SLLBQueueAdd(PSL_LB_PACKET pPacket,
  594. PSL_LB_Q_ELEMENT pRoot);
  595. PSL_LB_Q_ELEMENT DCINTERNAL SLLBQueueRemove(PSL_LB_Q_ELEMENT pRoot);
  596. DCVOID DCINTERNAL SLLBPacketCheck(PDCUINT8 pData, DCUINT dataLen);
  597. #endif /* DC_LOOPBACK */
  598. DCBOOL DCINTERNAL SLGetComputerAddressW(PDCUINT8 szBuff);
  599. BOOL
  600. SLComputeHMACVerifier(
  601. PBYTE pCookie, //IN - the shared secret
  602. LONG cbCookieLen, //IN - the shared secret len
  603. PBYTE pRandom, //IN - the session random
  604. LONG cbRandomLen, //IN - the session random len
  605. PBYTE pVerifier, //OUT- the verifier
  606. LONG cbVerifierLen //IN - the verifier buffer length
  607. );
  608. private:
  609. CUT* _pUt;
  610. CUI* _pUi;
  611. CNL* _pNl;
  612. CUH* _pUh;
  613. CRCV* _pRcv;
  614. CCD* _pCd;
  615. CSND* _pSnd;
  616. CCC* _pCc;
  617. CIH* _pIh;
  618. COR* _pOr;
  619. CSP* _pSp;
  620. CMCS* _pMcs;
  621. CTD* _pTd;
  622. CCO* _pCo;
  623. CCLX* _pClx;
  624. CLic* _pLic;
  625. CChan* _pChan;
  626. private:
  627. CObjs* _pClientObjects;
  628. BOOL _fSLInitComplete;
  629. };
  630. #endif // _H_SL