summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Rsa2048Sha256Sign
diff options
context:
space:
mode:
authorFeng, Bob C <bob.c.feng@intel.com>2019-01-23 10:16:00 +0800
committerFeng, Bob C <bob.c.feng@intel.com>2019-02-01 11:09:24 +0800
commitd943b0c339fe3d35ffdf9f580ccb7a55915c6854 (patch)
treef48623041095431d49c3cb8ce7f1a8dab953f26e /BaseTools/Source/Python/Rsa2048Sha256Sign
parentf8d11e5a4aaa90bf63b4789f3993dd6d16c60787 (diff)
downloadedk2-d943b0c339fe3d35ffdf9f580ccb7a55915c6854.tar.gz
edk2-d943b0c339fe3d35ffdf9f580ccb7a55915c6854.tar.bz2
edk2-d943b0c339fe3d35ffdf9f580ccb7a55915c6854.zip
BaseTools: Handle the bytes and str difference
Deal with bytes and str is different, remove the unicode(), correct open file parameter. Using utcfromtimestamp instead of fromtimestamp. Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Tested-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Rsa2048Sha256Sign')
-rw-r--r--BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py14
-rw-r--r--BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py7
2 files changed, 11 insertions, 10 deletions
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
index f96ceb2637..c0b661d03c 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
@@ -84,7 +84,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 = []
@@ -119,19 +119,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
@@ -157,14 +157,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 c285a69ec0..6cea885853 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
@@ -105,7 +105,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
@@ -153,7 +153,8 @@ 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 + PublicKeyHexString[0:2]
@@ -210,7 +211,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)