def sign_file(name, local_name, server_name):
output("Processing " + local_name + " ...", "VERBOSE")
file = open(name, 'rb')
copy = file.read()
crc32 = format(binascii.crc32(copy) & 0xFFFFFFFF, '08x')
size = os.path.getsize(name)+12
dest = open(local_name, 'w+')
dest.write(u32(0))
dest.write(u32(size))
dest.write(binascii.unhexlify(crc32))
dest.write(copy)
os.remove(name)
dest.close()
file.close()
output("Compressing ...", "VERBOSE")
subprocess.call(["mv", local_name, local_name+"-1"])
subprocess.call(["%s/lzss" % lzss_path, "-evf", local_name+"-1"], stdout=subprocess.PIPE) # Compress the file with the lzss program.
file = open(local_name + '-1', 'rb')
new = file.read()
dest = open(local_name, "w+")
key = open(key_path, 'rb')
output("RSA Signing ...", "VERBOSE")
private_key = rsa.PrivateKey.load_pkcs1(key.read(), "PEM") # Loads the RSA key.
signature = rsa.sign(new, private_key, "SHA-1") # Makes a SHA1 with ASN1 padding. Beautiful.
dest.write(binascii.unhexlify(str(0).zfill(128))) # Padding. This is where data for an encrypted WC24 file would go (such as the header and IV), but this is not encrypted so it's blank.
dest.write(signature)
dest.write(new)
dest.close()
file.close()
key.close()
subprocess.call(["mkdir", "-p", "%s/%s/%s" % (file_path, language_code, str(country_code).zfill(3))]) # Create directory if it does not exist
path = "%s/%s/%s/%s" % (file_path, language_code, str(country_code).zfill(3), server_name) # Path on the server to put the file.
subprocess.call(["cp", local_name, path])
os.remove(local_name)
os.remove(local_name + "-1")
评论列表
文章目录