-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.sh
59 lines (45 loc) · 1.01 KB
/
sign.sh
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
#!/bin/bash
if [ -n "${1}" ]; then
EXE_FILE=${1}
fi
if [ -n "${2}" ]; then
EXE_SIGNED=${2}
fi
if [ -n "${3}" ]; then
PASSWORD=${3}
fi
if [ ! -f ${CERT_FILE} ]; then
echo "Certificate ${CERT_FILE} file not found"
exit 1
fi
if [ ! -f ${EXE_FILE} ]; then
echo "Executable '${EXE_FILE}' not found"
exit 1
fi
mkdir -p sign
KEY_PEM=sign/key.pem
CERT_PEM=sign/cert.pem
RSA_KEY=sign/authenticode.key
RSA_SPC=sign/authenticode.spc
openssl pkcs12 \
-password pass:${CERT_PASSWORD} \
-in ${CERT_FILE} \
-nocerts -nodes \
-out ${KEY_PEM}
openssl pkcs12 \
-password pass:${CERT_PASSWORD} \
-in ${CERT_FILE} \
-nokeys -nodes \
-out ${CERT_PEM}
openssl rsa \
-in ${KEY_PEM} \
-outform DER \
-out ${RSA_KEY}
openssl crl2pkcs7 -nocrl -certfile ${CERT_PEM} \
-outform DER \
-out ${RSA_SPC}
osslsigncode -spc ${RSA_SPC} -key ${RSA_KEY} \
-pass ${PASSWORD} -t ${TIMESTAMP} \
-in ${EXE_FILE} -out ${EXE_SIGNED}
osslsigncode verify ${EXE_SIGNED}
rm -Rf sign/