/
pkpass.sh
executable file
·89 lines (61 loc) · 1.76 KB
/
pkpass.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# First parameter is a directory to be
if [ $2 ]
then
echo Packaging directory $2
# remmember current directory
olddir=$(pwd)
cd $2
rm -rf .DS_Store
# Opening statement
echo "{" > manifest.json
# Iterating over files in the specified directory
first="true"
for file in `find .`
do
if [ -f $file ]
then
# Creating filename without "./" prefix
fname=$(echo $file | colrm 1 2)
if [ "$fname" != "manifest.json" ]
then
if [ "$first" == "true" ]
then
first="false"
else
echo "," >> manifest.json
fi
echo FILE = $fname
checksum=$(openssl sha1 $fname | awk '{print $2}')
echo -n "\"$fname\" : \"$checksum\"" >> manifest.json
fi
fi
done
# Closing statement
echo >> manifest.json
echo "}" >> manifest.json
# Packagine must be done here
cd $olddir
echo "Extracting keys from certificate"
openssl pkcs12 -in $1 -clcerts -nokeys -passin "pass:$3" -out certificate.pem
openssl pkcs12 -in $1 -nocerts -out key.pem -passin "pass:$3" -passout pass:simplepassword
echo "SIGNING ITSELF"
openssl smime -binary -sign -certfile wwdr.pem -signer certificate.pem -inkey key.pem -passin pass:simplepassword -in "$2/manifest.json" -out "$2/signature" -outform DER
echo "Cleaning up"
rm -f certificate.pem
rm -f key.pem
echo "Compressing"
cd $2
outname="out.pkpass"
if [ $4 ]
then
outname="$4.pkpass"
fi
zip -r $outname * -x *.DS_Store
cp $outname "$olddir/"
rm -f $outname
rm -f signature
rm -f manifest.json
else
echo FORMAT: $0 certificate.p12 path/to/package/content password [PackageName]
fi