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.

645 lines
22 KiB

  1. /////////////////////////////////////////////////////////////
  2. // Copyright(c) 1998, Microsoft Corporation
  3. //
  4. // print.cpp
  5. //
  6. // Created on 3/2/00 by DKalin
  7. // Revisions:
  8. //
  9. // Print routines for ipsecpol tool
  10. //
  11. /////////////////////////////////////////////////////////////
  12. #include "ipseccmd.h"
  13. #define PRINT _ftprintf
  14. #define OUTSTREAM stdout
  15. // comment this if you don't want debug spew
  16. //#define DEBUG
  17. // The following is to format the output so that understandable text can be printed
  18. // instead of DWORDs or ints
  19. TCHAR esp_algo[][25]= {_T("NONE"),
  20. _T("DES"),
  21. _T("Unknown"),
  22. _T("3DES"),
  23. _T("IPSEC_ESP_MAX")};
  24. TCHAR ah_algo[][25]= {_T("NONE"),
  25. _T("MD5"),
  26. _T("SHA1"),
  27. _T("IPSEC_AH_MAX")};
  28. TCHAR operation[][25]= {_T("None"),
  29. _T("Authentication"),
  30. _T("Encryption"),
  31. _T("Compression"),
  32. _T("SA Delete")};
  33. TCHAR oakley_states[][50]= {_T("MainMode No State"),
  34. _T("MainMode SA Setup"),
  35. _T("MainMode Key Exchange"),
  36. _T("MainMode Key Authorizated"),
  37. _T("AG Normal State"),
  38. _T("AG Init Exchange"),
  39. _T("AG Authorization"),
  40. _T("QuickMode SA Accept"),
  41. _T("QuickMode Awaiting Authorization"),
  42. _T("QuickMode Idle"),
  43. _T("QuickMode Waiting for Connection")
  44. };
  45. TCHAR oak_auth[][25]= {_T("Unknown"),
  46. _T("Preshared Key"),
  47. _T("DSS Signature"),
  48. _T("RSA (Cert) Signature"),
  49. _T("RSA (Cert) Encryption"),
  50. _T("Kerberos")
  51. };
  52. TCHAR if_types[][25]= {_T("Unknown"),
  53. _T("All"),
  54. _T("LAN"),
  55. _T("Dialup"),
  56. _T("All")
  57. };
  58. /////////////////////// UTILITY FUNCTIONS //////////////////////////
  59. // PrintQMOffer will print quick mode policy offer with given prefix string (actually two prefix strings)
  60. // Parms: IN qmOffer - IPSEC_QM_OFFER structure
  61. // IN pszPrefix - prefix string
  62. // IN pszPrefix2 - 2nd prefix string (will be added to 1st)
  63. // Returns: None
  64. void PrintQMOffer(IN IPSEC_QM_OFFER qmOffer, IN PTCHAR pszPrefix, IN PTCHAR pszPrefix2)
  65. {
  66. int i;
  67. #ifdef DEBUG
  68. printf("DEBUG - number of Algos for this offer is %d\n", qmOffer.dwNumAlgos);
  69. #endif
  70. for (i = 0; i < (int) qmOffer.dwNumAlgos; i++)
  71. {
  72. //print algo
  73. PRINT(OUTSTREAM,TEXT("%s%sAlgo #%d : "), pszPrefix, pszPrefix2, i+1);
  74. #ifdef DEBUG
  75. printf("DEBUG - operation code is %d\n", qmOffer.Algos[i].Operation);
  76. #endif
  77. PRINT(OUTSTREAM,TEXT("%s"), operation[qmOffer.Algos[i].Operation]);
  78. switch (qmOffer.Algos[i].Operation)
  79. {
  80. case ENCRYPTION:
  81. PRINT(OUTSTREAM,TEXT(" %s"), esp_algo[qmOffer.Algos[i].uAlgoIdentifier]);
  82. if (qmOffer.Algos[i].uSecAlgoIdentifier != HMAC_AH_NONE)
  83. {
  84. PRINT(OUTSTREAM,TEXT(" %s"), ah_algo[qmOffer.Algos[i].uSecAlgoIdentifier]);
  85. }
  86. if (qmOffer.Algos[i].uAlgoKeyLen != 0 || qmOffer.Algos[i].uAlgoRounds != 0)
  87. {
  88. PRINT(OUTSTREAM,TEXT(" (%lubytes/%lurounds)"), qmOffer.Algos[i].uAlgoKeyLen, qmOffer.Algos[i].uAlgoRounds);
  89. }
  90. break;
  91. case AUTHENTICATION:
  92. PRINT(OUTSTREAM,TEXT(" %s"), ah_algo[qmOffer.Algos[i].uAlgoIdentifier]);
  93. if (qmOffer.Algos[i].uAlgoKeyLen != 0 || qmOffer.Algos[i].uAlgoRounds != 0)
  94. {
  95. PRINT(OUTSTREAM,TEXT(" (%lubytes/%lurounds)"), qmOffer.Algos[i].uAlgoKeyLen, qmOffer.Algos[i].uAlgoRounds);
  96. }
  97. break;
  98. case NONE:
  99. case COMPRESSION:
  100. case SA_DELETE:
  101. default:
  102. break;
  103. }
  104. if (qmOffer.Algos[i].MySpi != 0 || qmOffer.Algos[i].PeerSpi != 0)
  105. {
  106. PRINT(OUTSTREAM,TEXT("\n%s%s\t "), pszPrefix, pszPrefix2);
  107. }
  108. if (qmOffer.Algos[i].MySpi != 0)
  109. {
  110. PRINT(OUTSTREAM,TEXT(" MySpi %lu"), qmOffer.Algos[i].MySpi);
  111. }
  112. if (qmOffer.Algos[i].PeerSpi != 0)
  113. {
  114. PRINT(OUTSTREAM,TEXT(" PeerSpi %lu"), qmOffer.Algos[i].PeerSpi);
  115. }
  116. PRINT(OUTSTREAM,TEXT("\n"));
  117. }
  118. PRINT(OUTSTREAM,TEXT("%s%sPFS : %s"), pszPrefix, pszPrefix2, qmOffer.bPFSRequired ? _T("True") : _T("False"));
  119. if (qmOffer.bPFSRequired)
  120. {
  121. PRINT(OUTSTREAM,TEXT(" (Group %lu)"), qmOffer.dwPFSGroup);
  122. }
  123. PRINT(OUTSTREAM,TEXT(", Lifetime %luKbytes/%luseconds\n"), qmOffer.Lifetime.uKeyExpirationKBytes, qmOffer.Lifetime.uKeyExpirationTime);
  124. if (qmOffer.dwFlags != 0)
  125. {
  126. PRINT(OUTSTREAM,TEXT("%s%sFlags : %lu\n"), pszPrefix, pszPrefix2, qmOffer.dwFlags);
  127. }
  128. } // end of PrintQMOffer
  129. // PrintFilterAction will print filter action info with given prefix string
  130. // Parms: IN qmPolicy - QM policy (aka filter action) information
  131. // IN pszPrefix - prefix string
  132. // Returns: None
  133. void PrintFilterAction(IN IPSEC_QM_POLICY qmPolicy, IN PTCHAR pszPrefix)
  134. {
  135. TCHAR* StringTxt = new TCHAR[STRING_TEXT_SIZE];
  136. int i;
  137. // continue here
  138. // dump all data
  139. PRINT(OUTSTREAM,TEXT("%sName : %s\n"), pszPrefix, qmPolicy.pszPolicyName );
  140. StringFromGUID2(qmPolicy.gPolicyID, StringTxt, STRING_TEXT_SIZE);
  141. PRINT(OUTSTREAM,TEXT("%sPolicy Id : %s\n"), pszPrefix, StringTxt);
  142. PRINT(OUTSTREAM,TEXT("%sFlags : %lu %s %s %s\n"), pszPrefix, qmPolicy.dwFlags,
  143. (qmPolicy.dwFlags & IPSEC_QM_POLICY_TUNNEL_MODE) ? _T("(Tunnel)") : _T(""),
  144. (qmPolicy.dwFlags & IPSEC_QM_POLICY_DEFAULT_POLICY) ? _T("(Default)") : _T(""),
  145. (qmPolicy.dwFlags & IPSEC_QM_POLICY_ALLOW_SOFT) ? _T("(Allow Soft)") : _T(""));
  146. for (i = 0; i < (int) qmPolicy.dwOfferCount; i++)
  147. {
  148. PRINT(OUTSTREAM,TEXT("%sOffer #%d\n"), pszPrefix, i+1);
  149. PrintQMOffer(qmPolicy.pOffers[i], pszPrefix, TEXT("\t"));
  150. }
  151. } // end of PrintFilterAction
  152. // PrintFilter will print [transport] filter info with (optional) filter action info embedded
  153. // Parms: IN tFilter - filter information (TRANSPORT_FILTER structure)
  154. // IN bPrintNegPol - should we print the filter action info
  155. // IN bPrintSpecific - should we print specific filter information
  156. // Returns: FALSE if error occured while retrieving filter action info
  157. // TRUE if everything is OK
  158. BOOL PrintFilter (IN TRANSPORT_FILTER tFilter, IN BOOL bPrintNegPol, IN BOOL bPrintSpecific)
  159. {
  160. int i;
  161. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  162. DWORD hr;
  163. PRINT(OUTSTREAM,TEXT(" Name : %s\n"),tFilter.pszFilterName );
  164. StringFromGUID2(tFilter.gFilterID, StringTxt, STRING_TEXT_SIZE);
  165. PRINT(OUTSTREAM,TEXT(" Filter Id : %s\n"),StringTxt);
  166. StringFromGUID2(tFilter.gPolicyID, StringTxt, STRING_TEXT_SIZE);
  167. PRINT(OUTSTREAM,TEXT(" Policy Id : %s\n"),StringTxt);
  168. if (bPrintNegPol && (tFilter.InboundFilterFlag == NEGOTIATE_SECURITY || tFilter.OutboundFilterFlag == NEGOTIATE_SECURITY) )
  169. {
  170. // printing negpol only if we have actual negpol
  171. // need additional check for specific filter
  172. if (!bPrintSpecific ||
  173. (tFilter.dwDirection == FILTER_DIRECTION_INBOUND && tFilter.InboundFilterFlag == NEGOTIATE_SECURITY) ||
  174. (tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND && tFilter.OutboundFilterFlag == NEGOTIATE_SECURITY))
  175. {
  176. // get qm policy and print it, right here
  177. PIPSEC_QM_POLICY pipsqmp;
  178. if ((hr = GetQMPolicyByID(szServ, tFilter.gPolicyID, &pipsqmp)) != ERROR_SUCCESS)
  179. {
  180. // PRINT(OUTSTREAM,TEXT("GetQMPolicyByID failed with error %d\n"), hr);
  181. return FALSE;
  182. }
  183. PrintFilterAction(pipsqmp[0], TEXT("\t"));
  184. SPDApiBufferFree(pipsqmp);
  185. }
  186. }
  187. PRINT(OUTSTREAM,TEXT(" Src Addr : "));
  188. PrintAddr(tFilter.SrcAddr);
  189. PRINT(OUTSTREAM,TEXT("\n"));
  190. PRINT(OUTSTREAM,TEXT(" Des Addr : "));
  191. PrintAddr(tFilter.DesAddr);
  192. PRINT(OUTSTREAM,TEXT("\n"));
  193. PRINT(OUTSTREAM,TEXT(" Protocol : %lu Src Port : %u Des Port : %u\n"), tFilter.Protocol.dwProtocol, tFilter.SrcPort.wPort, tFilter.DesPort.wPort);
  194. if (!bPrintSpecific || tFilter.dwDirection == FILTER_DIRECTION_INBOUND)
  195. {
  196. if (tFilter.InboundFilterFlag == PASS_THRU)
  197. PRINT(OUTSTREAM,TEXT(" Inbound Passthru\n"));
  198. if (tFilter.InboundFilterFlag == BLOCKING)
  199. PRINT(OUTSTREAM,TEXT(" Inbound Block\n"));
  200. }
  201. if (!bPrintSpecific || tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND)
  202. {
  203. if (tFilter.OutboundFilterFlag == PASS_THRU)
  204. PRINT(OUTSTREAM,TEXT(" Outbound Passthru\n"));
  205. if (tFilter.OutboundFilterFlag == BLOCKING)
  206. PRINT(OUTSTREAM,TEXT(" Outbound Block\n"));
  207. }
  208. if (bPrintSpecific)
  209. {
  210. PRINT(OUTSTREAM,TEXT(" Direction : %s, Weight : %lu\n"),
  211. (tFilter.dwDirection == FILTER_DIRECTION_INBOUND) ? _T("Inbound") : ((tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND) ? _T("Outbound") : _T("Error")),
  212. tFilter.dwWeight);
  213. }
  214. else
  215. {
  216. PRINT(OUTSTREAM,TEXT(" Mirrored : %s\n"), tFilter.bCreateMirror ? _T("True") : _T("False"));
  217. }
  218. PRINT(OUTSTREAM,TEXT(" Interface Type : %s\n"), if_types[tFilter.InterfaceType]);
  219. return TRUE;
  220. } // end of PrintFilter
  221. // PrintTunnelFilter will print tunnel filter info with (optional) filter action info embedded
  222. // Parms: IN tFilter - filter information (TUNNEL_FILTER structure)
  223. // IN bPrintNegPol - should we print the filter action info
  224. // IN bPrintSpecific - should we print specific filter information
  225. // Returns: FALSE if error occured while retrieving filter action info
  226. // TRUE if everything is OK
  227. BOOL PrintTunnelFilter (IN TUNNEL_FILTER tFilter, IN BOOL bPrintNegPol, IN BOOL bPrintSpecific)
  228. {
  229. int i;
  230. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  231. DWORD hr;
  232. PRINT(OUTSTREAM,TEXT(" Name : %s\n"),tFilter.pszFilterName );
  233. StringFromGUID2(tFilter.gFilterID, StringTxt, STRING_TEXT_SIZE);
  234. PRINT(OUTSTREAM,TEXT(" Filter Id : %s\n"),StringTxt);
  235. StringFromGUID2(tFilter.gPolicyID, StringTxt, STRING_TEXT_SIZE);
  236. PRINT(OUTSTREAM,TEXT(" Policy Id : %s\n"),StringTxt);
  237. if (bPrintNegPol && (tFilter.InboundFilterFlag == NEGOTIATE_SECURITY || tFilter.OutboundFilterFlag == NEGOTIATE_SECURITY) )
  238. {
  239. // printing negpol only if we have actual negpol
  240. // need additional check for specific filter
  241. if (!bPrintSpecific ||
  242. (tFilter.dwDirection == FILTER_DIRECTION_INBOUND && tFilter.InboundFilterFlag == NEGOTIATE_SECURITY) ||
  243. (tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND && tFilter.OutboundFilterFlag == NEGOTIATE_SECURITY))
  244. {
  245. // get qm policy and print it, right here
  246. PIPSEC_QM_POLICY pipsqmp;
  247. if ((hr = GetQMPolicyByID(szServ, tFilter.gPolicyID, &pipsqmp)) != ERROR_SUCCESS)
  248. {
  249. // PRINT(OUTSTREAM,TEXT("GetQMPolicyByID failed with error %d\n"), hr);
  250. return FALSE;
  251. }
  252. PrintFilterAction(pipsqmp[0], TEXT("\t"));
  253. SPDApiBufferFree(pipsqmp);
  254. }
  255. }
  256. PRINT(OUTSTREAM,TEXT(" Src Addr : "));
  257. PrintAddr(tFilter.SrcAddr);
  258. PRINT(OUTSTREAM,TEXT("\n"));
  259. PRINT(OUTSTREAM,TEXT(" Des Addr : "));
  260. PrintAddr(tFilter.DesAddr);
  261. PRINT(OUTSTREAM,TEXT("\n"));
  262. PRINT(OUTSTREAM,TEXT(" Src Tunnel Addr : "));
  263. PrintAddr(tFilter.SrcTunnelAddr);
  264. PRINT(OUTSTREAM,TEXT("\n"));
  265. PRINT(OUTSTREAM,TEXT(" Des Tunnel Addr : "));
  266. PrintAddr(tFilter.DesTunnelAddr);
  267. PRINT(OUTSTREAM,TEXT("\n"));
  268. PRINT(OUTSTREAM,TEXT(" Protocol : %lu Src Port : %u Des Port : %u\n"), tFilter.Protocol.dwProtocol, tFilter.SrcPort.wPort, tFilter.DesPort.wPort);
  269. if (!bPrintSpecific || tFilter.dwDirection == FILTER_DIRECTION_INBOUND)
  270. {
  271. if (tFilter.InboundFilterFlag == PASS_THRU)
  272. PRINT(OUTSTREAM,TEXT(" Inbound Passthru\n"));
  273. if (tFilter.InboundFilterFlag == BLOCKING)
  274. PRINT(OUTSTREAM,TEXT(" Inbound Block\n"));
  275. }
  276. if (!bPrintSpecific || tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND)
  277. {
  278. if (tFilter.OutboundFilterFlag == PASS_THRU)
  279. PRINT(OUTSTREAM,TEXT(" Outbound Passthru\n"));
  280. if (tFilter.OutboundFilterFlag == BLOCKING)
  281. PRINT(OUTSTREAM,TEXT(" Outbound Block\n"));
  282. }
  283. if (bPrintSpecific)
  284. {
  285. PRINT(OUTSTREAM,TEXT(" Direction : %s, Weight : %lu\n"),
  286. (tFilter.dwDirection == FILTER_DIRECTION_INBOUND) ? _T("Inbound") : ((tFilter.dwDirection == FILTER_DIRECTION_OUTBOUND) ? _T("Outbound") : _T("Error")),
  287. tFilter.dwWeight);
  288. }
  289. else
  290. {
  291. PRINT(OUTSTREAM,TEXT(" Mirrored : %s\n"), tFilter.bCreateMirror ? _T("True") : _T("False"));
  292. }
  293. PRINT(OUTSTREAM,TEXT(" Interface Type : %s\n"), if_types[tFilter.InterfaceType]);
  294. return TRUE;
  295. } // end of PrintFilter
  296. // PrintMMFilter will print mainmode filter info with (optional) mmpolicy info embedded
  297. // Parms: IN mmFilter - Mainmode filter
  298. // IN bPrintNegPol - should we print the mmpolicy info
  299. // IN bPrintSpecific - should we print specific filter info
  300. // Returns: FALSE if any error, TRUE if OK
  301. BOOL PrintMMFilter (IN MM_FILTER mmFilter, IN BOOL bPrintNegPol, IN BOOL bPrintSpecific)
  302. {
  303. int i;
  304. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  305. DWORD hr;
  306. PRINT(OUTSTREAM,TEXT(" Name : %s\n"),mmFilter.pszFilterName );
  307. StringFromGUID2(mmFilter.gFilterID, StringTxt, STRING_TEXT_SIZE);
  308. PRINT(OUTSTREAM,TEXT(" Filter Id : %s\n"),StringTxt);
  309. StringFromGUID2(mmFilter.gPolicyID, StringTxt, STRING_TEXT_SIZE);
  310. PRINT(OUTSTREAM,TEXT(" Policy Id : %s\n"),StringTxt);
  311. if (bPrintNegPol)
  312. {
  313. // get mm policy and print it, right here
  314. PIPSEC_MM_POLICY pipsmmp;
  315. if ((hr = GetMMPolicyByID(szServ, mmFilter.gPolicyID, &pipsmmp)) != ERROR_SUCCESS)
  316. {
  317. // PRINT(OUTSTREAM,TEXT("GetMMPolicyByID failed with error %d\n"), hr);
  318. return FALSE;
  319. }
  320. PrintMMPolicy(pipsmmp[0], TEXT("\t"));
  321. SPDApiBufferFree(pipsmmp);
  322. }
  323. PRINT(OUTSTREAM,TEXT(" Src Addr : "));
  324. PrintAddr(mmFilter.SrcAddr);
  325. PRINT(OUTSTREAM,TEXT("\n"));
  326. PRINT(OUTSTREAM,TEXT(" Des Addr : "));
  327. PrintAddr(mmFilter.DesAddr);
  328. PRINT(OUTSTREAM,TEXT("\n"));
  329. if (bPrintSpecific)
  330. {
  331. PRINT(OUTSTREAM,TEXT(" Direction : %s, Weight : %lu\n"),
  332. (mmFilter.dwDirection == FILTER_DIRECTION_INBOUND) ? _T("Inbound") : ((mmFilter.dwDirection == FILTER_DIRECTION_OUTBOUND) ? _T("Outbound") : _T("Error")),
  333. mmFilter.dwWeight);
  334. }
  335. else
  336. {
  337. PRINT(OUTSTREAM,TEXT(" Mirrored : %s\n"), mmFilter.bCreateMirror ? _T("True") : _T("False"));
  338. }
  339. PRINT(OUTSTREAM,TEXT(" Interface Type : %s\n"), if_types[mmFilter.InterfaceType]);
  340. StringFromGUID2(mmFilter.gMMAuthID, StringTxt, STRING_TEXT_SIZE);
  341. PRINT(OUTSTREAM,TEXT(" Auth Methods Id: %s\n"),StringTxt);
  342. if (bPrintNegPol)
  343. {
  344. //print auth methods as well
  345. PMM_AUTH_METHODS pmmam;
  346. if ((hr = GetMMAuthMethods(szServ, mmFilter.gMMAuthID, &pmmam)) != ERROR_SUCCESS)
  347. {
  348. // PRINT(OUTSTREAM,TEXT("GetMMAuthMethods failed with error %d\n"), hr);
  349. return FALSE;
  350. }
  351. for (i = 0; i < (int) pmmam[0].dwNumAuthInfos; i++)
  352. {
  353. PRINT(OUTSTREAM,TEXT("\tAM #%d : "), i+1);
  354. PrintAuthInfo(pmmam[0].pAuthenticationInfo[i]);
  355. PRINT(OUTSTREAM,TEXT("\n"));
  356. }
  357. SPDApiBufferFree(pmmam);
  358. }
  359. return TRUE;
  360. } // end of PrintMMFilter
  361. // PrintMMAuthMethods will print main mode authentication methods information with given prefix string
  362. // Parms: IN mmAuth - MM_AUTH_METHODS structure
  363. // IN pszPrefix - prefix string
  364. // Returns: None
  365. void PrintMMAuthMethods(IN MM_AUTH_METHODS mmAuth, IN PTCHAR pszPrefix)
  366. {
  367. int i;
  368. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  369. DWORD hr;
  370. StringFromGUID2(mmAuth.gMMAuthID, StringTxt, STRING_TEXT_SIZE);
  371. PRINT(OUTSTREAM,TEXT("%sAuth Methods Id: %s\n"), pszPrefix, StringTxt);
  372. for (i = 0; i < (int) mmAuth.dwNumAuthInfos; i++)
  373. {
  374. PRINT(OUTSTREAM,TEXT("%s\tAM #%d : "), pszPrefix, i+1);
  375. PrintAuthInfo(mmAuth.pAuthenticationInfo[i]);
  376. PRINT(OUTSTREAM,TEXT("\n"));
  377. }
  378. }
  379. // PrintMMPolicy will print main mode policy information with given prefix string
  380. // Parms: IN mmPolicy - IPSEC_MM_POLICY structure
  381. // IN pszPrefix - prefix string
  382. // Returns: None
  383. void PrintMMPolicy(IN IPSEC_MM_POLICY mmPolicy, IN PTCHAR pszPrefix)
  384. {
  385. int i;
  386. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  387. PRINT(OUTSTREAM,TEXT("%sName : %s\n"), pszPrefix, mmPolicy.pszPolicyName );
  388. StringFromGUID2(mmPolicy.gPolicyID, StringTxt, STRING_TEXT_SIZE);
  389. PRINT(OUTSTREAM,TEXT("%sPolicy Id : %s\n"), pszPrefix, StringTxt);
  390. PRINT(OUTSTREAM,TEXT("%sFlags : %lu %s %s\n"), pszPrefix, mmPolicy.dwFlags,
  391. (mmPolicy.dwFlags & IPSEC_MM_POLICY_DEFAULT_POLICY) ? _T("(Default)") : _T(""),
  392. (mmPolicy.dwFlags & IPSEC_MM_POLICY_ENABLE_DIAGNOSTICS) ? _T("(Enable Diag)") : _T(""));
  393. if (mmPolicy.uSoftSAExpirationTime != 0)
  394. {
  395. PRINT(OUTSTREAM,TEXT("%sSoft SA expiration time : %lu\n"), pszPrefix, mmPolicy.uSoftSAExpirationTime);
  396. }
  397. for (i = 0; i < (int) mmPolicy.dwOfferCount; i++)
  398. {
  399. PRINT(OUTSTREAM,TEXT("%sOffer #%d\n"), pszPrefix, i+1);
  400. PrintMMOffer(mmPolicy.pOffers[i], pszPrefix, TEXT("\t"));
  401. }
  402. } // end of PrintMMPolicy
  403. // PrintMMOffer will print main mode policy offer with given prefix string (actually two prefix strings)
  404. // Parms: IN mmOffer - IPSEC_MM_OFFER structure
  405. // IN pszPrefix - prefix string
  406. // IN pszPrefix2 - 2nd prefix string (will be added to 1st)
  407. // Returns: None
  408. void PrintMMOffer(IN IPSEC_MM_OFFER mmOffer, IN PTCHAR pszPrefix, IN PTCHAR pszPrefix2)
  409. {
  410. PRINT(OUTSTREAM,TEXT("%s%s%s"), pszPrefix, pszPrefix2, esp_algo[mmOffer.EncryptionAlgorithm.uAlgoIdentifier]);
  411. if (mmOffer.EncryptionAlgorithm.uAlgoKeyLen != 0 || mmOffer.EncryptionAlgorithm.uAlgoRounds != 0)
  412. {
  413. PRINT(OUTSTREAM,TEXT("(%lubytes/%lurounds)"), mmOffer.EncryptionAlgorithm.uAlgoKeyLen, mmOffer.EncryptionAlgorithm.uAlgoRounds);
  414. }
  415. PRINT(OUTSTREAM,TEXT(" %s"), ah_algo[mmOffer.HashingAlgorithm.uAlgoIdentifier]);
  416. if (mmOffer.HashingAlgorithm.uAlgoKeyLen != 0 || mmOffer.HashingAlgorithm.uAlgoRounds != 0)
  417. {
  418. PRINT(OUTSTREAM,TEXT("(%lubytes/%lurounds)"), mmOffer.HashingAlgorithm.uAlgoKeyLen, mmOffer.HashingAlgorithm.uAlgoRounds);
  419. }
  420. PRINT(OUTSTREAM,TEXT(" DH Group %lu\n"), mmOffer.dwDHGroup);
  421. PRINT(OUTSTREAM,TEXT("%s%sQuickmode limit : %lu, Lifetime %luKbytes/%luseconds\n"), pszPrefix, pszPrefix2, mmOffer.dwQuickModeLimit,
  422. mmOffer.Lifetime.uKeyExpirationKBytes, mmOffer.Lifetime.uKeyExpirationTime);
  423. if (mmOffer.dwFlags != 0)
  424. {
  425. PRINT(OUTSTREAM,TEXT("%s%sFlags : %lu\n"), pszPrefix, pszPrefix2, mmOffer.dwFlags);
  426. }
  427. } // end of PrintMMOffer
  428. // PrintAddr will print ADDR structure (address used in SPD)
  429. // Parms: IN addr - ADDR structure
  430. // Returns: None
  431. void PrintAddr(IN ADDR addr)
  432. {
  433. struct in_addr inAddr;
  434. TCHAR * StringTxt = new TCHAR[STRING_TEXT_SIZE];
  435. if (addr.AddrType == IP_ADDR_UNIQUE && addr.uIpAddr == IP_ADDRESS_ME)
  436. {
  437. PRINT(OUTSTREAM,TEXT("Me"));
  438. }
  439. else if (addr.AddrType == IP_ADDR_SUBNET && addr.uIpAddr == SUBNET_ADDRESS_ANY && addr.uSubNetMask == SUBNET_MASK_ANY)
  440. {
  441. PRINT(OUTSTREAM,TEXT("Any"));
  442. }
  443. else if (addr.AddrType == IP_ADDR_UNIQUE)
  444. {
  445. inAddr.s_addr = addr.uIpAddr;
  446. PRINT(OUTSTREAM,TEXT("%S"), inet_ntoa(inAddr)) ;
  447. }
  448. else if (addr.AddrType == IP_ADDR_SUBNET)
  449. {
  450. inAddr.s_addr = addr.uIpAddr;
  451. PRINT(OUTSTREAM,TEXT("subnet %S "), inet_ntoa(inAddr)) ;
  452. inAddr.s_addr = addr.uSubNetMask;
  453. PRINT(OUTSTREAM,TEXT("mask %S"), inet_ntoa(inAddr)) ;
  454. }
  455. else if (addr.AddrType == IP_ADDR_INTERFACE)
  456. {
  457. StringFromGUID2(addr.gInterfaceID, StringTxt, STRING_TEXT_SIZE);
  458. PRINT(OUTSTREAM,TEXT("interface id %s "), StringTxt);
  459. if (addr.uIpAddr != IP_ADDRESS_ME)
  460. {
  461. inAddr.s_addr = addr.uIpAddr;
  462. PRINT(OUTSTREAM,TEXT("IP Addr %S "), inet_ntoa(inAddr)) ;
  463. }
  464. }
  465. } // end of PrintAddr
  466. // PrintAuthInfo will print authentication method information
  467. // Parms: IN authInfo - IPSEC_MM_AUTH_INFO structure
  468. // Returns: None
  469. void PrintAuthInfo(IN IPSEC_MM_AUTH_INFO authInfo)
  470. {
  471. int i;
  472. DWORD dwReturn;
  473. WCHAR *pszCertStr, *pTmp;
  474. PRINT(OUTSTREAM,TEXT("%s"), oak_auth[authInfo.AuthMethod]);
  475. if (authInfo.AuthMethod == IKE_PRESHARED_KEY)
  476. {
  477. // print preshared key
  478. PRINT(OUTSTREAM,TEXT(" : \""));
  479. for (i = 0; i < (int) (authInfo.dwAuthInfoSize/sizeof(TCHAR)); i++)
  480. {
  481. PRINT(OUTSTREAM,TEXT("%c"), *(((TCHAR*)authInfo.pAuthInfo)+i));
  482. }
  483. PRINT(OUTSTREAM,TEXT("\""));
  484. }
  485. else if (authInfo.AuthMethod == IKE_RSA_SIGNATURE || authInfo.AuthMethod == IKE_RSA_ENCRYPTION)
  486. {
  487. // convert and print cert
  488. PRINT(OUTSTREAM,TEXT(" : \""));
  489. dwReturn = CM_DecodeName(authInfo.pAuthInfo, authInfo.dwAuthInfoSize, &pszCertStr);
  490. if (dwReturn != ERROR_SUCCESS)
  491. {
  492. PRINT(OUTSTREAM,TEXT("Unknown"));
  493. }
  494. else
  495. {
  496. for (pTmp = pszCertStr; *pTmp; pTmp++)
  497. {
  498. PRINT(OUTSTREAM,TEXT("%c"), *pTmp);
  499. }
  500. delete [] pszCertStr;
  501. }
  502. PRINT(OUTSTREAM,TEXT("\""));
  503. }
  504. } // end of PrintAuthInfo
  505. void PrintPolicies(IN IPSEC_IKE_POLICY& IPSecIkePol)
  506. {
  507. int i;
  508. IPSEC_IKE_POLICY TmpPol; // for checks
  509. TCHAR szPrefix[] = TEXT(" ");
  510. // set TmpPol to 0's
  511. memset(&TmpPol, 0, sizeof(TmpPol));
  512. PRINT(OUTSTREAM,TEXT("==========================\n"));
  513. if (IPSecIkePol.dwNumMMFilters != 0)
  514. {
  515. for (i = 0; i < (int) IPSecIkePol.dwNumMMFilters; ++i)
  516. {
  517. PRINT(OUTSTREAM,TEXT("MM Filter %d\n"),i);
  518. PrintMMFilter(IPSecIkePol.pMMFilters[i], FALSE, FALSE);
  519. PRINT(OUTSTREAM,TEXT("==========================\n"));
  520. }
  521. }
  522. if (IPSecIkePol.dwNumFilters != 0)
  523. {
  524. for (i = 0; i < (int) IPSecIkePol.dwNumFilters; ++i)
  525. {
  526. PRINT(OUTSTREAM,TEXT("Filter %d\n"),i);
  527. if (IPSecIkePol.QMFilterType == QM_TRANSPORT_FILTER)
  528. {
  529. PrintFilter(IPSecIkePol.pTransportFilters[i], FALSE, FALSE);
  530. }
  531. else
  532. {
  533. // tunnel
  534. PrintTunnelFilter(IPSecIkePol.pTunnelFilters[i], FALSE, FALSE);
  535. }
  536. PRINT(OUTSTREAM,TEXT("==========================\n"));
  537. }
  538. }
  539. PRINT(OUTSTREAM,TEXT("Oakley Auth: \n"));
  540. for (i = 0; i < (int) IPSecIkePol.AuthInfos.dwNumAuthInfos; i++)
  541. {
  542. PRINT(OUTSTREAM,TEXT("\tAM #%d : "), i+1);
  543. PrintAuthInfo(IPSecIkePol.AuthInfos.pAuthenticationInfo[i]);
  544. PRINT(OUTSTREAM,TEXT("\n"));
  545. }
  546. PRINT(OUTSTREAM,TEXT("==========================\n"));
  547. // continue here
  548. // mm policy
  549. if (memcmp(&IPSecIkePol.IkePol, &TmpPol.IkePol, sizeof(TmpPol.IkePol)) != 0)
  550. {
  551. PRINT(OUTSTREAM,TEXT("MM Policy: \n"));
  552. PrintMMPolicy(IPSecIkePol.IkePol, szPrefix);
  553. }
  554. PRINT(OUTSTREAM,TEXT("==========================\n"));
  555. // qm policy
  556. if (memcmp(&IPSecIkePol.IpsPol, &TmpPol.IpsPol, sizeof(TmpPol.IpsPol)) != 0)
  557. {
  558. PRINT(OUTSTREAM,TEXT("QM Policy: \n"));
  559. PrintFilterAction(IPSecIkePol.IpsPol, szPrefix);
  560. }
  561. }