0
|
1 #!/bin/sh
|
|
2 #
|
|
3 # Generates a PHP file containing the keyring state and various PGP data blobs
|
|
4 # required by Crypt_GPG unit tests.
|
|
5 #
|
|
6 # Running this script will require a lot of system entropy. Installing an
|
|
7 # entropy generator like 'randomsound' is recommended.
|
|
8 #
|
|
9 # Copyright (c) 2008 Michael Gauthier
|
|
10 #
|
|
11
|
|
12 HOMEDIR=`pwd`"/test-keyring"
|
|
13 GPG="gpg --homedir $HOMEDIR --no-secmem --no-permission-warning --quiet --no-greeting"
|
|
14 DATA="Hello, Alice! Goodbye, Bob!"
|
|
15
|
|
16 echo "Creating key homedir"
|
|
17 mkdir $HOMEDIR
|
|
18
|
|
19 # create temp files for signing
|
|
20 cp test-file-small $HOMEDIR/clearsigned-data
|
|
21 cp test-file-small $HOMEDIR/detached-signature
|
|
22 cp test-file-small $HOMEDIR/normal-signed-data
|
|
23 cp test-file-small $HOMEDIR/dual-clearsigned-data
|
|
24 cp test-file-small $HOMEDIR/dual-detached-signature
|
|
25 cp test-file-small $HOMEDIR/dual-normal-signed-data
|
|
26
|
|
27 # create temp files for encrypting
|
|
28 cp test-file-medium $HOMEDIR/encrypted-data-file
|
|
29 cp test-file-medium $HOMEDIR/encrypted-data-no-passphrase-file
|
|
30 cp test-file-medium $HOMEDIR/encrypted-data-missing-key-file
|
|
31 cp test-file-medium $HOMEDIR/dual-encrypted-data-file
|
|
32 cp test-file-medium $HOMEDIR/dual-encrypted-data-one-passphrase-file
|
|
33
|
|
34 # BUILDING KEYS
|
|
35
|
|
36 # second-keypair@example.com
|
|
37 echo "Creating first-keypair@example.com"
|
|
38 echo "1
|
|
39 2048
|
|
40 0
|
|
41 First Keypair Test Key
|
|
42 first-keypair@example.com
|
|
43 do not encrypt important data with this key
|
|
44 test1
|
|
45 " | $GPG --command-fd 0 --gen-key
|
|
46
|
|
47 # second-keypair@example.com
|
|
48 echo "Creating second-keypair@example.com"
|
|
49 echo "1
|
|
50 2048
|
|
51 0
|
|
52 Second Keypair Test Key
|
|
53 second-keypair@example.com
|
|
54 do not encrypt important data with this key
|
|
55 test2
|
|
56 " | $GPG --command-fd 0 --gen-key
|
|
57
|
|
58 # public-only@example.com
|
|
59 echo "Creating public-only@example.com"
|
|
60 echo "1
|
|
61 2048
|
|
62 0
|
|
63 Public Only Test Key
|
|
64 public-only@example.com
|
|
65 do not encrypt important data with this key
|
|
66 test
|
|
67 " | $GPG --command-fd 0 --gen-key
|
|
68
|
|
69 # no-passphrase@example.com
|
|
70 echo "Creating no-passphrase@example.com"
|
|
71 echo "1
|
|
72 2048
|
|
73 0
|
|
74 No Passphrase Public and Private Test Key
|
|
75 no-passphrase@example.com
|
|
76 do not encrypt important data with this key
|
|
77
|
|
78 " | $GPG --command-fd 0 --gen-key
|
|
79
|
|
80 # external-public@example.com
|
|
81 echo "Creating external-public@example.com"
|
|
82 echo "1
|
|
83 2048
|
|
84 0
|
|
85 External Public Key
|
|
86 external-public@example.com
|
|
87 do not encrypt important data with this key
|
|
88 test
|
|
89 " | $GPG --command-fd 0 --gen-key
|
|
90
|
|
91 # missing-key@example.com
|
|
92 echo "Creating missing-key@example.com"
|
|
93 echo "1
|
|
94 2048
|
|
95 0
|
|
96 Missing Key
|
|
97 missing-key@example.com
|
|
98 do not encrypt important data with this key
|
|
99 test
|
|
100 " | $GPG --command-fd 0 --gen-key
|
|
101
|
|
102 # DONE BUILDING KEYS
|
|
103
|
|
104 # BUILDING FILES
|
|
105
|
|
106 # encrypted-data.asc
|
|
107 echo "generating encrypted-data.asc"
|
|
108 echo -n $DATA | $GPG \
|
|
109 --recipient first-keypair@example.com \
|
|
110 --armor \
|
|
111 --encrypt > $HOMEDIR/encrypted-data.asc
|
|
112
|
|
113 # normal-signed-data.asc
|
|
114 echo "generating normal-signed-data.asc"
|
|
115 echo "test1" | $GPG \
|
|
116 --command-fd 0 \
|
|
117 --armor \
|
|
118 --local-user first-keypair@example.com \
|
|
119 --sign $HOMEDIR/normal-signed-data
|
|
120
|
|
121 # clearsigned-data.asc
|
|
122 echo "generating clearsigned-data.asc"
|
|
123 echo "test1" | $GPG \
|
|
124 --command-fd 0 \
|
|
125 --armor \
|
|
126 --local-user first-keypair@example.com \
|
|
127 --clearsign $HOMEDIR/clearsigned-data
|
|
128
|
|
129 # detached-signature.asc
|
|
130 echo "generating detached-signature.asc"
|
|
131 echo "test1" | $GPG \
|
|
132 --command-fd 0 \
|
|
133 --armor \
|
|
134 --local-user first-keypair@example.com \
|
|
135 --detach-sign $HOMEDIR/detached-signature
|
|
136
|
|
137 # dual-encrypted-data@example.com
|
|
138 echo "generating dual-encrypted-data.asc"
|
|
139 echo -n $DATA | $GPG \
|
|
140 --recipient first-keypair@example.com \
|
|
141 --recipient second-keypair@example.com \
|
|
142 --armor \
|
|
143 --encrypt > $HOMEDIR/dual-encrypted-data.asc
|
|
144
|
|
145 # dual-normal-signed-data.asc
|
|
146 echo "generating dual-normal-signed-data.asc"
|
|
147 echo "test1
|
|
148 test2" | $GPG \
|
|
149 --command-fd 0 \
|
|
150 --armor \
|
|
151 --local-user second-keypair@example.com \
|
|
152 --local-user first-keypair@example.com \
|
|
153 --sign $HOMEDIR/dual-normal-signed-data
|
|
154
|
|
155 # dual-clearsigned-data.asc
|
|
156 echo "generating dual-clearsigned-data.asc"
|
|
157 echo "test1
|
|
158 test2" | $GPG \
|
|
159 --command-fd 0 \
|
|
160 --armor \
|
|
161 --local-user second-keypair@example.com \
|
|
162 --local-user first-keypair@example.com \
|
|
163 --clearsign $HOMEDIR/dual-clearsigned-data
|
|
164
|
|
165 # dual-detached-signature.asc
|
|
166 echo "generating dual-detached-signature.asc"
|
|
167 echo "test1
|
|
168 test2" | $GPG \
|
|
169 --command-fd 0 \
|
|
170 --armor \
|
|
171 --local-user second-keypair@example.com \
|
|
172 --local-user first-keypair@example.com \
|
|
173 --detach-sign $HOMEDIR/dual-detached-signature
|
|
174
|
|
175 # public-only-sec.asc
|
|
176 echo "generating public-only-sec.asc"
|
|
177 $GPG \
|
|
178 --armor \
|
|
179 --export-secret-keys public-only@example.com > $HOMEDIR/public-only-sec.asc
|
|
180
|
|
181 # public-only-pub.asc
|
|
182 echo "generating public-only-pub.asc"
|
|
183 $GPG \
|
|
184 --armor \
|
|
185 --export public-only@example.com > $HOMEDIR/public-only-pub.asc
|
|
186
|
|
187 # delete public-only@example.com secret key
|
|
188 echo "deleting secret key for public-only@example.com"
|
|
189 echo "y" | $GPG \
|
|
190 --command-fd 0 \
|
|
191 --delete-secret-key public-only@example.com
|
|
192
|
|
193 # encrypted-data.asc
|
|
194 echo "generating encrypted-data.asc"
|
|
195 echo -n $DATA | $GPG \
|
|
196 --recipient first-keypair@example.com \
|
|
197 --armor \
|
|
198 --encrypt > $HOMEDIR/encrypted-data.asc
|
|
199
|
|
200 # encrypted-data-file.asc
|
|
201 echo "generating encrypted-data-file.asc"
|
|
202 $GPG \
|
|
203 --recipient first-keypair@example.com \
|
|
204 --armor \
|
|
205 --encrypt $HOMEDIR/encrypted-data-file
|
|
206
|
|
207 # encrypted-data-no-passphrase.asc
|
|
208 echo "generating encrypted-data-no-passphrase.asc"
|
|
209 echo -n $DATA | $GPG \
|
|
210 --recipient no-passphrase@example.com \
|
|
211 --armor \
|
|
212 --encrypt > $HOMEDIR/encrypted-data-no-passphrase.asc
|
|
213
|
|
214 # encrypted-data-no-passphrase-file.asc
|
|
215 echo "generating encrypted-data-no-passphrase-file.asc"
|
|
216 $GPG \
|
|
217 --recipient no-passphrase@example.com \
|
|
218 --armor \
|
|
219 --encrypt $HOMEDIR/encrypted-data-no-passphrase-file
|
|
220
|
|
221 # dual-encrypted-data-one-passphrase.asc
|
|
222 echo "generating dual-encrypted-data-one-passphrase.asc"
|
|
223 echo -n $DATA | $GPG \
|
|
224 --recipient first-keypair@example.com \
|
|
225 --recipient no-passphrase@example.com \
|
|
226 --armor \
|
|
227 --encrypt > $HOMEDIR/dual-encrypted-data-one-passphrase.asc
|
|
228
|
|
229 # dual-encrypted-data-one-passphrase-file.asc
|
|
230 echo "generating dual-encrypted-data-one-passphrase-file.asc"
|
|
231 $GPG \
|
|
232 --recipient first-keypair@example.com \
|
|
233 --recipient no-passphrase@example.com \
|
|
234 --armor \
|
|
235 --encrypt $HOMEDIR/dual-encrypted-data-one-passphrase-file
|
|
236
|
|
237 # delete external-public@example.com secret key
|
|
238 echo "deleting secret key for external-public@example.com"
|
|
239 echo "y" | $GPG \
|
|
240 --command-fd 0 \
|
|
241 --delete-secret-key external-public@example.com
|
|
242
|
|
243 # external-public-pub.asc
|
|
244 echo "generating external-public-pub.asc"
|
|
245 $GPG \
|
|
246 --armor \
|
|
247 --export external-public@example.com > $HOMEDIR/external-public-pub.asc
|
|
248
|
|
249 # delete external-public@example.com key
|
|
250 echo "deleting key external-public@example.com"
|
|
251 echo "y" | $GPG \
|
|
252 --command-fd 0 \
|
|
253 --delete-secret-and-public-key external-public@example.com
|
|
254
|
|
255 # encrypted-data-missing-key.asc
|
|
256 echo "generating encrypted-data-missing-key.asc"
|
|
257 echo -n $DATA | $GPG \
|
|
258 --recipient missing-key@example.com \
|
|
259 --armor \
|
|
260 --encrypt > $HOMEDIR/encrypted-data-missing-key.asc
|
|
261
|
|
262 # encrypted-data-missing-key-file.asc
|
|
263 echo "generating encrypted-data-missing-key-file.asc"
|
|
264 $GPG \
|
|
265 --recipient missing-key@example.com \
|
|
266 --armor \
|
|
267 --encrypt $HOMEDIR/encrypted-data-missing-key-file
|
|
268
|
|
269 # delete missing-key@example.com key
|
|
270 echo "deleting key missing-key@example.com"
|
|
271 echo "y" | $GPG \
|
|
272 --command-fd 0 \
|
|
273 --delete-secret-and-public-key missing-key@example.com
|
|
274
|
|
275 # DONE BUILDING FILES
|
|
276
|
|
277 echo "dumping keyring state"
|
|
278 php -f build-keyring.php $HOMEDIR > keyring-dump.php
|
|
279
|
|
280 echo "removing key homedir"
|
|
281 rm -rf $HOMEDIR
|