-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathgpg-client-wrapper
More file actions
executable file
·342 lines (335 loc) · 11.4 KB
/
gpg-client-wrapper
File metadata and controls
executable file
·342 lines (335 loc) · 11.4 KB
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
options=() # the buffer array for the parameters
eoo=0 # end of options reached
output=0 # do we try to write to file
target='' # where do we try to write to
special_filenames=0 # --enable-special-filenames was given
localgpg=0 #use local gpg (for ex --gen-rand etc.)
origargs=( "$@" )
set_output () {
if (( output )); then
echo 'Output file already set'>&2
exit 1
fi
output=1 target=$1
}
check_charset () {
if ! [[ "$1" =~ ^[uU][tT][fF]-?8$ ]]; then
printf 'Unsupported character set %q\n' "$1"
exit 1
fi
}
while (( $# )); do
if ! ((eoo)); then
case "$1" in
#when those arguments are present will not use the keyring, and so they can be executed with local gpg
# can be used in combination with sign
#-c)
# localgpg=1
# break
#;;
--gen-rand|--gen-prime|--enarmor|--dearmor|--print-md|--help|-h)
localgpg=1
break
;;
--no-default-keyring)
# this is not possible with split gpg right?
localgpg=1
break
;;
--import)
# ignore all the options and only collect file name(s) - if any
shift
exec qubes-gpg-import-key "$@"
;;
# Keyserver options makes no sense for offline GPG VM, so it is
# rejected by qubes-gpg-client and qubes-gpg-server. But since
# it is forced by Torbirdy extension, simply ignore the option.
--keyserver-options=*)
shift
;;
# --quiet is safe and is accepted by the current server, but
# old versions rejected it. Use -q instead, which is
# accepted in all versions.
--quiet)
options+=(-q)
shift
;;
--keyserver-options)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
shift 2
;;
# Using dirmngr in an offline GPG VM makes no sense, however
# qubes-gpg-client does not recognize the command line option
# --disable-dirmngr so to avoid an error message we ignore
# this option.
--disable-dirmngr)
shift
;;
# --photo-viewer shouldn't be passed to the backend as it allow
# arbitrary command execution
--photo-viewer=*)
shift
;;
--photo-viewer)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
shift 2
;;
# --command-fd is used by reprepro, and looks safe.
# However, it turns out that GnuPG trusts the data it
# receives on this FD, so the backend has to reject it.
--command-fd=*)
shift
;;
--command-fd)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
shift 2
;;
# Used by Mailpile, see https://github.com/QubesOS/qubes-issues/issues/3485
--expert|--pinentry-mode=*|--passphrase-fd=*|--no-use-agent)
shift
;;
--pinentry-mode|--passphrase-fd)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
shift 2
;;
# ignore tty/display related options - those are meaningless in another VM
--ttyname=*|--display=*|--ttytype=*|--lc-messages=*|--lc-ctype=*|--no-tty|--xauthority=*)
shift
;;
--ttyname|--ttytype|--display|--lc-messages|--lc-ctype|--xauthority)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
shift 2
;;
--enable-special-filenames)
special_filenames=1
shift
;;
# Deprecated legacy options
--disable-mdc|\
--force-mdc|\
--force-v3-sigs|\
--force-v4-certs|\
--no-sk-comments|\
--use-agent)
shift
;;
# Ignored options
--yes)
shift
;;
--detach|--detach-sig)
options+=( --detach-sign )
shift
;;
--output)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
set_output "$2"
shift 2
;;
--output=*)
set_output "${1:9}"
shift
;;
--status-fd|\
--logger-fd|\
--attribute-fd)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
elif [[ "$2" =~ ^(0x)?0*1$ ]]; then
# don't use stdout for status fd, since it might be later
# redirected to a file with --output
exec {fd_for_stdout}>&1
options+=( "$1" "$fd_for_stdout" )
else
options+=( "$1" "$2" )
fi
shift 2
;;
--status-fd=*|\
--logger-fd=*|\
--attribute-fd=*)
if [[ $1 =~ ^([^=]*=)(0x)?0*1$ ]]; then
# don't use stdout for status fd, since it might be later
# redirected to a file with --output
exec {fd_for_stdout}>&1
options+=( "${BASH_REMATCH[1]}$fd_for_stdout" )
else
options+=( "$1" )
fi
shift
;;
--log-file=*)
# rejected by split-gpg to not allow a write to arbitrary file
# on the backend side; emulate using --logger-fd
exec {fd_for_logfile}>"${1:11}"
options+=( "--logger-fd" "$fd_for_logfile" )
shift
;;
--log-file)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
# rejected by split-gpg to not allow a write to arbitrary file
# on the backend side; emulate using --logger-fd
exec {fd_for_logfile}>"$2"
options+=( "--logger-fd" "$fd_for_logfile" )
shift 2
;;
--display-charset=*)
check_charset "${1:18}"
shift
;;
--charset=*)
check_charset "${1:10}"
shift
;;
--charset|--display-charset)
if [[ "$#" -lt 2 ]]; then
printf 'Missing argument to %s\n' "$1" >&2
exit 1
fi
check_charset "$2"
shift 2
;;
# alias '--sign-with' to '-u' (short for '--local-user')
# https://github.com/QubesOS/qubes-issues/issues/3325#issuecomment-1039877769
--sign-with=*)
options+=("-u" "${1:12}")
shift
;;
--sign-with)
if (( $# >= 2 )); then
options+=("-u" "$2")
shift 2
else # let qubes-gpg-client error out
options+=("$1")
shift
fi
;;
--auto-key-locate)
# Generally not safe to use, but allow using with the default
# value (and ignore the option in such case as it's no-op)
# See https://github.com/QubesOS/qubes-issues/issues/8287
if [ "$2" = "local,wkd" ]; then
shift 2
else
printf 'Unsupported --auto-key-locate %s (only local,wkd value is allowed)\n' "$2" >&2
exit 1
fi
;;
--cert-digest-algo|\
--cert-notation|\
--cipher-algo|\
--command-fd|\
--comment|\
--compress-algo|\
--default-recipient|\
--digest-algo|\
--disable-cipher-algo|\
--disable-pubkey-algo|\
--encrypt-to|\
--hidden-encrypt-to|\
--hidden-recipient|\
--list-options|\
--local-user|\
--keyid-format|\
--max-output|\
--personal-cipher-preferences|\
--personal-compress-preferences|\
--personal-digest-preferences|\
--recipient|\
--s2k-cipher-algo|\
--s2k-count|\
--s2k-digest-algo|\
--s2k-mode|\
--sender|\
--sig-notation|\
--set-filename|\
--set-notation|\
--trust-model|\
--trusted-key|\
--try-secret-key|\
--verify-options)
if (( $# >= 2 )); then
options+=("$1" "$2")
shift 2
else # let qubes-gpg-client error out
options+=("$1")
shift
fi
;;
-[!-]*)
if [[ "$1" =~ ^-[bacdekKnqst]*[NrRu]$ ]] && (( $# >= 2 )); then
options+=("$1" "$2")
shift 2
elif [[ "$1" =~ ^(-[bacdekKnqst]*)o(.*)$ ]]; then
if (( ${#BASH_REMATCH[1]} > 1 )); then
options+=("${BASH_REMATCH[1]}")
fi
if (( ${#BASH_REMATCH[2]} > 0 )); then
set_output "${BASH_REMATCH[2]}"
shift
elif (( $# >= 2 )); then
set_output "$2"
shift 2
else
printf 'Missing argument to -o\n' >&2
exit 1
fi
else # if $# is too small, let qubes-gpg-client error out
options+=("$1")
shift
fi
;;
--)
eoo=1
options+=("$1")
shift
;;
*)
options+=("$1")
shift
;;
esac
else
if ((special_filenames)) && [[ "$1" = "-&"* ]]; then
options+=("/proc/self/fd/${1#-&}")
else
options+=("$1")
fi
shift
fi
done
if [[ "$localgpg" -eq 1 ]]
then
exec /usr/bin/gpg "${origargs[@]}"
exit $?
fi
. /etc/profile.d/qubes-gpg.sh
if ((output)); then
if [[ "$target" != '-' ]]; then exec > "$target"; fi
exec qubes-gpg-client -o- "${options[@]}"
else
exec qubes-gpg-client "${options[@]}"
fi