diff options
author | Yunhua Feng <yunhuax.feng@intel.com> | 2018-10-11 11:20:59 +0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2018-10-13 09:54:07 +0800 |
commit | 86e6cf98a8493574878286522078050ac4dd505d (patch) | |
tree | ca47729eab67c9f90e0dac5a14dc5ca14ef22ef1 /BaseTools/Source/Python/Rsa2048Sha256Sign | |
parent | a09f4c91f785e36f0987aa3a6d7656ba51e6aeda (diff) | |
download | edk2-86e6cf98a8493574878286522078050ac4dd505d.tar.gz edk2-86e6cf98a8493574878286522078050ac4dd505d.tar.bz2 edk2-86e6cf98a8493574878286522078050ac4dd505d.zip |
BaseTools: Handle the bytes and str difference
Deal with bytes and str is different, remove the unicode()
Using utcfromtimestamp instead of fromtimestamp.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Rsa2048Sha256Sign')
-rw-r--r-- | BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py | 14 | ||||
-rw-r--r-- | BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py | 11 |
2 files changed, 13 insertions, 12 deletions
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py index 1be360f743..e49e819c9a 100644 --- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py +++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py @@ -82,7 +82,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())
args.PemFileName = []
@@ -117,19 +117,19 @@ if __name__ == '__main__': args.PemFileName.append(Item.name)
Item.close()
- PublicKeyHash = ''
+ PublicKeyHash = bytearray()
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('=')[1].strip()
+ PublicKeyHexString = Process.communicate()[0].split(b'=')[1].strip()
if Process.returncode != 0:
print('ERROR: Unable to extract public key from private key')
sys.exit(Process.returncode)
- PublicKey = ''
+ PublicKey = bytearray()
for Index in range (0, len(PublicKeyHexString), 2):
- PublicKey = PublicKey + chr(int(PublicKeyHexString[Index:Index + 2], 16))
+ PublicKey = PublicKey + PublicKeyHexString[Index:Index + 2]
#
# Generate SHA 256 hash of RSA 2048 bit public key into STDOUT
@@ -155,14 +155,14 @@ if __name__ == '__main__': #
PublicKeyHashC = '{'
for Item in PublicKeyHash:
- PublicKeyHashC = PublicKeyHashC + '0x%02x, ' % (ord(Item))
+ PublicKeyHashC = PublicKeyHashC + '0x%02x, ' % (Item)
PublicKeyHashC = PublicKeyHashC[:-2] + '}'
#
# Write SHA 256 of 2048 bit binary public key to public key hash C structure file
#
try:
- args.PublicKeyHashCFile.write (PublicKeyHashC)
+ args.PublicKeyHashCFile.write (bytes(PublicKeyHashC))
args.PublicKeyHashCFile.close ()
except:
pass
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py index 2856359631..be5ebac280 100644 --- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py +++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py @@ -103,7 +103,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())
#
# Read input file into a buffer and save input filename
@@ -151,10 +151,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(encoding='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)
@@ -186,7 +187,7 @@ if __name__ == '__main__': #
args.OutputFile = open(args.OutputFileName, 'wb')
args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.get_bytes_le())
- args.OutputFile.write(PublicKey)
+ args.OutputFile.write(bytearray.fromhex(PublicKey))
args.OutputFile.write(Signature)
args.OutputFile.write(args.InputFileBuffer)
args.OutputFile.close()
@@ -208,7 +209,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)
|