]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Capsule/GenerateCapsule.py
BaseTools:Coding problems cause can not encode FMP Auth Header
[mirror_edk2.git] / BaseTools / Source / Python / Capsule / GenerateCapsule.py
index d829000849ad0185e9e3b911b1fe09b0708f1a5e..4de363529889faba560a3d503f357eb6dfab8a68 100644 (file)
 #   * Do not support vendor code bytes in a capsule.\r
 #\r
 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 '''\r
@@ -94,7 +88,7 @@ def SignPayloadSignTool (Payload, ToolPath, PfxFile):
 \r
     if Process.returncode != 0:\r
         shutil.rmtree (TempDirectoryName)\r
-        print (Result[1].decode())\r
+        print (Result[1].decode(encoding='utf-8', errors='ignore'))\r
         raise ValueError ('GenerateCapsule: error: signtool failed.')\r
 \r
     #\r
@@ -137,7 +131,7 @@ def SignPayloadOpenSsl (Payload, ToolPath, SignerPrivateCertFile, OtherPublicCer
         raise ValueError ('GenerateCapsule: error: can not run openssl.')\r
 \r
     if Process.returncode != 0:\r
-        print (Result[1].decode())\r
+        print (Result[1].decode(encoding='utf-8', errors='ignore'))\r
         raise ValueError ('GenerateCapsule: error: openssl failed.')\r
 \r
     return Signature\r
@@ -186,7 +180,7 @@ def VerifyPayloadOpenSsl (Payload, CertData, ToolPath, SignerPrivateCertFile, Ot
 \r
     if Process.returncode != 0:\r
         shutil.rmtree (TempDirectoryName)\r
-        print (Result[1].decode())\r
+        print (Result[1].decode(encoding='utf-8', errors='ignore'))\r
         raise ValueError ('GenerateCapsule: error: openssl failed.')\r
 \r
     shutil.rmtree (TempDirectoryName)\r
@@ -408,7 +402,6 @@ if __name__ == '__main__':
                                  )\r
             except:\r
                 print ('GenerateCapsule: error: can not sign payload')\r
-                raise\r
                 sys.exit (1)\r
 \r
             try:\r
@@ -456,6 +449,9 @@ if __name__ == '__main__':
                 FmpCapsuleHeader.DumpInfo ()\r
             if UseSignTool or UseOpenSsl:\r
                 Result = FmpAuthHeader.Decode (Result)\r
+                if args.Verbose:\r
+                    print ('--------')\r
+                    FmpAuthHeader.DumpInfo ()\r
 \r
                 #\r
                 # Verify Image with 64-bit MonotonicCount appended to end of image\r
@@ -480,23 +476,27 @@ if __name__ == '__main__':
                 except ValueError:\r
                     print ('GenerateCapsule: warning: can not verify payload.')\r
 \r
-                Result = FmpPayloadHeader.Decode (Result)\r
-                if args.Verbose:\r
-                    print ('--------')\r
-                    FmpAuthHeader.DumpInfo ()\r
-                    print ('--------')\r
-                    FmpPayloadHeader.DumpInfo ()\r
+                try:\r
+                    Result = FmpPayloadHeader.Decode (Result)\r
+                    if args.Verbose:\r
+                        print ('--------')\r
+                        FmpPayloadHeader.DumpInfo ()\r
+                        print ('========')\r
+                except:\r
+                    if args.Verbose:\r
+                        print ('--------')\r
+                        print ('No FMP_PAYLOAD_HEADER')\r
+                        print ('========')\r
+                    raise\r
             else:\r
                 if args.Verbose:\r
                     print ('--------')\r
                     print ('No EFI_FIRMWARE_IMAGE_AUTHENTICATION')\r
                     print ('--------')\r
                     print ('No FMP_PAYLOAD_HEADER')\r
-            if args.Verbose:\r
-                print ('========')\r
+                    print ('========')\r
         except:\r
             print ('GenerateCapsule: error: can not decode capsule')\r
-            raise\r
             sys.exit (1)\r
 \r
     elif args.DumpInfo:\r
@@ -510,11 +510,15 @@ if __name__ == '__main__':
             FmpCapsuleHeader.DumpInfo ()\r
             try:\r
                 Result = FmpAuthHeader.Decode (Result)\r
-                Result = FmpPayloadHeader.Decode (Result)\r
                 print ('--------')\r
                 FmpAuthHeader.DumpInfo ()\r
-                print ('--------')\r
-                FmpPayloadHeader.DumpInfo ()\r
+                try:\r
+                    Result = FmpPayloadHeader.Decode (Result)\r
+                    print ('--------')\r
+                    FmpPayloadHeader.DumpInfo ()\r
+                except:\r
+                    print ('--------')\r
+                    print ('No FMP_PAYLOAD_HEADER')\r
             except:\r
                 print ('--------')\r
                 print ('No EFI_FIRMWARE_IMAGE_AUTHENTICATION')\r