X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FRsa2048Sha256Sign%2FRsa2048Sha256Sign.py;h=df05826282ebb685f14f4dd00a686944780f759c;hp=285635963100fe7b8fdae62c71e720667ba10bcf;hb=HEAD;hpb=8371d87412bc1dae454dcc570691fc0d63e710b4 diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py index 2856359631..df05826282 100644 --- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py +++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py @@ -5,18 +5,13 @@ # This tool has been tested with OpenSSL 1.0.1e 11 Feb 2013 # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# SPDX-License-Identifier: BSD-2-Clause-Patent # ''' Rsa2048Sha256Sign ''' +from __future__ import print_function import os import sys @@ -41,7 +36,7 @@ __usage__ = '%s -e|-d [options] ' % (__prog__) EFI_HASH_ALGORITHM_SHA256_GUID = uuid.UUID('{51aa59de-fdf2-4ea3-bc63-875fb7842ee9}') # -# Structure defintion to unpack EFI_CERT_BLOCK_RSA_2048_SHA256 from UEFI 2.4 Specification +# Structure definition to unpack EFI_CERT_BLOCK_RSA_2048_SHA256 from UEFI 2.4 Specification # # typedef struct _EFI_CERT_BLOCK_RSA_2048_SHA256 { # EFI_GUID HashType; @@ -61,10 +56,11 @@ if __name__ == '__main__': # # Create command line argument parser object # - parser = argparse.ArgumentParser(prog=__prog__, version=__version__, usage=__usage__, description=__copyright__, conflict_handler='resolve') + parser = argparse.ArgumentParser(prog=__prog__, usage=__usage__, description=__copyright__, conflict_handler='resolve') group = parser.add_mutually_exclusive_group(required=True) group.add_argument("-e", action="store_true", dest='Encode', help='encode file') group.add_argument("-d", action="store_true", dest='Decode', help='decode file') + group.add_argument("--version", action='version', version=__version__) parser.add_argument("-o", "--output", dest='OutputFile', type=str, metavar='filename', help="specify the output filename", required=True) parser.add_argument("--monotonic-count", dest='MonotonicCountStr', type=str, help="specify the MonotonicCount in FMP capsule.") parser.add_argument("--private-key", dest='PrivateKeyFile', type=argparse.FileType('rb'), help="specify the private key filename. If not specified, a test signing key is used.") @@ -103,7 +99,7 @@ if __name__ == '__main__': if Process.returncode != 0: print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH') sys.exit(Process.returncode) - print(Version[0]) + print(Version[0].decode('utf-8')) # # Read input file into a buffer and save input filename @@ -151,10 +147,11 @@ if __name__ == '__main__': # Extract public key from private key into STDOUT # Process = subprocess.Popen('%s rsa -in "%s" -modulus -noout' % (OpenSslCommand, args.PrivateKeyFileName), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - PublicKeyHexString = Process.communicate()[0].split('=')[1].strip() + PublicKeyHexString = Process.communicate()[0].split(b'=')[1].strip() + PublicKeyHexString = PublicKeyHexString.decode('utf-8') PublicKey = '' while len(PublicKeyHexString) > 0: - PublicKey = PublicKey + chr(int(PublicKeyHexString[0:2], 16)) + PublicKey = PublicKey + PublicKeyHexString[0:2] PublicKeyHexString=PublicKeyHexString[2:] if Process.returncode != 0: sys.exit(Process.returncode) @@ -162,9 +159,9 @@ if __name__ == '__main__': if args.MonotonicCountStr: try: if args.MonotonicCountStr.upper().startswith('0X'): - args.MonotonicCountValue = (int)(args.MonotonicCountStr, 16) + args.MonotonicCountValue = int(args.MonotonicCountStr, 16) else: - args.MonotonicCountValue = (int)(args.MonotonicCountStr) + args.MonotonicCountValue = int(args.MonotonicCountStr) except: pass @@ -185,8 +182,8 @@ if __name__ == '__main__': # Write output file that contains hash GUID, Public Key, Signature, and Input data # args.OutputFile = open(args.OutputFileName, 'wb') - args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.get_bytes_le()) - args.OutputFile.write(PublicKey) + args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.bytes_le) + args.OutputFile.write(bytearray.fromhex(str(PublicKey))) args.OutputFile.write(Signature) args.OutputFile.write(args.InputFileBuffer) args.OutputFile.close() @@ -208,7 +205,7 @@ if __name__ == '__main__': # # Verify the public key # - if Header.PublicKey != PublicKey: + if Header.PublicKey != bytearray.fromhex(PublicKey): print('ERROR: Public key in input file does not match public key from private key file') sys.exit(1)