Revert BaseTools: PYTHON3 migration
This reverts commit 6693f359b3c213513c5096a06c6f67244a44dc52..
678f851312
.
Python3 migration is the fundamental change. It requires every developer
to install Python3. Before this migration, the well communication and wide
verification must be done. But now, most people is not aware of this change,
and not try it. So, Python3 migration is reverted and be moved to edk2-staging
Python3 branch for the edk2 user evaluation.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
'''
|
||||
Rsa2048Sha256GenerateKeys
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
@ -42,9 +43,8 @@ if __name__ == '__main__':
|
||||
#
|
||||
# Create command line argument parser object
|
||||
#
|
||||
parser = argparse.ArgumentParser(prog=__prog__, usage=__usage__, description=__copyright__, conflict_handler='resolve')
|
||||
parser = argparse.ArgumentParser(prog=__prog__, version=__version__, usage=__usage__, description=__copyright__, conflict_handler='resolve')
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("--version", action='version', version=__version__)
|
||||
group.add_argument("-o", "--output", dest='OutputFile', type=argparse.FileType('wb'), metavar='filename', nargs='*', help="specify the output private key filename in PEM format")
|
||||
group.add_argument("-i", "--input", dest='InputFile', type=argparse.FileType('rb'), metavar='filename', nargs='*', help="specify the input private key filename in PEM format")
|
||||
parser.add_argument("--public-key-hash", dest='PublicKeyHashFile', type=argparse.FileType('wb'), help="specify the public key hash filename that is SHA 256 hash of 2048 bit RSA public key in binary format")
|
||||
@ -83,7 +83,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].decode())
|
||||
print(Version[0])
|
||||
|
||||
args.PemFileName = []
|
||||
|
||||
@ -118,19 +118,19 @@ if __name__ == '__main__':
|
||||
args.PemFileName.append(Item.name)
|
||||
Item.close()
|
||||
|
||||
PublicKeyHash = bytearray()
|
||||
PublicKeyHash = ''
|
||||
for Item in args.PemFileName:
|
||||
#
|
||||
# Extract public key from private key into STDOUT
|
||||
#
|
||||
Process = subprocess.Popen('%s rsa -in %s -modulus -noout' % (OpenSslCommand, Item), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
PublicKeyHexString = Process.communicate()[0].split(b'=')[1].strip()
|
||||
PublicKeyHexString = Process.communicate()[0].split('=')[1].strip()
|
||||
if Process.returncode != 0:
|
||||
print('ERROR: Unable to extract public key from private key')
|
||||
sys.exit(Process.returncode)
|
||||
PublicKey = bytearray()
|
||||
PublicKey = ''
|
||||
for Index in range (0, len(PublicKeyHexString), 2):
|
||||
PublicKey = PublicKey + PublicKeyHexString[Index:Index + 2]
|
||||
PublicKey = PublicKey + chr(int(PublicKeyHexString[Index:Index + 2], 16))
|
||||
|
||||
#
|
||||
# Generate SHA 256 hash of RSA 2048 bit public key into STDOUT
|
||||
@ -156,14 +156,14 @@ if __name__ == '__main__':
|
||||
#
|
||||
PublicKeyHashC = '{'
|
||||
for Item in PublicKeyHash:
|
||||
PublicKeyHashC = PublicKeyHashC + '0x%02x, ' % (Item)
|
||||
PublicKeyHashC = PublicKeyHashC + '0x%02x, ' % (ord(Item))
|
||||
PublicKeyHashC = PublicKeyHashC[:-2] + '}'
|
||||
|
||||
#
|
||||
# Write SHA 256 of 2048 bit binary public key to public key hash C structure file
|
||||
#
|
||||
try:
|
||||
args.PublicKeyHashCFile.write (bytes(PublicKeyHashC))
|
||||
args.PublicKeyHashCFile.write (PublicKeyHashC)
|
||||
args.PublicKeyHashCFile.close ()
|
||||
except:
|
||||
pass
|
||||
|
Reference in New Issue
Block a user