summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Rsa2048Sha256Sign
diff options
context:
space:
mode:
authorLiming Gao <liming.gao@intel.com>2018-10-15 08:27:53 +0800
committerLiming Gao <liming.gao@intel.com>2018-10-15 08:29:14 +0800
commit1ccc4d895dd8d659d016efcd6ef8a48749aba1d0 (patch)
tree0d5f58643cc72275887d3bb322813609906a9334 /BaseTools/Source/Python/Rsa2048Sha256Sign
parent678f85131238622e576705117e299d81cff755c9 (diff)
downloadedk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.tar.gz
edk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.tar.bz2
edk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.zip
Revert BaseTools: PYTHON3 migration
This reverts commit 6693f359b3c213513c5096a06c6f67244a44dc52.. 678f85131238622e576705117e299d81cff755c9. 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>
Diffstat (limited to 'BaseTools/Source/Python/Rsa2048Sha256Sign')
-rw-r--r--BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py18
-rw-r--r--BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py21
2 files changed, 19 insertions, 20 deletions
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
index 7bdc460146..a34dac423b 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
@@ -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
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
index 2f901a7f29..3fd7eefd6a 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
@@ -17,6 +17,7 @@
'''
Rsa2048Sha256Sign
'''
+from __future__ import print_function
import os
import sys
@@ -61,9 +62,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("-e", action="store_true", dest='Encode', help='encode file')
group.add_argument("-d", action="store_true", dest='Decode', help='decode file')
parser.add_argument("-o", "--output", dest='OutputFile', type=str, metavar='filename', help="specify the output filename", required=True)
@@ -104,7 +104,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])
#
# Read input file into a buffer and save input filename
@@ -152,11 +152,10 @@ 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(b'=')[1].strip()
- PublicKeyHexString = PublicKeyHexString.decode(encoding='utf-8')
+ PublicKeyHexString = Process.communicate()[0].split('=')[1].strip()
PublicKey = ''
while len(PublicKeyHexString) > 0:
- PublicKey = PublicKey + PublicKeyHexString[0:2]
+ PublicKey = PublicKey + chr(int(PublicKeyHexString[0:2], 16))
PublicKeyHexString=PublicKeyHexString[2:]
if Process.returncode != 0:
sys.exit(Process.returncode)
@@ -164,9 +163,9 @@ if __name__ == '__main__':
if args.MonotonicCountStr:
try:
if args.MonotonicCountStr.upper().startswith('0X'):
- args.MonotonicCountValue = (int)(args.MonotonicCountStr, 16)
+ args.MonotonicCountValue = (long)(args.MonotonicCountStr, 16)
else:
- args.MonotonicCountValue = (int)(args.MonotonicCountStr)
+ args.MonotonicCountValue = (long)(args.MonotonicCountStr)
except:
pass
@@ -187,8 +186,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.bytes_le)
- args.OutputFile.write(bytearray.fromhex(PublicKey))
+ args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.get_bytes_le())
+ args.OutputFile.write(PublicKey)
args.OutputFile.write(Signature)
args.OutputFile.write(args.InputFileBuffer)
args.OutputFile.close()
@@ -210,7 +209,7 @@ if __name__ == '__main__':
#
# Verify the public key
#
- if Header.PublicKey != bytearray.fromhex(PublicKey):
+ if Header.PublicKey != PublicKey:
print('ERROR: Public key in input file does not match public key from private key file')
sys.exit(1)