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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#!/bin/bash
#############################################################################
##
## Copyright (C) 2021 The Qt Company Ltd.
## Copyright (C) 2019 Luxoft Sweden AB
## Copyright (C) 2018 Pelagicore AG
## Contact: https://www.qt.io/licensing/
##
## This file is part of the QtApplicationManager module of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
#set -x
set -e
isWin=0
isMac=0
[ "$OS" == "Windows_NT" ] && isWin=1
[ "$(uname)" == "Darwin" ] && isMac=1
# check basic requirement
[ ! -d certificates ] && { echo "Please cd to the tests/data directory before running this script"; exit 1; }
# set a well-known UTF-8 locale: C.UTF-8 is the obvious choice, but macOS doesn't support it
if [ "$isMac" = "1" ]; then
export LC_ALL=en_US.UTF-8
else
export LC_ALL=C.UTF-8
fi
. utilities.sh
usage()
{
echo "create-test-packages.sh <appman-packager binary>"
exit 1
}
[ "$#" -lt 1 ] && usage
PACKAGER="${@: -1}"
[ ! -x "$PACKAGER" ] && usage
eval ${@:1:$# - 1}
"$PACKAGER" --version 2>/dev/null | grep -qsi "Packager" || usage
( cd certificates && ./create-test-certificates.sh )
dst="packages"
tmp=$(mktemp -d "${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX")
src="$tmp/source"
removeTmp() { rm -rf "$tmp"; }
trap removeTmp INT QUIT 0
mkdir -p "$dst"
mkdir -p "$src"
[ "$isWin" = "1" ] && src=$(cygpath -m "$src")
packager()
{
set +e
packagerOutput=`"$PACKAGER" "$@" 2>&1`
packagerResult=$?
set -e
if [ $packagerResult -ne 0 ]; then
echo -e "`basename $PACKAGER`$R failed with exit code $packagerResult$W. The executed command was:"
echo
echo -e " $G $PACKAGER $@$W"
echo
echo "The command's output was:"
echo
echo "$packagerOutput"
echo
exit $packagerResult
fi
}
echo "Generating test packages:"
### normal packages
cp info.yaml "$src"
cp icon.png "$src"
echo "test" >"$src/test"
if [ "$isMac" = "1" ]; then
# macOS shells create filenames with unicode characters in pre-composed UTF form, which is
# non-standard on macOS. Qt's internal QFileSystemIterator class on the other hand is ignoring
# these filenames as being invalid. A workaround is to convert the name to de-composed form
# already in the shell environment:
echo "test with umlaut" >"$src/$(iconv -f utf-8 -t utf-8-mac <<< täst)"
else
echo "test with umlaut" >"$src/täst"
fi
info "Create package"
packager create-package "$dst/test.appkg" "$src"
info "Dev-sign package"
packager dev-sign-package "$dst/test.appkg" "$dst/test-dev-signed.appkg" certificates/dev1.p12 password
info "Store-sign package"
packager store-sign-package "$dst/test.appkg" "$dst/test-store-signed.appkg" certificates/store.p12 password "foobar"
info "Store-sign dev package"
packager store-sign-package "$dst/test-dev-signed.appkg" "$dst/test-store-dev-signed.appkg" certificates/store.p12 password "foobar"
info "Create package with extra meta-data"
cat >"$tmp/exmd" <<EOT
array:
- 1
- 2
EOT
cat >"$tmp/exmd2" <<EOT
key: value
EOT
cat >"$tmp/exmds" <<EOT
signed-object:
k1: v1
k2: v2
EOT
cat >"$tmp/exmds2" <<EOT
signed-key: signed-value
EOT
packager create-package "$dst/test-extra.appkg" "$src" \
-m '{ "foo": "bar" }' -m '{ "foo2": "bar2" }' -M "$src/../exmd" -M "$src/../exmd2" \
-s '{ "sfoo": "sbar" }' -s '{ "sfoo2": "sbar2" }' -S "$src/../exmds" -S "$src/../exmds2"
info "Dev-sign package with extra meta-data"
packager dev-sign-package "$dst/test-extra.appkg" "$dst/test-extra-dev-signed.appkg" certificates/dev1.p12 password
info "Create a hello-world.red update package"
packager create-package "$dst/hello-world.red.appkg" hello-world.red
### v2 packages for testing updates
echo "test update" >"$src/test"
sed <info.yaml >"$src/info.yaml" 's/version: "1.0"/version: "2.0"/'
info "Create update package"
packager create-package "$dst/test-update.appkg" "$src"
info "Dev-sign update package"
packager dev-sign-package "$dst/test-update.appkg" "$dst/test-update-dev-signed.appkg" certificates/dev2.p12 password
echo "test" >"$src/test"
cp "info.yaml" "$src"
### big packages
cp info-big.yaml "$src/info.yaml"
dd if=/dev/zero of="$src/bigtest" bs=1048576 count=5 >/dev/null 2>&1
info "Create big package"
packager create-package "$dst/bigtest.appkg" "$src"
info "Dev-sign big package"
packager dev-sign-package "$dst/bigtest.appkg" "$dst/bigtest-dev-signed.appkg" certificates/dev1.p12 password
cp info.yaml "$src"
rm "$src/bigtest"
### create invalid packages
tar -C "$src" -xof "$dst/test.appkg" -- --PACKAGE-HEADER-- --PACKAGE-FOOTER--
info "Create a package with invalid format"
echo "invalid" >"$dst/test-invalid-format.appkg"
info "Create a package with an invalid formatVersion header field"
mv "$src"/--PACKAGE-HEADER--{,.orig}
sed <"$src/--PACKAGE-HEADER--.orig" >"$src/--PACKAGE-HEADER--" 's/formatVersion: 2/formatVersion: X/'
tar -C "$src" -cf "$dst/test-invalid-header-formatversion.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-HEADER--{.orig,}
info "Create a package with a 0 diskSpaceUsed header field"
mv "$src"/--PACKAGE-HEADER--{,.orig}
sed <"$src/--PACKAGE-HEADER--.orig" >"$src/--PACKAGE-HEADER--" 's/diskSpaceUsed: [0-9]*/diskSpaceUsed: 0/'
tar -C "$src" -cf "$dst/test-invalid-header-diskspaceused.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-HEADER--{.orig,}
info "Create a package with an invalid id header field"
mv "$src"/--PACKAGE-HEADER--{,.orig}
sed <"$src/--PACKAGE-HEADER--.orig" >"$src/--PACKAGE-HEADER--" "s/packageId: '[a-z0-9.-]*'/packageId: ':invalid'/"
tar -C "$src" -cf "$dst/test-invalid-header-id.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-HEADER--{.orig,}
info "Create a package with a non-matching id header field"
mv "$src"/--PACKAGE-HEADER--{,.orig}
sed <"$src/--PACKAGE-HEADER--.orig" >"$src/--PACKAGE-HEADER--" "s/packageId: '[a-z0-9.-]*'/packageId: 'non-matching'/"
tar -C "$src" -cf "$dst/test-non-matching-header-id.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-HEADER--{.orig,}
info "Create a package with a tampered extraSigned header field"
mv "$src"/--PACKAGE-HEADER--{,.orig}
( cat "$src/--PACKAGE-HEADER--.orig" ; echo "extraSigned: { foo: bar }") >"$src/--PACKAGE-HEADER--"
tar -C "$src" -cf "$dst/test-tampered-extra-signed-header.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-HEADER--{.orig,}
info "Create a package with an invalid info.yaml id"
mv "$src"/info.yaml{,.orig}
sed <"$src/info.yaml.orig" >"$src/info.yaml" 's/id: "[a-z0-9.-]*"/id: ":invalid"/'
tar -C "$src" -cf "$dst/test-invalid-info-id.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/info.yaml{.orig,}
info "Create a package with an invalid info.yaml file"
mv "$src"/info.yaml{,.orig}
sed <"$src/info.yaml.orig" >"$src/info.yaml" 's/code: "test"/: "test"/'
tar -C "$src" -cf "$dst/test-invalid-info.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/info.yaml{.orig,}
info "Create a package with an invalid file order"
tar -C "$src" -cf "$dst/test-invalid-file-order.appkg" -- --PACKAGE-HEADER-- info.yaml test icon.png --PACKAGE-FOOTER--
info "Create a package with an invalid digest"
mv "$src"/--PACKAGE-FOOTER--{,.orig}
tr <"$src/--PACKAGE-FOOTER--.orig" >"$src/--PACKAGE-FOOTER--" 3 0
tar -C "$src" -cf "$dst/test-invalid-footer-digest.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png test --PACKAGE-FOOTER--
mv "$src"/--PACKAGE-FOOTER--{.orig,}
info "Create a package with an invalid signature"
packager dev-sign-package "$dst/test.appkg" "$dst/test-invalid-footer-signature.appkg" certificates/other.p12 password
info "Create a package with an invalid entry path"
touch "$src/../invalid-path"
tar -C "$src" -P -cf "$dst/test-invalid-path.appkg" -- --PACKAGE-HEADER-- info.yaml icon.png ../invalid-path test --PACKAGE-FOOTER--
echo -e "$G All test packages have been created successfully$W"
echo
exit 0
|