Bläddra i källkod

SCons: Abort if SCRIPT_AES256_ENCRYPTION_KEY is invalid

Helps users figure out that something is wrong if they did define this
environment variable and it turns out being ignored.

(cherry picked from commit 08b4383e3f7543fca93c7df71343d3559c45637e)
Rémi Verschelde 4 år sedan
förälder
incheckning
a00ef0d27b
1 ändrade filer med 10 tillägg och 7 borttagningar
  1. 10 7
      core/SCsub

+ 10 - 7
core/SCsub

@@ -14,25 +14,28 @@ import os
 
 
 txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
 txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
 if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
 if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
-    e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
-    txt = ""
+    key = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
     ec_valid = True
     ec_valid = True
-    if len(e) != 64:
+    if len(key) != 64:
         ec_valid = False
         ec_valid = False
     else:
     else:
-
+        txt = ""
         for i in range(len(e) >> 1):
         for i in range(len(e) >> 1):
             if i > 0:
             if i > 0:
                 txt += ","
                 txt += ","
-            txts = "0x" + e[i * 2 : i * 2 + 2]
+            txts = "0x" + key[i * 2 : i * 2 + 2]
             try:
             try:
                 int(txts, 16)
                 int(txts, 16)
             except Exception:
             except Exception:
                 ec_valid = False
                 ec_valid = False
             txt += txts
             txt += txts
     if not ec_valid:
     if not ec_valid:
-        txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
-        print("Invalid AES256 encryption key, not 64 bits hex: " + e)
+        print("Error: Invalid AES256 encryption key, not 64 hexadecimal characters: '" + key + "'.")
+        print(
+            "Unset 'SCRIPT_AES256_ENCRYPTION_KEY' in your environment "
+            "or make sure that it contains exactly 64 hexadecimal characters."
+        )
+        Exit(255)
 
 
 # NOTE: It is safe to generate this file here, since this is still executed serially
 # NOTE: It is safe to generate this file here, since this is still executed serially
 with open("script_encryption_key.gen.cpp", "w") as f:
 with open("script_encryption_key.gen.cpp", "w") as f: