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.

1354 lines
41 KiB

  1. // Test.cpp : Defines the entry point for the console application. This code uses SASL calling convention
  2. //
  3. #include "testglobal.h"
  4. #include <stdio.h> // printf
  5. #include <security.h> // General definition of a Security Support Provider
  6. #define AUTH_USERNAME "test1"
  7. #define AUTH_USERNAME_W L"test1"
  8. #define AUTH_NONCE "9b38dce631309cc25a653ebaad5b18ee01c8bf385260b26db0574a302be4c11367"
  9. #define AUTH_URI_W L"imap/elwood.innosoft.com"
  10. #define AUTH_NC "0000000b"
  11. #define AUTH_NC1 "00000001"
  12. #define AUTH_NC2 "00000002"
  13. #define AUTH_NC3 "00000003"
  14. #define AUTH_NC4 "00000004"
  15. #define AUTHDATA_USERNAME L"test1"
  16. // #define AUTHDATA_DOMAIN L"kdamour2w.damourlan.nttest.microsoft.com"
  17. // #define AUTHDATA_DOMAIN L"damourlan"
  18. #define AUTHDATA_DOMAIN L"damourlan"
  19. #define AUTHDATA_PASSWORD L"test1"
  20. #define STR_BUF_SIZE 4000
  21. char g_czTestPasswd[257];
  22. BOOLEAN QuietMode = FALSE; // Don't be verbose
  23. // Prototypes
  24. void PrintStatus(SECURITY_STATUS NetStatus);
  25. void PrintTime(LPSTR Comment,TimeStamp ConvertTime);
  26. void ISCRETFlags(ULONG ulFlags);
  27. void ASCRETFlags(ULONG ulFlags);
  28. VOID BinToHex(
  29. LPBYTE pSrc,
  30. UINT cSrc,
  31. LPSTR pDst
  32. );
  33. int __cdecl
  34. main(int argc, char* argv[])
  35. {
  36. BOOL bPass = TRUE;
  37. SECURITY_STATUS Status = STATUS_SUCCESS;
  38. char cTemp[STR_BUF_SIZE]; // temp buffer for scratch data
  39. char cTemp2[STR_BUF_SIZE]; // temp buffer for scratch data
  40. char cTemp3[STR_BUF_SIZE]; // temp buffer for scratch data
  41. char cTempPadding[STR_BUF_SIZE]; // temp buffer for scratch data
  42. char cOutputTemp[STR_BUF_SIZE];
  43. char szOutSecBuf[STR_BUF_SIZE];
  44. char szChallenge[STR_BUF_SIZE];
  45. char szISCChallengeResponse[STR_BUF_SIZE]; // Output buffer from ISC
  46. char szASCChallengeResponse[STR_BUF_SIZE]; // Output buffer from ASC
  47. char szASCResponseAuth[STR_BUF_SIZE]; // Output buffer from ASC
  48. // SSPI Interface tests
  49. ULONG PackageCount = 0;
  50. int i = 0;
  51. PSecPkgInfo pPackageInfo = NULL;
  52. PSecPkgInfo pPackageTmp = NULL;
  53. SECURITY_STATUS TmpStatus = STATUS_SUCCESS;
  54. CredHandle ServerCred;
  55. CredHandle ClientCred;
  56. TimeStamp Lifetime;
  57. BOOL bServerCred = FALSE;
  58. BOOL bClientCred = FALSE;
  59. PBYTE pTemp = NULL;
  60. ULONG ulTemp = 0;
  61. int j = 0;
  62. SecPkgContext_StreamSizes StreamSizes;
  63. ULONG ClientContextReqFlags = ISC_REQ_INTEGRITY | ISC_REQ_CONFIDENTIALITY | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONNECTION;
  64. ULONG ServerContextReqFlags = ASC_REQ_INTEGRITY | ASC_REQ_CONFIDENTIALITY;
  65. ULONG ClientContextRetFlags = 0;
  66. ULONG ServerContextRetFlags = 0;
  67. ULONG TargetDataRep = 0;
  68. CtxtHandle OldContextHandle;
  69. CtxtHandle ServerCtxtHandle;
  70. CtxtHandle ClientCtxtHandle;
  71. SecBufferDesc InputBuffers;
  72. SecBufferDesc OutputBuffers;
  73. SecBuffer TempTokensIn[10];
  74. SecBuffer TempTokensOut[6];
  75. PCHAR pcPtr = NULL;
  76. int iLen = 0;
  77. UNICODE_STRING ustrUsername;
  78. UNICODE_STRING ustrPassword;
  79. UNICODE_STRING ustrDomain;
  80. STRING strTemp;
  81. STRING strChallenge;
  82. STRING strMethod;
  83. STRING strHEntity;
  84. STRING strOutBuffer;
  85. ULONG ulMessSeqNo = 0;
  86. ULONG ulQOP = 0;
  87. SEC_WINNT_AUTH_IDENTITY_W AuthData;
  88. printf("Begining TESTC...\n");
  89. ZeroMemory(&ClientCred, sizeof(CredHandle));
  90. ZeroMemory(&ServerCred, sizeof(CredHandle));
  91. ZeroMemory(&OldContextHandle, sizeof(CtxtHandle));
  92. ZeroMemory(&ServerCtxtHandle, sizeof(CtxtHandle));
  93. ZeroMemory(&ClientCtxtHandle, sizeof(CtxtHandle));
  94. ZeroMemory(&ustrUsername, sizeof(ustrUsername));
  95. ZeroMemory(&ustrPassword, sizeof(ustrPassword));
  96. ZeroMemory(&ustrDomain, sizeof(ustrDomain));
  97. ZeroMemory(&strTemp, sizeof(strTemp));
  98. ZeroMemory(&StreamSizes, sizeof(StreamSizes));
  99. // Pull out any command line args
  100. if (argc > 1)
  101. {
  102. for (i = 1; i < argc; i++)
  103. {
  104. pcPtr = argv[i];
  105. if (*pcPtr == '-')
  106. {
  107. iLen = strlen(pcPtr);
  108. if (iLen >= 2)
  109. {
  110. switch (*(pcPtr + 1))
  111. {
  112. case 'u':
  113. Status = RtlCreateUnicodeStringFromAsciiz(&ustrUsername, (pcPtr + 2));
  114. break;
  115. case 'd':
  116. Status = RtlCreateUnicodeStringFromAsciiz(&ustrDomain, (pcPtr + 2));
  117. break;
  118. case 'p':
  119. Status = RtlCreateUnicodeStringFromAsciiz(&ustrPassword, (pcPtr + 2));
  120. break;
  121. case '?':
  122. default:
  123. printf("Usage: %s -uUsername -pPassword -ddomain\n", argv[0]);
  124. return(-1);
  125. break;
  126. }
  127. }
  128. }
  129. }
  130. }
  131. //
  132. // Get info about the security packages.
  133. //
  134. Status = EnumerateSecurityPackages( &PackageCount, &pPackageInfo );
  135. TmpStatus = GetLastError();
  136. if (!NT_SUCCESS(Status)) {
  137. printf( "EnumerateSecurityPackages failed: 0x%x", Status);
  138. PrintStatus( Status );
  139. bPass = FALSE;
  140. goto CleanUp;
  141. }
  142. if ( !QuietMode ) {
  143. printf( "PackageCount: %ld\n", PackageCount );
  144. for ( i= 0; i< (int)PackageCount; i++)
  145. {
  146. pPackageTmp = (pPackageInfo + i);
  147. printf( "Name: %ws Comment: %ws\n", pPackageTmp->Name, pPackageTmp->Comment );
  148. printf( "Cap: %ld Version: %ld RPCid: %ld MaxToken: %ld\n\n",
  149. pPackageTmp->fCapabilities,
  150. pPackageTmp->wVersion,
  151. pPackageTmp->wRPCID,
  152. pPackageTmp->cbMaxToken );
  153. }
  154. }
  155. //
  156. // Get info about the security packages.
  157. //
  158. Status = QuerySecurityPackageInfo( WDIGEST_SP_NAME, &pPackageInfo );
  159. TmpStatus = GetLastError();
  160. if (!NT_SUCCESS(Status)) {
  161. printf( "QuerySecurityPackageInfo failed: " );
  162. PrintStatus( Status );
  163. bPass = FALSE;
  164. goto CleanUp;
  165. }
  166. if ( !QuietMode ) {
  167. printf( "Name: %ws Comment: %ws\n", pPackageInfo->Name, pPackageInfo->Comment );
  168. printf( "Cap: %ld Version: %ld RPCid: %ld MaxToken: %ld\n\n",
  169. pPackageInfo->fCapabilities,
  170. pPackageInfo->wVersion,
  171. pPackageInfo->wRPCID,
  172. pPackageInfo->cbMaxToken );
  173. }
  174. //
  175. // Acquire a credential handle for the server side
  176. //
  177. printf("Server AcquireCredentialHandle\n");
  178. Status = AcquireCredentialsHandle(
  179. NULL, // New principal
  180. WDIGEST_SP_NAME, // Package Name
  181. SECPKG_CRED_INBOUND,
  182. NULL,
  183. NULL,
  184. NULL,
  185. NULL,
  186. &ServerCred,
  187. &Lifetime );
  188. if (!NT_SUCCESS(Status)) {
  189. printf( "AcquireCredentialsHandle failed: ");
  190. printf( "FAILED: AcquireCredentialsHandle failed: status 0x%x\n", Status);
  191. PrintStatus( Status );
  192. bPass = FALSE;
  193. ZeroMemory(&ServerCred, sizeof(CredHandle));
  194. goto CleanUp;
  195. }
  196. bServerCred = TRUE;
  197. //
  198. // Acquire a credential handle for the client side
  199. //
  200. printf("Client AcquireCredentialHandle\n");
  201. if (ustrUsername.Length || ustrPassword.Length || ustrDomain.Length)
  202. {
  203. printf("ACH Using supplied credentials\n");
  204. printf(" Username %wZ Domain %wZ Password %wZ\n",
  205. &ustrUsername, &ustrDomain, &ustrPassword);
  206. ZeroMemory(&AuthData, sizeof(SEC_WINNT_AUTH_IDENTITY_W));
  207. AuthData.Domain = ustrDomain.Buffer;
  208. AuthData.DomainLength = ustrDomain.Length / sizeof(WCHAR);
  209. AuthData.Password = ustrPassword.Buffer;
  210. AuthData.PasswordLength = ustrPassword.Length / sizeof(WCHAR);
  211. AuthData.User = ustrUsername.Buffer;
  212. AuthData.UserLength = ustrUsername.Length / sizeof(WCHAR);
  213. AuthData.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  214. Status = AcquireCredentialsHandle(
  215. NULL, // AUTH_USERNAME_W, // get the creds for user digest
  216. WDIGEST_SP_NAME, // Package Name
  217. SECPKG_CRED_OUTBOUND,
  218. NULL,
  219. &AuthData, // Make NULL not to use any AuthData for cred
  220. NULL,
  221. NULL,
  222. &ClientCred,
  223. &Lifetime );
  224. }
  225. else
  226. {
  227. printf("ACH Using default credentials\n");
  228. Status = AcquireCredentialsHandle(
  229. NULL, // AUTH_USERNAME_W, // get the creds for user digest
  230. WDIGEST_SP_NAME, // Package Name
  231. SECPKG_CRED_OUTBOUND,
  232. NULL,
  233. NULL,
  234. NULL,
  235. NULL,
  236. &ClientCred,
  237. &Lifetime );
  238. }
  239. if (!NT_SUCCESS(Status)) {
  240. printf( "AcquireCredentialsHandle failed: for user %s: ", AUTH_USERNAME);
  241. PrintStatus( Status );
  242. // bPass = FALSE;
  243. // ZeroMemory(&ClientCred, sizeof(CredHandle));
  244. // goto CleanUp;
  245. }
  246. else
  247. bClientCred = TRUE;
  248. if ( !QuietMode ) {
  249. printf( "ClientCred: 0x%lx 0x%lx ",
  250. ClientCred.dwLower, ClientCred.dwUpper );
  251. printf( "ServerCred: 0x%lx 0x%lx ",
  252. ServerCred.dwLower, ServerCred.dwUpper );
  253. PrintTime( "Lifetime: ", Lifetime );
  254. }
  255. // Big time - call Accept with no parameters to get a challenge
  256. StringAllocate(&strChallenge, 0);
  257. StringCharDuplicate(&strMethod, "GET");
  258. StringAllocate(&strHEntity, 0);
  259. StringAllocate(&strOutBuffer, 4000);
  260. ZeroMemory(TempTokensIn, sizeof(TempTokensIn));
  261. ZeroMemory(TempTokensOut, sizeof(TempTokensOut));
  262. ZeroMemory(&InputBuffers, sizeof(SecBufferDesc));
  263. ZeroMemory(&OutputBuffers, sizeof(SecBufferDesc));
  264. // SASL first calls ISC with no-input
  265. InputBuffers.ulVersion = SECBUFFER_VERSION;
  266. InputBuffers.cBuffers = 1;
  267. InputBuffers.pBuffers = TempTokensIn;
  268. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  269. TempTokensIn[0].cbBuffer = 1; // no data passed in
  270. TempTokensIn[0].pvBuffer = cTemp;
  271. OutputBuffers.ulVersion = SECBUFFER_VERSION;
  272. OutputBuffers.cBuffers = 1;
  273. OutputBuffers.pBuffers = TempTokensOut;
  274. TempTokensOut[0].BufferType = SECBUFFER_TOKEN;
  275. TempTokensOut[0].cbBuffer = strOutBuffer.MaximumLength; // use any space here
  276. TempTokensOut[0].pvBuffer = strOutBuffer.Buffer;
  277. Status = InitializeSecurityContext(&ClientCred,
  278. NULL,
  279. AUTH_URI_W,
  280. ClientContextReqFlags,
  281. NULL,
  282. SECURITY_NATIVE_DREP,
  283. NULL, // &InputBuffers, MSDN allows NULL for 1st call
  284. NULL,
  285. &ClientCtxtHandle,
  286. &OutputBuffers,
  287. &ClientContextRetFlags,
  288. &Lifetime);
  289. if (!NT_SUCCESS(Status))
  290. {
  291. printf("InitializeSecurityContext SASL 1st call returned: ");
  292. PrintStatus( Status );
  293. bPass = FALSE;
  294. goto CleanUp;
  295. }
  296. printf("ISC Context Flags Req 0x%lx Ret 0x%lx\n", ClientContextReqFlags, ClientContextRetFlags);
  297. ISCRETFlags(ClientContextRetFlags);
  298. printf("InitializeSecurityContext SASL 1st call Output buffer size %d\n",
  299. TempTokensOut[0].cbBuffer );
  300. InputBuffers.ulVersion = SECBUFFER_VERSION;
  301. InputBuffers.cBuffers = 1;
  302. InputBuffers.pBuffers = TempTokensIn;
  303. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  304. TempTokensIn[0].cbBuffer = strChallenge.Length + 1; // for NULL
  305. TempTokensIn[0].pvBuffer = strChallenge.Buffer;
  306. OutputBuffers.ulVersion = SECBUFFER_VERSION;
  307. OutputBuffers.cBuffers = 1;
  308. OutputBuffers.pBuffers = TempTokensOut;
  309. TempTokensOut[0].BufferType = SECBUFFER_TOKEN;
  310. TempTokensOut[0].cbBuffer = strOutBuffer.MaximumLength; // use any space here
  311. TempTokensOut[0].pvBuffer = strOutBuffer.Buffer;
  312. Status = AcceptSecurityContext(
  313. &ServerCred,
  314. NULL,
  315. &InputBuffers,
  316. ServerContextReqFlags,
  317. TargetDataRep,
  318. &ServerCtxtHandle,
  319. &OutputBuffers,
  320. &ServerContextRetFlags,
  321. &Lifetime);
  322. if (Status != SEC_I_CONTINUE_NEEDED) // Indicates that this is the challenge
  323. {
  324. printf("SpAcceptLsaModeContext FAILED 0x%x\n", Status);
  325. PrintStatus( Status );
  326. bPass = FALSE;
  327. goto CleanUp;
  328. }
  329. ZeroMemory(cOutputTemp, STR_BUF_SIZE); // contains the output buffer
  330. ZeroMemory(szChallenge, STR_BUF_SIZE); // contains the output buffer
  331. strncpy(cOutputTemp, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  332. cOutputTemp[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  333. strncpy(szChallenge, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  334. szChallenge[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  335. printf("ASC Context Flags Req 0x%lx Ret 0x%lx\n", ServerContextReqFlags, ServerContextRetFlags);
  336. ASCRETFlags(ServerContextRetFlags);
  337. printf("Challenge Output Buffer is:\n%s\n\n", cOutputTemp);
  338. printf("Now call the SSPI InitializeSecCtxt to generate the ChallengeResponse\n");
  339. sprintf(cTemp, "username=\"%s\",%s,uri=\"%S\",nc=%0.8x",
  340. AUTH_USERNAME,
  341. szChallenge,
  342. AUTH_URI_W,
  343. 1);
  344. InputBuffers.ulVersion = SECBUFFER_VERSION;
  345. InputBuffers.cBuffers = 1;
  346. InputBuffers.pBuffers = TempTokensIn;
  347. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  348. TempTokensIn[0].cbBuffer = strlen(cTemp) + 1; // for NULL
  349. TempTokensIn[0].pvBuffer = cTemp;
  350. OutputBuffers.ulVersion = SECBUFFER_VERSION;
  351. OutputBuffers.cBuffers = 1;
  352. OutputBuffers.pBuffers = TempTokensOut;
  353. TempTokensOut[0].BufferType = SECBUFFER_TOKEN;
  354. TempTokensOut[0].cbBuffer = strOutBuffer.MaximumLength; // use any space here
  355. TempTokensOut[0].pvBuffer = strOutBuffer.Buffer;
  356. Status = InitializeSecurityContext(&ClientCred,
  357. &ClientCtxtHandle,
  358. AUTH_URI_W,
  359. ClientContextReqFlags,
  360. NULL,
  361. SECURITY_NATIVE_DREP,
  362. &InputBuffers,
  363. NULL,
  364. &ClientCtxtHandle,
  365. &OutputBuffers,
  366. &ClientContextRetFlags,
  367. &Lifetime);
  368. if (Status != SEC_I_CONTINUE_NEEDED) // Indicates that this is the challengeresponse - wait for mutual auth
  369. {
  370. printf("SpAcceptLsaModeContext FAILED 0x%x\n", Status);
  371. PrintStatus( Status );
  372. bPass = FALSE;
  373. goto CleanUp;
  374. }
  375. printf("InitializeSecurityContext SUCCEEDED with Context Handle (0x%x,0x%x)\n",
  376. ClientCtxtHandle.dwLower, ClientCtxtHandle.dwUpper );
  377. printf("ISC Context Flags Req 0x%lx Ret 0x%lx\n", ClientContextReqFlags, ClientContextRetFlags);
  378. ISCRETFlags(ClientContextRetFlags);
  379. ZeroMemory(cOutputTemp, STR_BUF_SIZE); // contains the output buffer
  380. ZeroMemory(szChallenge, STR_BUF_SIZE); // contains the output buffer
  381. strncpy(cOutputTemp, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  382. cOutputTemp[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  383. strncpy(szISCChallengeResponse, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  384. szISCChallengeResponse[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  385. printf("ISC: Challenge Response Output Buffer is\n%s\n\n", szISCChallengeResponse);
  386. InputBuffers.ulVersion = SECBUFFER_VERSION;
  387. InputBuffers.cBuffers = 1;
  388. InputBuffers.pBuffers = TempTokensIn;
  389. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  390. TempTokensIn[0].cbBuffer = strlen(cOutputTemp) + 1; // for NULL
  391. TempTokensIn[0].pvBuffer = cOutputTemp;
  392. OutputBuffers.ulVersion = SECBUFFER_VERSION;
  393. OutputBuffers.cBuffers = 1;
  394. OutputBuffers.pBuffers = TempTokensOut;
  395. TempTokensOut[0].BufferType = SECBUFFER_TOKEN;
  396. TempTokensOut[0].cbBuffer = strOutBuffer.MaximumLength; // use any space here
  397. TempTokensOut[0].pvBuffer = strOutBuffer.Buffer;
  398. printf("Calling the AcceptSC with a ChallengeResponse (should talk to the DC)!\n");
  399. Status = AcceptSecurityContext(
  400. &ServerCred,
  401. &ServerCtxtHandle,
  402. &InputBuffers,
  403. ServerContextReqFlags,
  404. TargetDataRep,
  405. &ServerCtxtHandle,
  406. &OutputBuffers,
  407. &ServerContextRetFlags,
  408. &Lifetime);
  409. if (!NT_SUCCESS(Status))
  410. {
  411. printf("AcceptSecurityContext 2nd Call: ");
  412. PrintStatus( Status );
  413. bPass = FALSE;
  414. goto CleanUp;
  415. }
  416. strcpy(szASCChallengeResponse, (char *)InputBuffers.pBuffers[0].pvBuffer);
  417. ZeroMemory(cOutputTemp, STR_BUF_SIZE); // contains the output buffer
  418. ZeroMemory(szASCResponseAuth, STR_BUF_SIZE); // contains the output buffer
  419. strncpy(cOutputTemp, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  420. cOutputTemp[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  421. strncpy(szASCResponseAuth, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  422. szASCResponseAuth[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  423. printf("ASC has accepted the Challenge Resposne and generated rspauth for mutual auth back to client\n");
  424. printf("ASC Context Flags Req 0x%lx Ret 0x%lx\n", ServerContextReqFlags, ServerContextRetFlags);
  425. ASCRETFlags(ServerContextRetFlags);
  426. printf("ASC: Response Auth Output Buffer is\n%s\n\n", szASCResponseAuth);
  427. printf("Now have a valid Security Context handle from ASC\n\n");
  428. InputBuffers.ulVersion = SECBUFFER_VERSION;
  429. InputBuffers.cBuffers = 1;
  430. InputBuffers.pBuffers = TempTokensIn;
  431. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  432. TempTokensIn[0].cbBuffer = strlen(cOutputTemp) + 1; // for NULL
  433. TempTokensIn[0].pvBuffer = cOutputTemp;
  434. OutputBuffers.ulVersion = SECBUFFER_VERSION;
  435. OutputBuffers.cBuffers = 1;
  436. OutputBuffers.pBuffers = TempTokensOut;
  437. TempTokensOut[0].BufferType = SECBUFFER_TOKEN;
  438. TempTokensOut[0].cbBuffer = strOutBuffer.MaximumLength; // use any space here
  439. TempTokensOut[0].pvBuffer = strOutBuffer.Buffer;
  440. Status = InitializeSecurityContext(&ClientCred,
  441. &ClientCtxtHandle,
  442. AUTH_URI_W,
  443. ClientContextReqFlags,
  444. NULL,
  445. SECURITY_NATIVE_DREP,
  446. &InputBuffers,
  447. NULL,
  448. &ClientCtxtHandle,
  449. &OutputBuffers,
  450. &ClientContextRetFlags,
  451. &Lifetime);
  452. if (!NT_SUCCESS(Status))
  453. {
  454. printf("InitializeSecurityContext on Response Auth FAILED: ");
  455. PrintStatus( Status );
  456. bPass = FALSE;
  457. goto CleanUp;
  458. }
  459. printf("InitializeSecurityContext SUCCEEDED with Context Handle (0x%x,0x%x)\n",
  460. ClientCtxtHandle.dwLower, ClientCtxtHandle.dwUpper );
  461. printf("ISC Context Flags Req 0x%lx Ret 0x%lx\n", ClientContextReqFlags, ClientContextRetFlags);
  462. ISCRETFlags(ClientContextRetFlags);
  463. ZeroMemory(cOutputTemp, STR_BUF_SIZE); // contains the output buffer
  464. strncpy(cOutputTemp, (char *)OutputBuffers.pBuffers[0].pvBuffer, OutputBuffers.pBuffers[0].cbBuffer);
  465. cOutputTemp[OutputBuffers.pBuffers[0].cbBuffer] = '\0';
  466. printf("\nISC: Mutual auth Output Buffer is\n%s\n\n", cOutputTemp);
  467. printf("Now have a valid Security Context handle from ISC and ASC\n\n");
  468. // Now get some info on the securitycontexts
  469. Status = QueryContextAttributes(&ServerCtxtHandle, SECPKG_ATTR_STREAM_SIZES, &StreamSizes);
  470. if (!NT_SUCCESS(Status))
  471. {
  472. printf("FAILED: QueryContextAttributes SECPKG_ATTR_STREAM_SIZES error: status 0x%x\n", Status);
  473. PrintStatus( Status );
  474. }
  475. else
  476. {
  477. printf("Server Context Stream Sizes: MaxBuf %lu Blocksize %lu Trailer %lu\n",
  478. StreamSizes.cbMaximumMessage, StreamSizes.cbBlockSize,
  479. StreamSizes.cbTrailer);
  480. }
  481. Status = QueryContextAttributes(&ClientCtxtHandle, SECPKG_ATTR_STREAM_SIZES, &StreamSizes);
  482. if (!NT_SUCCESS(Status))
  483. {
  484. printf("FAILED: QueryContextAttributes SECPKG_ATTR_STREAM_SIZES error: status 0x%x\n", Status);
  485. PrintStatus( Status );
  486. }
  487. else
  488. {
  489. printf("Client Context Stream Sizes: MaxBuf %lu Blocksize %lu Trailer %lu\n",
  490. StreamSizes.cbMaximumMessage, StreamSizes.cbBlockSize,
  491. StreamSizes.cbTrailer);
  492. }
  493. // Now have authenticated connection
  494. // Try MakeSignature and VerifySignature
  495. for (i = 0; i < 9; i++)
  496. {
  497. printf("Loop %d\n", i);
  498. ZeroMemory(cTemp, sizeof(cTemp));
  499. strcpy(cTemp, AUTH_NONCE); // Create message to sign
  500. InputBuffers.ulVersion = SECBUFFER_VERSION;
  501. InputBuffers.cBuffers = 5;
  502. InputBuffers.pBuffers = TempTokensIn;
  503. TempTokensIn[0].BufferType = SECBUFFER_TOKEN;
  504. TempTokensIn[0].cbBuffer = 0;
  505. TempTokensIn[0].pvBuffer = NULL;
  506. TempTokensIn[1].BufferType = SECBUFFER_DATA; // select some data to sign
  507. TempTokensIn[1].cbBuffer = 10;
  508. TempTokensIn[1].pvBuffer = cTemp;
  509. TempTokensIn[2].BufferType = SECBUFFER_PADDING;
  510. TempTokensIn[2].cbBuffer = STR_BUF_SIZE; // for NULL
  511. TempTokensIn[2].pvBuffer = cTempPadding;
  512. TempTokensIn[3].BufferType = SECBUFFER_DATA; // select some data to sign
  513. TempTokensIn[3].cbBuffer = 5; // for NULL use i to test non-blocksize buffers
  514. TempTokensIn[3].pvBuffer = cTemp + 10;
  515. TempTokensIn[4].BufferType = SECBUFFER_DATA; // select some data to sign
  516. // TempTokensIn[4].cbBuffer = strlen(AUTH_NONCE) + 1 -2 - 12 - i; // for NULL use i to test non-blocksize buffers
  517. TempTokensIn[4].cbBuffer = 40 + 1 -10 - 5 - i; // for NULL use i to test non-blocksize buffers
  518. TempTokensIn[4].pvBuffer = cTemp + 10 + 5;
  519. if (TempTokensIn[1].cbBuffer)
  520. {
  521. printf("Input Message to process is %d bytes in SecBuffer 1\n", TempTokensIn[1].cbBuffer);
  522. BinToHex((PBYTE)TempTokensIn[1].pvBuffer, TempTokensIn[1].cbBuffer, cTemp2);
  523. printf("Message: %s\n", cTemp2);
  524. }
  525. if (TempTokensIn[3].cbBuffer)
  526. {
  527. printf("Input Message to process is %d bytes in SecBuffer 3\n", TempTokensIn[3].cbBuffer);
  528. BinToHex((PBYTE)TempTokensIn[3].pvBuffer, TempTokensIn[3].cbBuffer, cTemp2);
  529. printf("Message: %s\n", cTemp2);
  530. }
  531. if (TempTokensIn[4].cbBuffer)
  532. {
  533. printf("Input Message to process is %d bytes in SecBuffer 4\n", TempTokensIn[4].cbBuffer);
  534. BinToHex((PBYTE)TempTokensIn[4].pvBuffer, TempTokensIn[4].cbBuffer, cTemp2);
  535. printf("Message: %s\n", cTemp2);
  536. }
  537. Status = EncryptMessage(&ClientCtxtHandle,
  538. ulQOP,
  539. &InputBuffers,
  540. 0);
  541. if (!NT_SUCCESS(Status))
  542. {
  543. printf("TestCredAPI: EncryptMessage FAILED: ");
  544. PrintStatus( Status );
  545. bPass = FALSE;
  546. goto CleanUp;
  547. }
  548. // put all of the parts together
  549. pTemp = (PBYTE)&cTemp3[0];
  550. ulTemp = 0;
  551. j = 1;
  552. memcpy(pTemp, (PBYTE)TempTokensIn[j].pvBuffer, TempTokensIn[j].cbBuffer);
  553. pTemp = pTemp + TempTokensIn[j].cbBuffer;
  554. ulTemp = ulTemp + TempTokensIn[j].cbBuffer;
  555. j = 3;
  556. memcpy(pTemp, (PBYTE)TempTokensIn[j].pvBuffer, TempTokensIn[j].cbBuffer);
  557. pTemp = pTemp + TempTokensIn[j].cbBuffer;
  558. ulTemp = ulTemp + TempTokensIn[j].cbBuffer;
  559. j = 4;
  560. memcpy(pTemp, (PBYTE)TempTokensIn[j].pvBuffer, TempTokensIn[j].cbBuffer);
  561. pTemp = pTemp + TempTokensIn[j].cbBuffer;
  562. ulTemp = ulTemp + TempTokensIn[j].cbBuffer;
  563. memcpy(pTemp, (PBYTE)TempTokensIn[2].pvBuffer, TempTokensIn[2].cbBuffer); // signature bytes
  564. pTemp = pTemp + TempTokensIn[2].cbBuffer;
  565. ulTemp = ulTemp + TempTokensIn[2].cbBuffer;
  566. // You now send Output buffer to Server - in this case the buffer is szOutSecBuf
  567. printf("Now verify that the message is Authenticate\n");
  568. InputBuffers.ulVersion = SECBUFFER_VERSION;
  569. InputBuffers.cBuffers = 2;
  570. InputBuffers.pBuffers = TempTokensIn;
  571. TempTokensIn[0].BufferType = SECBUFFER_STREAM;
  572. TempTokensIn[0].cbBuffer = ulTemp;
  573. TempTokensIn[0].pvBuffer = cTemp3;
  574. TempTokensIn[1].BufferType = SECBUFFER_DATA;
  575. TempTokensIn[1].cbBuffer = 0;
  576. TempTokensIn[1].pvBuffer = NULL;
  577. Status = DecryptMessage(&ServerCtxtHandle,
  578. &InputBuffers,
  579. ulMessSeqNo,
  580. &ulQOP);
  581. if (!NT_SUCCESS(Status))
  582. {
  583. printf("TestCredAPI: DecryptMessage Call FAILED :");
  584. PrintStatus( Status );
  585. bPass = FALSE;
  586. goto CleanUp;
  587. }
  588. printf("Now have a authenticated message under context 0x%x\n", ServerCtxtHandle);
  589. printf("Processed (verify/unseal) is %d bytes\n", TempTokensIn[1].cbBuffer);
  590. if (TempTokensIn[1].cbBuffer)
  591. {
  592. BinToHex((PBYTE)TempTokensIn[1].pvBuffer, TempTokensIn[1].cbBuffer, cTemp2);
  593. printf("Message: %s\n", cTemp2);
  594. }
  595. }
  596. CleanUp:
  597. printf("Leaving test program\n");
  598. if (pPackageInfo)
  599. {
  600. FreeContextBuffer(pPackageInfo);
  601. }
  602. printf("About to call deletesecuritycontext\n");
  603. //
  604. // Free the security context handle
  605. //
  606. if (ServerCtxtHandle.dwLower || ServerCtxtHandle.dwUpper)
  607. {
  608. Status = DeleteSecurityContext(&ServerCtxtHandle);
  609. if (!NT_SUCCESS(Status))
  610. {
  611. printf("ERROR: DeleteSecurityContext ServerCtxtHandle failed: ");
  612. PrintStatus(Status);
  613. }
  614. }
  615. if (ClientCtxtHandle.dwLower || ClientCtxtHandle.dwUpper)
  616. {
  617. Status = DeleteSecurityContext(&ClientCtxtHandle);
  618. if (!NT_SUCCESS(Status))
  619. {
  620. printf("ERROR: DeleteSecurityContext ClientCtxtHandle failed: ");
  621. PrintStatus(Status);
  622. }
  623. }
  624. //
  625. // Free the credential handles
  626. //
  627. printf("Now calling to Free the ServerCred\n");
  628. if (bServerCred)
  629. {
  630. Status = FreeCredentialsHandle( &ServerCred );
  631. if (!NT_SUCCESS(Status))
  632. {
  633. printf( "FreeCredentialsHandle failed for ServerCred: " );
  634. PrintStatus(Status);
  635. }
  636. }
  637. printf("Now calling to Free the ServerCred\n");
  638. if (bClientCred)
  639. {
  640. Status = FreeCredentialsHandle(&ClientCred);
  641. if (!NT_SUCCESS(Status))
  642. {
  643. printf( "FreeCredentialsHandle failed for ClientCred: " );
  644. PrintStatus( Status );
  645. }
  646. }
  647. StringFree(&strChallenge);
  648. StringFree(&strMethod);
  649. StringFree(&strHEntity);
  650. StringFree(&strOutBuffer);
  651. if (bPass != TRUE)
  652. printf("FAILED test run with one or more tests failing.\n");
  653. else
  654. printf("All tests passed.\n");
  655. return 0;
  656. }
  657. void
  658. PrintStatus(
  659. SECURITY_STATUS NetStatus
  660. )
  661. /*++
  662. Routine Description:
  663. Print a net status code.
  664. Arguments:
  665. NetStatus - The net status code to print.
  666. Return Value:
  667. None
  668. --*/
  669. {
  670. printf( "Status = 0x%lx",NetStatus );
  671. switch (NetStatus) {
  672. case ERROR_LOGON_FAILURE:
  673. printf( " ERROR_LOGON_FAILURE" );
  674. break;
  675. case ERROR_ACCESS_DENIED:
  676. printf( " ERROR_ACCESS_DENIED" );
  677. break;
  678. case ERROR_NOT_SUPPORTED:
  679. printf( " ERROR_NOT_SUPPORTED" );
  680. break;
  681. case ERROR_NO_LOGON_SERVERS:
  682. printf( " ERROR_NO_LOGON_SERVERS" );
  683. break;
  684. case ERROR_NO_SUCH_DOMAIN:
  685. printf( " ERROR_NO_SUCH_DOMAIN" );
  686. break;
  687. case ERROR_NO_TRUST_LSA_SECRET:
  688. printf( " ERROR_NO_TRUST_LSA_SECRET" );
  689. break;
  690. case ERROR_NO_TRUST_SAM_ACCOUNT:
  691. printf( " ERROR_NO_TRUST_SAM_ACCOUNT" );
  692. break;
  693. case ERROR_DOMAIN_TRUST_INCONSISTENT:
  694. printf( " ERROR_DOMAIN_TRUST_INCONSISTENT" );
  695. break;
  696. case ERROR_BAD_NETPATH:
  697. printf( " ERROR_BAD_NETPATH" );
  698. break;
  699. case ERROR_FILE_NOT_FOUND:
  700. printf( " ERROR_FILE_NOT_FOUND" );
  701. break;
  702. case SEC_E_NO_SPM:
  703. printf( " SEC_E_NO_SPM" );
  704. break;
  705. case SEC_E_BAD_PKGID:
  706. printf( " SEC_E_BAD_PKGID" ); break;
  707. case SEC_E_NOT_OWNER:
  708. printf( " SEC_E_NOT_OWNER" ); break;
  709. case SEC_E_CANNOT_INSTALL:
  710. printf( " SEC_E_CANNOT_INSTALL" ); break;
  711. case SEC_E_INVALID_TOKEN:
  712. printf( " SEC_E_INVALID_TOKEN" ); break;
  713. case SEC_E_CANNOT_PACK:
  714. printf( " SEC_E_CANNOT_PACK" ); break;
  715. case SEC_E_QOP_NOT_SUPPORTED:
  716. printf( " SEC_E_QOP_NOT_SUPPORTED" ); break;
  717. case SEC_E_NO_IMPERSONATION:
  718. printf( " SEC_E_NO_IMPERSONATION" ); break;
  719. case SEC_E_LOGON_DENIED:
  720. printf( " SEC_E_LOGON_DENIED" ); break;
  721. case SEC_E_UNKNOWN_CREDENTIALS:
  722. printf( " SEC_E_UNKNOWN_CREDENTIALS" ); break;
  723. case SEC_E_NO_CREDENTIALS:
  724. printf( " SEC_E_NO_CREDENTIALS" ); break;
  725. case SEC_E_MESSAGE_ALTERED:
  726. printf( " SEC_E_MESSAGE_ALTERED" ); break;
  727. case SEC_E_OUT_OF_SEQUENCE:
  728. printf( " SEC_E_OUT_OF_SEQUENCE" ); break;
  729. case SEC_E_INSUFFICIENT_MEMORY:
  730. printf( " SEC_E_INSUFFICIENT_MEMORY" ); break;
  731. case SEC_E_INVALID_HANDLE:
  732. printf( " SEC_E_INVALID_HANDLE" ); break;
  733. case SEC_E_NOT_SUPPORTED:
  734. printf( " SEC_E_NOT_SUPPORTED" ); break;
  735. case SEC_I_CONTINUE_NEEDED:
  736. printf( " SEC_I_CONTINUE_NEEDED" ); break;
  737. }
  738. printf( "\n" );
  739. }
  740. void
  741. PrintTime(
  742. LPSTR Comment,
  743. TimeStamp ConvertTime
  744. )
  745. /*++
  746. Routine Description:
  747. Print the specified time
  748. Arguments:
  749. Comment - Comment to print in front of the time
  750. Time - Local time to print
  751. Return Value:
  752. None
  753. --*/
  754. {
  755. LARGE_INTEGER LocalTime;
  756. NTSTATUS Status;
  757. LocalTime.HighPart = ConvertTime.HighPart;
  758. LocalTime.LowPart = ConvertTime.LowPart;
  759. Status = RtlSystemTimeToLocalTime( &ConvertTime, &LocalTime );
  760. if (!NT_SUCCESS( Status )) {
  761. printf( "Can't convert time from GMT to Local time\n" );
  762. LocalTime = ConvertTime;
  763. }
  764. printf( "%s", Comment );
  765. //
  766. // If the time is infinite,
  767. // just say so.
  768. //
  769. if ( LocalTime.HighPart == 0x7FFFFFFF && LocalTime.LowPart == 0xFFFFFFFF ) {
  770. printf( "Infinite\n" );
  771. //
  772. // Otherwise print it more clearly
  773. //
  774. } else {
  775. TIME_FIELDS TimeFields;
  776. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  777. printf( "%ld/%ld/%ld %ld:%2.2ld:%2.2ld\n",
  778. TimeFields.Month,
  779. TimeFields.Day,
  780. TimeFields.Year,
  781. TimeFields.Hour,
  782. TimeFields.Minute,
  783. TimeFields.Second );
  784. }
  785. }
  786. // Support Routines
  787. //+-------------------------------------------------------------------------
  788. //
  789. // Function: StringAllocate
  790. //
  791. // Synopsis: Allocates cb chars to STRING Buffer
  792. //
  793. // Arguments: pString - pointer to String to allocate memory to
  794. //
  795. // Returns: STATUS_SUCCESS - Normal completion
  796. //
  797. // Requires:
  798. //
  799. // Effects: allocates memory and sets STRING sizes
  800. //
  801. // Notes: Must call StringFree() to release memory
  802. //
  803. //--------------------------------------------------------------------------
  804. NTSTATUS
  805. StringAllocate(
  806. IN PSTRING pString,
  807. IN USHORT cb
  808. )
  809. {
  810. // DebugLog((DEB_TRACE, "NTDigest:Entering StringAllocate\n"));
  811. NTSTATUS Status = STATUS_SUCCESS;
  812. cb = cb + 1; // Add in extra room for the terminating NULL
  813. if (ARGUMENT_PRESENT(pString))
  814. {
  815. pString->Length = 0;
  816. pString->Buffer = (char *)DigestAllocateMemory((ULONG)(cb * sizeof(CHAR)));
  817. if (pString->Buffer)
  818. {
  819. pString->MaximumLength = cb;
  820. }
  821. else
  822. {
  823. pString->MaximumLength = 0;
  824. Status = STATUS_NO_MEMORY;
  825. goto CleanUp;
  826. }
  827. }
  828. else
  829. {
  830. Status = STATUS_INVALID_PARAMETER;
  831. goto CleanUp;
  832. }
  833. CleanUp:
  834. // DebugLog((DEB_TRACE, "NTDigest: Leaving StringAllocate\n"));
  835. return(Status);
  836. }
  837. //+-------------------------------------------------------------------------
  838. //
  839. // Function: StringFree
  840. //
  841. // Synopsis: Clears a String and releases the memory
  842. //
  843. // Arguments: pString - pointer to String to clear
  844. //
  845. // Returns: SEC_E_OK - released memory succeeded
  846. //
  847. // Requires:
  848. //
  849. // Effects: de-allocates memory with LsaFunctions.AllocateLsaHeap
  850. //
  851. // Notes:
  852. //
  853. //--------------------------------------------------------------------------
  854. NTSTATUS
  855. StringFree(
  856. IN PSTRING pString
  857. )
  858. {
  859. // DebugLog((DEB_TRACE, "NTDigest:Entering StringFree\n"));
  860. NTSTATUS Status = STATUS_SUCCESS;
  861. if (ARGUMENT_PRESENT(pString) &&
  862. (pString->Buffer != NULL))
  863. {
  864. DigestFreeMemory(pString->Buffer);
  865. pString->Length = 0;
  866. pString->MaximumLength = 0;
  867. pString->Buffer = NULL;
  868. }
  869. // DebugLog((DEB_TRACE, "NTDigest: Leaving StringFree\n"));
  870. return(Status);
  871. }
  872. //+-------------------------------------------------------------------------
  873. //
  874. // Function: StringCharDuplicate
  875. //
  876. // Synopsis: Duplicates a NULL terminated char. If the source string buffer is
  877. // NULL the destionation will be too.
  878. //
  879. // Arguments: Destination - Receives a copy of the source NULL Term char *
  880. // czSource - String to copy
  881. //
  882. // Returns: SEC_E_OK - the copy succeeded
  883. // SEC_E_INSUFFICIENT_MEMORY - the call to allocate
  884. // memory failed.
  885. //
  886. // Requires:
  887. //
  888. // Effects: allocates memory with LsaFunctions.AllocateLsaHeap
  889. //
  890. // Notes:
  891. //
  892. //
  893. //--------------------------------------------------------------------------
  894. NTSTATUS
  895. StringCharDuplicate(
  896. OUT PSTRING DestinationString,
  897. IN OPTIONAL char *czSource
  898. )
  899. {
  900. // DebugLog((DEB_TRACE, "NTDigest: Entering StringCharDuplicate\n"));
  901. NTSTATUS Status = STATUS_SUCCESS;
  902. USHORT cbSourceCz = 0;
  903. DestinationString->Buffer = NULL;
  904. DestinationString->Length = 0;
  905. DestinationString->MaximumLength = 0;
  906. if ((ARGUMENT_PRESENT(czSource)) &&
  907. ((cbSourceCz = strlen(czSource)) != 0))
  908. {
  909. DestinationString->Buffer = (LPSTR) DigestAllocateMemory(cbSourceCz + sizeof(CHAR));
  910. if (DestinationString->Buffer != NULL)
  911. {
  912. DestinationString->Length = cbSourceCz;
  913. DestinationString->MaximumLength = cbSourceCz + sizeof(CHAR);
  914. RtlCopyMemory(
  915. DestinationString->Buffer,
  916. czSource,
  917. cbSourceCz
  918. );
  919. DestinationString->Buffer[cbSourceCz/sizeof(CHAR)] = '\0';
  920. }
  921. else
  922. {
  923. Status = STATUS_NO_MEMORY;
  924. // DebugLog((DEB_ERROR, "NTDigest: StringCharDuplicate, DigestAllocateMemory returns NULL\n"));
  925. goto CleanUp;
  926. }
  927. }
  928. CleanUp:
  929. // DebugLog((DEB_TRACE, "NTDigest: Leaving StringCharDuplicate\n"));
  930. return(Status);
  931. }
  932. //+-------------------------------------------------------------------------
  933. //
  934. // Function: DigestAllocateMemory
  935. //
  936. // Synopsis: Allocate memory in either lsa mode or user mode
  937. //
  938. // Effects: Allocated chunk is zeroed out
  939. //
  940. // Arguments:
  941. //
  942. // Requires:
  943. //
  944. // Returns:
  945. //
  946. // Notes:
  947. //
  948. //
  949. //--------------------------------------------------------------------------
  950. PVOID
  951. DigestAllocateMemory(
  952. IN ULONG BufferSize
  953. )
  954. {
  955. PVOID Buffer = NULL;
  956. // DebugLog((DEB_TRACE, "Entering DigestAllocateMemory\n"));
  957. Buffer = LocalAlloc(LPTR, BufferSize);
  958. // DebugLog((DEB_TRACE, "Leaving DigestAllocateMemory\n"));
  959. return Buffer;
  960. }
  961. //+-------------------------------------------------------------------------
  962. //
  963. // Function: NtLmFree
  964. //
  965. // Synopsis: Free memory in either lsa mode or user mode
  966. //
  967. // Effects:
  968. //
  969. // Arguments:
  970. //
  971. // Requires:
  972. //
  973. // Returns:
  974. //
  975. // Notes:
  976. //
  977. //
  978. //--------------------------------------------------------------------------
  979. VOID
  980. DigestFreeMemory(
  981. IN PVOID Buffer
  982. )
  983. {
  984. // DebugLog((DEB_TRACE, "Entering DigestFreeMemory\n"));
  985. LocalFree(Buffer);
  986. // DebugLog((DEB_TRACE, "Leaving DigestFreeMemory\n"));
  987. }
  988. VOID
  989. BinToHex(
  990. LPBYTE pSrc,
  991. UINT cSrc,
  992. LPSTR pDst
  993. )
  994. {
  995. #define TOHEX(a) ((a)>=10 ? 'a'+(a)-10 : '0'+(a))
  996. for ( UINT x = 0, y = 0 ; x < cSrc ; ++x )
  997. {
  998. UINT v;
  999. v = pSrc[x]>>4;
  1000. pDst[y++] = TOHEX( v );
  1001. v = pSrc[x]&0x0f;
  1002. pDst[y++] = TOHEX( v );
  1003. }
  1004. pDst[y] = '\0';
  1005. }
  1006. VOID
  1007. ISCRETFlags( ULONG ulFlags)
  1008. {
  1009. printf("ISC Ret Flag (0x%x):", ulFlags);
  1010. if (ulFlags & ISC_RET_DELEGATE)
  1011. {
  1012. printf(" Delegate");
  1013. }
  1014. if (ulFlags & ISC_RET_MUTUAL_AUTH)
  1015. {
  1016. printf(" Mutual_Auth");
  1017. }
  1018. if (ulFlags & ISC_RET_REPLAY_DETECT)
  1019. {
  1020. printf(" Replay_Detect");
  1021. }
  1022. if (ulFlags & ISC_RET_SEQUENCE_DETECT)
  1023. {
  1024. printf(" Seq_Detect");
  1025. }
  1026. if (ulFlags & ISC_RET_CONFIDENTIALITY)
  1027. {
  1028. printf(" Confident");
  1029. }
  1030. if (ulFlags & ISC_RET_ALLOCATED_MEMORY)
  1031. {
  1032. printf(" Alloc_Mem");
  1033. }
  1034. if (ulFlags & ISC_RET_CONNECTION)
  1035. {
  1036. printf(" Connection");
  1037. }
  1038. if (ulFlags & ISC_RET_INTEGRITY)
  1039. {
  1040. printf(" Integrity");
  1041. }
  1042. printf("\n");
  1043. }
  1044. VOID
  1045. ASCRETFlags( ULONG ulFlags)
  1046. {
  1047. printf("ASC Ret Flag (0x%x):", ulFlags);
  1048. if (ulFlags & ASC_RET_DELEGATE)
  1049. {
  1050. printf(" Delegate");
  1051. }
  1052. if (ulFlags & ASC_RET_MUTUAL_AUTH)
  1053. {
  1054. printf(" Mutual_Auth");
  1055. }
  1056. if (ulFlags & ASC_RET_REPLAY_DETECT)
  1057. {
  1058. printf(" Replay_Detect");
  1059. }
  1060. if (ulFlags & ASC_RET_SEQUENCE_DETECT)
  1061. {
  1062. printf(" Seq_Detect");
  1063. }
  1064. if (ulFlags & ASC_RET_CONFIDENTIALITY)
  1065. {
  1066. printf(" Confident");
  1067. }
  1068. if (ulFlags & ASC_RET_ALLOCATED_MEMORY)
  1069. {
  1070. printf(" Alloc_Mem");
  1071. }
  1072. if (ulFlags & ASC_RET_CONNECTION)
  1073. {
  1074. printf(" Connection");
  1075. }
  1076. if (ulFlags & ASC_RET_INTEGRITY)
  1077. {
  1078. printf(" Integrity");
  1079. }
  1080. printf("\n");
  1081. }