Page MenuHome
Paste P1137

winsigner.py
ActivePublic

Authored by Nathan Letwory (jesterking) on Thu, Oct 10, 12:28 PM.
import subprocess
import zipfile
import pathlib
import os
import time
PFX = "D:\Dev\\bf-blender\\signbuildbot\\blendersigner\\buildbot\\BlenderSPC.pfx"
TIMESTAMP_URL = "http://timestamp.digicert.com"
WINSIGNER_UNSIGNED_DIR="N:\\uploaded_builds\\unsigned"
WINSIGNER_SIGNED_DIR="N:\\uploaded_builds\\signed"
cwd_with_sep = WINSIGNER_UNSIGNED_DIR + os.sep
to_sign_zip = os.path.join(WINSIGNER_UNSIGNED_DIR, "tosign.zip")
to_sign_file = os.path.join(WINSIGNER_UNSIGNED_DIR, 'to_sign')
signed_zip = os.path.join(WINSIGNER_SIGNED_DIR, "signed.zip")
signed_file = os.path.join(WINSIGNER_SIGNED_DIR, 'signed')
incantation = "signtool sign /v /f {} /t {}".format(PFX, TIMESTAMP_URL)
# forever
while True:
os.chdir(WINSIGNER_UNSIGNED_DIR)
print("Waiting for sign request...")
while not os.path.exists(to_sign_file):
time.sleep(1)
print("Received request to sign")
with zipfile.ZipFile(to_sign_zip, 'r') as zf:
zf.extractall()
# signing
blenextractdirpath = pathlib.Path(WINSIGNER_UNSIGNED_DIR)
allfiles = [
list(blenextractdirpath.rglob("*.exe")),
list(blenextractdirpath.rglob("*.dll")),
list(blenextractdirpath.rglob("*.msi"))
]
allfiles = [y for x in allfiles for y in x]
command = incantation.split()
for allfn in allfiles:
allfn = str(allfn)
if allfn.find("ms-win")>-1: continue
if allfn.endswith("140.all"): continue
allfn = allfn.replace(cwd_with_sep, "")
command.append(allfn)
print(command)
subprocess.run(command)
# rezip to signed dir
with zipfile.ZipFile(signed_zip, 'w') as zf:
for allfn in allfiles:
allfn = str(allfn)
shortallfn = allfn.replace(cwd_with_sep, "")
zf.write(allfn, arcname=shortallfn)
# cleanup
for allfn in allfiles:
os.remove(allfn)
os.remove(to_sign_file)
with open(signed_file, 'w') as f:
f.write(" ")
print("Done signing")