-
Notifications
You must be signed in to change notification settings - Fork 6
/
signer.py
72 lines (55 loc) · 1.76 KB
/
signer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!env python
"""
Prompt for a password for signtool
"""
import subprocess
import sys
import getpass
import os
import shutil
from Tkinter import *
def getpwd(prompt):
store = {}
root = Tk()
pwdbox = Entry(root, show='*')
def onpwdentry(evt):
store["pass"] = pwdbox.get()
root.destroy()
def onokclick():
onpwdentry(None)
Label(root, text=prompt).pack(side='top')
pwdbox.pack(side='top')
pwdbox.bind('<Return>', onpwdentry)
Button(root, command=onokclick, text='OK').pack(side='top')
root.mainloop()
return store["pass"]
TIMESTAMP_SERVER = "http://timestamp.comodoca.com/authenticode"
SIGNTOOL = os.path.join(os.path.abspath(os.sep),
"Program Files (x86)", "Windows Kits", "8.1", "bin", "x64", "signtool.exe")
def execute(pfxfile, exefile, gui=False, copy=None):
"""
Run the signer
:param args:
:return:
"""
print("Running in {}".format(os.getcwd()))
assert os.path.exists(pfxfile), "Can't find pfx file {}".format(pfxfile)
assert os.path.exists(exefile), "Can't find exe file {}".format(exefile)
assert os.path.exists(SIGNTOOL), "Can't find signtool"
if not gui:
password = getpass.getpass("Enter password for {}:".format(pfxfile))
else:
password = getpwd("Enter password for {}:".format(pfxfile))
cmd = [SIGNTOOL, "sign",
"/t", TIMESTAMP_SERVER,
"/p", password,
"/f", pfxfile,
"/v", exefile]
subprocess.check_call(cmd)
if copy:
folder = os.path.dirname(copy)
if not os.path.exists(folder):
os.makedirs(folder)
shutil.copy(exefile, copy)
if __name__ == "__main__":
execute(sys.argv[1], sys.argv[2], copy=sys.argv[3], gui="--gui" in sys.argv)