]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Update Ipsecconfig Application to print the keys of SAD in concise way.
authorqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 5 Jan 2011 09:41:57 +0000 (09:41 +0000)
committerqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 5 Jan 2011 09:41:57 +0000 (09:41 +0000)
If the SAD is set manually, print its keys in Ascci string format.
If the SAD is created by IKE, print its keys in Hex format.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11226 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/Application/IpsecConfig/Dump.c
NetworkPkg/Application/IpsecConfig/Match.c

index f467f94afb68145e304365202f1df15f962dc3fc..72d3bc5955be2eefbff1e2f22e7476175bf0e67e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of dump policy entry function in IpSecConfig application.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -70,9 +70,30 @@ DumpAsciiString (
   )\r
 {\r
   UINTN    Index;\r
+  Print (L"\"");\r
   for (Index = 0; Index < Length; Index++) {\r
     Print (L"%c", (CHAR16) Str[Index]);\r
   }\r
+  Print (L"\"");\r
+}\r
+\r
+/**\r
+  Private function called to print a buffer in Hex format.\r
+\r
+  @param[in] Data      The pointer to the buffer.\r
+  @param[in] Length    The size of the buffer.\r
+\r
+**/\r
+VOID\r
+DumpBuf (\r
+  IN UINT8    *Data,\r
+  IN UINTN    Length\r
+  )\r
+{\r
+  UINTN    Index;\r
+  for (Index = 0; Index < Length; Index++) {\r
+    Print (L"%02x ", Data[Index]); \r
+  }\r
 }\r
 \r
 /**\r
@@ -365,13 +386,9 @@ DumpSadEntry (
   BOOLEAN    HasPre;\r
   CHAR16     *AuthAlgoStr;\r
   CHAR16     *EncAlgoStr;\r
-  CHAR8      *AuthKeyAsciiStr;\r
-  CHAR8      *EncKeyAsciiStr;\r
 \r
   AuthAlgoStr      = NULL;\r
   EncAlgoStr       = NULL;\r
-  AuthKeyAsciiStr  = NULL;\r
-  EncKeyAsciiStr   = NULL;\r
 \r
   //\r
   // SPI:1234 ESP Destination:xxx.xxx.xxx.xxx\r
@@ -386,7 +403,7 @@ DumpSadEntry (
     Print (L"TunnelSourceAddress:");\r
     DumpIpAddress (&Data->TunnelSourceAddress);\r
     Print (L"\n");\r
-    Print (L"TunnelDestination:");\r
+    Print (L"  TunnelDestination:");\r
     DumpIpAddress (&Data->TunnelDestinationAddress);\r
     Print (L"\n");\r
   }\r
@@ -433,30 +450,35 @@ DumpSadEntry (
     AuthAlgoStr = MapIntegerToString (Data->AlgoInfo.EspAlgoInfo.AuthAlgoId, mMapAuthAlgo);\r
     EncAlgoStr  = MapIntegerToString (Data->AlgoInfo.EspAlgoInfo.EncAlgoId, mMapEncAlgo);\r
 \r
-    AuthKeyAsciiStr    = AllocateZeroPool (Data->AlgoInfo.EspAlgoInfo.AuthKeyLength + 1);\r
-    ASSERT (AuthKeyAsciiStr != NULL);\r
-    CopyMem (AuthKeyAsciiStr, Data->AlgoInfo.EspAlgoInfo.AuthKey, Data->AlgoInfo.EspAlgoInfo.AuthKeyLength);\r
-    AuthKeyAsciiStr[Data->AlgoInfo.EspAlgoInfo.AuthKeyLength] = '\0';\r
-\r
-    EncKeyAsciiStr  = AllocateZeroPool (Data->AlgoInfo.EspAlgoInfo.EncKeyLength + 1);\r
-    ASSERT (EncKeyAsciiStr != NULL) ;\r
-    CopyMem (EncKeyAsciiStr, Data->AlgoInfo.EspAlgoInfo.EncKey, Data->AlgoInfo.EspAlgoInfo.EncKeyLength);\r
-    EncKeyAsciiStr[Data->AlgoInfo.EspAlgoInfo.EncKeyLength] = '\0';\r
-\r
-    Print (\r
-      L"  Auth:%s/%a Encrypt:%s/%a\n",\r
-      AuthAlgoStr,      \r
-      AuthKeyAsciiStr,\r
-      EncAlgoStr,\r
-      EncKeyAsciiStr\r
-      );\r
\r
-    FreePool (AuthKeyAsciiStr);\r
-    FreePool (EncKeyAsciiStr);\r
+    if (Data->ManualSet) {\r
+      //\r
+      // if the SAD is set manually the key is a Ascii string in most of time.\r
+      // Print the Key in Ascii string format.\r
+      //\r
+      Print (L"  Auth:%s/",AuthAlgoStr);\r
+      DumpAsciiString (\r
+        Data->AlgoInfo.EspAlgoInfo.AuthKey, \r
+        Data->AlgoInfo.EspAlgoInfo.AuthKeyLength\r
+        );\r
+      Print (L"\n  Encrypt:%s/",EncAlgoStr);\r
+      DumpAsciiString (\r
+        Data->AlgoInfo.EspAlgoInfo.EncKey, \r
+        Data->AlgoInfo.EspAlgoInfo.EncKeyLength\r
+        );\r
+    } else {\r
+      //\r
+      // if the SAD is created by IKE, the key is a set of hex value in buffer.\r
+      // Print the Key in Hex format.\r
+      //\r
+      Print (L"  Auth:%s/",AuthAlgoStr);\r
+      DumpBuf ((UINT8 *)(Data->AlgoInfo.EspAlgoInfo.AuthKey), Data->AlgoInfo.EspAlgoInfo.AuthKeyLength);\r
+      \r
+      Print (L"\n  Encrypt:%s/",EncAlgoStr);\r
+      DumpBuf ((UINT8 *)(Data->AlgoInfo.EspAlgoInfo.EncKey), Data->AlgoInfo.EspAlgoInfo.EncKeyLength);      \r
+    }\r
   }\r
-\r
   if (Data->SpdSelector != NULL) {\r
-    Print (L"  ");\r
+    Print (L"\n  ");\r
     DumpSpdSelector (Data->SpdSelector);\r
     Print (L"\n");\r
   }\r
index 7ac1cb5c5a7336d5bb5586569a6a6ff7b0814b3e..d283f5b7168e8cfc0a96326b5471b20be9604ede 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of match policy entry function in IpSecConfig application.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -82,7 +82,7 @@ MatchSpdEntry (
   Find the matching SAD with Indexer.\r
 \r
   @param[in] SaId       The pointer to the EFI_IPSEC_SA_ID structure.\r
-  @param[in] Data       The pointer to the EFI_IPSEC_SA_DATA structure.\r
+  @param[in] Data       The pointer to the EFI_IPSEC_SA_DATA2 structure.\r
   @param[in] Indexer    The pointer to the SPD_ENTRY_INDEXER structure.\r
 \r
   @retval TRUE     The matched SAD is found.\r