Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/VerifyTest.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 <?php | |
2 | |
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
4 | |
5 /** | |
6 * Verify tests for the Crypt_GPG package. | |
7 * | |
8 * These tests require the PHPUnit 3.6 or greater package to be installed. | |
9 * PHPUnit is installable using PEAR. See the | |
10 * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual} | |
11 * for detailed installation instructions. | |
12 * | |
13 * To run these tests, use: | |
14 * <code> | |
15 * $ phpunit VerifyTestCase | |
16 * </code> | |
17 * | |
18 * LICENSE: | |
19 * | |
20 * This library is free software; you can redistribute it and/or modify | |
21 * it under the terms of the GNU Lesser General Public License as | |
22 * published by the Free Software Foundation; either version 2.1 of the | |
23 * License, or (at your option) any later version. | |
24 * | |
25 * This library is distributed in the hope that it will be useful, | |
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
28 * Lesser General Public License for more details. | |
29 * | |
30 * You should have received a copy of the GNU Lesser General Public | |
31 * License along with this library; if not, see | |
32 * <http://www.gnu.org/licenses/> | |
33 * | |
34 * @category Encryption | |
35 * @package Crypt_GPG | |
36 * @author Michael Gauthier <mike@silverorange.com> | |
37 * @copyright 2005-2008 silverorange | |
38 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
39 * @version CVS: $Id$ | |
40 * @link http://pear.php.net/package/Crypt_GPG | |
41 */ | |
42 | |
43 /** | |
44 * Base test case. | |
45 */ | |
46 require_once 'TestCase.php'; | |
47 | |
48 /** | |
49 * Tests verification abilities of Crypt_GPG. | |
50 * | |
51 * @category Encryption | |
52 * @package Crypt_GPG | |
53 * @author Michael Gauthier <mike@silverorange.com> | |
54 * @copyright 2005-2008 silverorange | |
55 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
56 * @link http://pear.php.net/package/Crypt_GPG | |
57 */ | |
58 class VerifyTestCase extends Crypt_GPG_TestCase | |
59 { | |
60 // string | |
61 // {{{ testVerifyNoDataException_invalid() | |
62 | |
63 /** | |
64 * @expectedException Crypt_GPG_NoDataException | |
65 * | |
66 * @group string | |
67 */ | |
68 public function testVerifyNoDataException_invalid() | |
69 { | |
70 $signedData = 'Invalid OpenPGP data.'; | |
71 $this->gpg->verify($signedData); | |
72 } | |
73 | |
74 // }}} | |
75 // {{{ testVerifyNoDataException_empty() | |
76 | |
77 /** | |
78 * @expectedException Crypt_GPG_NoDataException | |
79 * | |
80 * @group string | |
81 */ | |
82 public function testVerifyNoDataException_empty() | |
83 { | |
84 $signedData = ''; | |
85 $this->gpg->verify($signedData); | |
86 } | |
87 | |
88 // }}} | |
89 // {{{ testVerifyKeyNotFoundException() | |
90 | |
91 /** | |
92 * @expectedException Crypt_GPG_KeyNotFoundException | |
93 * | |
94 * @group string | |
95 */ | |
96 public function testVerifyKeyNotFoundException() | |
97 { | |
98 $data = 'Hello, Alice! Goodbye, Bob!'; | |
99 // {{{ detached signature | |
100 $detachedSignature = <<<TEXT | |
101 -----BEGIN PGP SIGNATURE----- | |
102 Version: GnuPG v1.4.6 (GNU/Linux) | |
103 | |
104 iD8DBQBI1xN9CuJ9bDb23VARAkKSAKCG5/jPq1H7+mpMEpDITFnAJhSqlwCggzRx | |
105 laNWOZOef2zfm1yANtWjPyU= | |
106 =fhME | |
107 -----END PGP SIGNATURE----- | |
108 | |
109 TEXT; | |
110 // }}} | |
111 $this->gpg->verify($data, $detachedSignature); | |
112 } | |
113 | |
114 // }}} | |
115 // {{{ testVerifyNormalSignedData() | |
116 | |
117 /** | |
118 * @group string | |
119 */ | |
120 public function testVerifyNormalSignedData() | |
121 { | |
122 // {{{ signature | |
123 $signature = new Crypt_GPG_Signature(); | |
124 $signature->setId('KuhELanvhPRXozEjFWb2mam1q20'); | |
125 $signature->setKeyFingerprint( | |
126 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
127 | |
128 $signature->setKeyId('C097D9EC94C06363'); | |
129 $signature->setCreationDate(1221785858); | |
130 $signature->setExpirationDate(0); | |
131 $signature->setValid(true); | |
132 | |
133 $userId = new Crypt_GPG_UserId(); | |
134 $userId->setName('First Keypair Test Key'); | |
135 $userId->setComment('do not encrypt important data with this key'); | |
136 $userId->setEmail('first-keypair@example.com'); | |
137 $signature->setUserId($userId); | |
138 // }}} | |
139 // {{{ normal signed data | |
140 $normalSignedData = <<<TEXT | |
141 -----BEGIN PGP MESSAGE----- | |
142 Version: GnuPG v1.4.6 (GNU/Linux) | |
143 | |
144 owGbwMvMwCR4YPrNN1MOJCczrjFOEsrLL8pNzNEtzkzPS03RTUksSfS49JPJIzUn | |
145 J19HwTEnMzlVUcE9Pz8lqTJVR8EpP0mxw56ZlQGkBmaMIJO9GsOCo2L3pk5y2DNT | |
146 yiFKb0X03YSJqscaGRb0BKjZ3P+6SvjG160/WOa9vpey4QUDAA== | |
147 =wtCB | |
148 -----END PGP MESSAGE----- | |
149 | |
150 TEXT; | |
151 // }}} | |
152 | |
153 $expectedSignatures = array($signature); | |
154 | |
155 $signatures = $this->gpg->verify($normalSignedData); | |
156 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
157 } | |
158 | |
159 // }}} | |
160 // {{{ testVerifyClearsignedData() | |
161 | |
162 /** | |
163 * @group string | |
164 */ | |
165 public function testVerifyClearsignedData() | |
166 { | |
167 // {{{ signature | |
168 $signature = new Crypt_GPG_Signature(); | |
169 $signature->setId('wwm5gqNiFS+E/tmqbt1uXvVy3Ck'); | |
170 $signature->setKeyFingerprint( | |
171 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
172 | |
173 $signature->setKeyId('C097D9EC94C06363'); | |
174 $signature->setCreationDate(1221785858); | |
175 $signature->setExpirationDate(0); | |
176 $signature->setValid(true); | |
177 | |
178 $userId = new Crypt_GPG_UserId(); | |
179 $userId->setName('First Keypair Test Key'); | |
180 $userId->setComment('do not encrypt important data with this key'); | |
181 $userId->setEmail('first-keypair@example.com'); | |
182 $signature->setUserId($userId); | |
183 // }}} | |
184 // {{{ clearsigned data | |
185 $clearsignedData = <<<TEXT | |
186 -----BEGIN PGP SIGNED MESSAGE----- | |
187 Hash: SHA1 | |
188 | |
189 Hello, Alice! Goodbye, Bob! | |
190 -----BEGIN PGP SIGNATURE----- | |
191 Version: GnuPG v1.4.6 (GNU/Linux) | |
192 | |
193 iD8DBQFI0vkCwJfZ7JTAY2MRAgzTAKCRecYZsCS+PE46Fa2QLTEP8XGLwwCfQEAL | |
194 qO+KlKcldtYdMZH9AA+KOLQ= | |
195 =EO2G | |
196 -----END PGP SIGNATURE----- | |
197 | |
198 TEXT; | |
199 // }}} | |
200 | |
201 $expectedSignatures = array($signature); | |
202 | |
203 $signatures = $this->gpg->verify($clearsignedData); | |
204 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
205 } | |
206 | |
207 // }}} | |
208 // {{{ testVerifyDetachedSignature() | |
209 | |
210 /** | |
211 * @group string | |
212 */ | |
213 public function testVerifyDetachedSignature() | |
214 { | |
215 $data = 'Hello, Alice! Goodbye, Bob!'; | |
216 | |
217 // {{{ signature | |
218 $signature = new Crypt_GPG_Signature(); | |
219 $signature->setId('E4HEDmMtecF457JFb88UAtPBVWY'); | |
220 $signature->setKeyFingerprint( | |
221 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
222 | |
223 $signature->setKeyId('C097D9EC94C06363'); | |
224 $signature->setCreationDate(1221785858); | |
225 $signature->setExpirationDate(0); | |
226 $signature->setValid(true); | |
227 | |
228 $userId = new Crypt_GPG_UserId(); | |
229 $userId->setName('First Keypair Test Key'); | |
230 $userId->setComment('do not encrypt important data with this key'); | |
231 $userId->setEmail('first-keypair@example.com'); | |
232 $signature->setUserId($userId); | |
233 // }}} | |
234 // {{{ detached signature | |
235 $detachedSignature = <<<TEXT | |
236 -----BEGIN PGP SIGNATURE----- | |
237 Version: GnuPG v1.4.6 (GNU/Linux) | |
238 | |
239 iD8DBQBI0vkCwJfZ7JTAY2MRAj8mAKC4IN01tGaEtNxWYS5eQiNT4Fua9ACeKum3 | |
240 BdQ5rTOK2pp2X2vy/k2aCPo= | |
241 =upYI | |
242 -----END PGP SIGNATURE----- | |
243 | |
244 TEXT; | |
245 // }}} | |
246 | |
247 $expectedSignatures = array($signature); | |
248 | |
249 $signatures = $this->gpg->verify($data, $detachedSignature); | |
250 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
251 } | |
252 | |
253 // }}} | |
254 // {{{ testVerifyDualNormalSignedData() | |
255 | |
256 /** | |
257 * @group string | |
258 */ | |
259 public function testVerifyDualNormalSignedData() | |
260 { | |
261 // {{{ first signature | |
262 $firstSignature = new Crypt_GPG_Signature(); | |
263 $firstSignature->setId('4BunvSK18HPx6Xt4tEzyAqcNVzY'); | |
264 $firstSignature->setKeyFingerprint( | |
265 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
266 | |
267 $firstSignature->setKeyId('03CC890AFA1DAD4B'); | |
268 $firstSignature->setCreationDate(1221785858); | |
269 $firstSignature->setExpirationDate(0); | |
270 $firstSignature->setValid(true); | |
271 | |
272 $userId = new Crypt_GPG_UserId(); | |
273 $userId->setName('Second Keypair Test Key'); | |
274 $userId->setComment('do not encrypt important data with this key'); | |
275 $userId->setEmail('second-keypair@example.com'); | |
276 $firstSignature->setUserId($userId); | |
277 // }}} | |
278 // {{{ second signature | |
279 $secondSignature = new Crypt_GPG_Signature(); | |
280 $secondSignature->setId('oAZ64v4sFarc7dssFOAJPB0D7zs'); | |
281 $secondSignature->setKeyFingerprint( | |
282 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
283 | |
284 $secondSignature->setKeyId('C097D9EC94C06363'); | |
285 $secondSignature->setCreationDate(1221785858); | |
286 $secondSignature->setExpirationDate(0); | |
287 $secondSignature->setValid(true); | |
288 | |
289 $userId = new Crypt_GPG_UserId(); | |
290 $userId->setName('First Keypair Test Key'); | |
291 $userId->setComment('do not encrypt important data with this key'); | |
292 $userId->setEmail('first-keypair@example.com'); | |
293 $secondSignature->setUserId($userId); | |
294 // }}} | |
295 // {{{ dual normal signed data | |
296 $dualNormalSignedData = <<<TEXT | |
297 -----BEGIN PGP MESSAGE----- | |
298 Version: GnuPG v1.4.6 (GNU/Linux) | |
299 | |
300 owGbwMvMwCR4YPrNN1MOJCczTABzmc90cv2SXevNuMYiSTylNDFHNy+/KBdIFWem | |
301 56Wm6KYkliR6XPrJ5JGak5Ovo+CYk5mcqqjgnp+fklSZqqPglJ+k2GHPzMoAUgMz | |
302 S5DJXo1hns0D5bkxpVHbI8+1y866l6K4yE1vHcNcOS1T45mf+VMn1NxQnnVn3Uab | |
303 dx7z4AbA3AY2YMGDvnnpCe982TwPTGyZdn+fMbu0fQDDgn098wSP/O79+/aYgon9 | |
304 y/y/MVtYcwE= | |
305 =7EC6 | |
306 -----END PGP MESSAGE----- | |
307 | |
308 TEXT; | |
309 // }}} | |
310 | |
311 $expectedSignatures = array($firstSignature, $secondSignature); | |
312 | |
313 $signatures = $this->gpg->verify($dualNormalSignedData); | |
314 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
315 } | |
316 | |
317 // }}} | |
318 // {{{ testVerifyDualClearsignedData() | |
319 | |
320 /** | |
321 * @group string | |
322 */ | |
323 public function testVerifyDualClearsignedData() | |
324 { | |
325 // {{{ first signature | |
326 $firstSignature = new Crypt_GPG_Signature(); | |
327 $firstSignature->setId('MCn4/0Giq0njPh2smOs3Lrdc7yY'); | |
328 $firstSignature->setKeyFingerprint( | |
329 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
330 | |
331 $firstSignature->setKeyId('03CC890AFA1DAD4B'); | |
332 $firstSignature->setCreationDate(1221785858); | |
333 $firstSignature->setExpirationDate(0); | |
334 $firstSignature->setValid(true); | |
335 | |
336 $userId = new Crypt_GPG_UserId(); | |
337 $userId->setName('Second Keypair Test Key'); | |
338 $userId->setComment('do not encrypt important data with this key'); | |
339 $userId->setEmail('second-keypair@example.com'); | |
340 $firstSignature->setUserId($userId); | |
341 // }}} | |
342 // {{{ second signature | |
343 $secondSignature = new Crypt_GPG_Signature(); | |
344 $secondSignature->setId('O5tcpOAXJhd0v5TBxqhIixgphn8'); | |
345 $secondSignature->setKeyFingerprint( | |
346 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
347 | |
348 $secondSignature->setKeyId('C097D9EC94C06363'); | |
349 $secondSignature->setCreationDate(1221785858); | |
350 $secondSignature->setExpirationDate(0); | |
351 $secondSignature->setValid(true); | |
352 | |
353 $userId = new Crypt_GPG_UserId(); | |
354 $userId->setName('First Keypair Test Key'); | |
355 $userId->setComment('do not encrypt important data with this key'); | |
356 $userId->setEmail('first-keypair@example.com'); | |
357 $secondSignature->setUserId($userId); | |
358 // }}} | |
359 // {{{ dual clearsigned data | |
360 $dualClearsignedData = <<<TEXT | |
361 -----BEGIN PGP SIGNED MESSAGE----- | |
362 Hash: SHA1 | |
363 | |
364 Hello, Alice! Goodbye, Bob! | |
365 -----BEGIN PGP SIGNATURE----- | |
366 Version: GnuPG v1.4.6 (GNU/Linux) | |
367 | |
368 iD8DBQFI0vkCA8yJCvodrUsRAgzTAJ9xSosvdq3fqaseRS6YV9VgnSGo2gCgiD+2 | |
369 TRUrY67ZzdfTjCd6cFZHqauIPwMFAUjS+QLAl9nslMBjYxECDNMAoKdQQAWe8EwG | |
370 kZ/cCDE/fgToHk+7AJ9sU0NweUfUP3KNe2UK808Epd0Avg== | |
371 =j0ot | |
372 -----END PGP SIGNATURE----- | |
373 | |
374 TEXT; | |
375 // }}} | |
376 | |
377 $expectedSignatures = array($firstSignature, $secondSignature); | |
378 | |
379 $signatures = $this->gpg->verify($dualClearsignedData); | |
380 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
381 } | |
382 | |
383 // }}} | |
384 // {{{ testVerifyDualDetachedSignature() | |
385 | |
386 /** | |
387 * @group string | |
388 */ | |
389 public function testVerifyDualDetachedSignature() | |
390 { | |
391 $data = 'Hello, Alice! Goodbye, Bob!'; | |
392 | |
393 // {{{ first signature | |
394 $firstSignature = new Crypt_GPG_Signature(); | |
395 $firstSignature->setId('tejKd9+9OBUM+EsrbV3fVuOiBeE'); | |
396 $firstSignature->setKeyFingerprint( | |
397 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
398 | |
399 $firstSignature->setKeyId('03CC890AFA1DAD4B'); | |
400 $firstSignature->setCreationDate(1221785858); | |
401 $firstSignature->setExpirationDate(0); | |
402 $firstSignature->setValid(true); | |
403 | |
404 $userId = new Crypt_GPG_UserId(); | |
405 $userId->setName('Second Keypair Test Key'); | |
406 $userId->setComment('do not encrypt important data with this key'); | |
407 $userId->setEmail('second-keypair@example.com'); | |
408 $firstSignature->setUserId($userId); | |
409 // }}} | |
410 // {{{ second signature | |
411 $secondSignature = new Crypt_GPG_Signature(); | |
412 $secondSignature->setId('7oizks/aha+bSONesnWDu1x2jn8'); | |
413 $secondSignature->setKeyFingerprint( | |
414 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
415 | |
416 $secondSignature->setKeyId('C097D9EC94C06363'); | |
417 $secondSignature->setCreationDate(1221785858); | |
418 $secondSignature->setExpirationDate(0); | |
419 $secondSignature->setValid(true); | |
420 | |
421 $userId = new Crypt_GPG_UserId(); | |
422 $userId->setName('First Keypair Test Key'); | |
423 $userId->setComment('do not encrypt important data with this key'); | |
424 $userId->setEmail('first-keypair@example.com'); | |
425 $secondSignature->setUserId($userId); | |
426 // }}} | |
427 // {{{ dual detached signature | |
428 $dualDetachedSignature = <<<TEXT | |
429 -----BEGIN PGP SIGNATURE----- | |
430 Version: GnuPG v1.4.6 (GNU/Linux) | |
431 | |
432 iD8DBQBI0vkCA8yJCvodrUsRAj8mAKCJWz3ANeG9SPGUHMg04gH0rCOqKwCfaxUR | |
433 Dypdcanj3VE3inTxleaQtdqIPwMFAEjS+QLAl9nslMBjYxECPyYAoN+Y3tibHIg+ | |
434 9+fdvxAEvANir2RQAKCuD2BsKzSmyV3G4/i6oPNhOrwtPg== | |
435 =8P1D | |
436 -----END PGP SIGNATURE----- | |
437 | |
438 TEXT; | |
439 // }}} | |
440 | |
441 $expectedSignatures = array($firstSignature, $secondSignature); | |
442 | |
443 $signatures = $this->gpg->verify($data, $dualDetachedSignature); | |
444 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
445 } | |
446 | |
447 // }}} | |
448 // {{{ testVerifyBadSignature() | |
449 | |
450 /** | |
451 * @group string | |
452 */ | |
453 public function testVerifyBadSignature() | |
454 { | |
455 $modifiedData = 'Hello, Bob! Goodbye, Alice!'; | |
456 | |
457 // {{{ signature | |
458 $signature = new Crypt_GPG_Signature(); | |
459 $signature->setKeyId('C097D9EC94C06363'); | |
460 $signature->setValid(false); | |
461 $userId = new Crypt_GPG_UserId(); | |
462 $userId->setName('First Keypair Test Key'); | |
463 $userId->setComment('do not encrypt important data with this key'); | |
464 $userId->setEmail('first-keypair@example.com'); | |
465 $signature->setUserId($userId); | |
466 // }}} | |
467 // {{{ detached signature | |
468 $detachedSignature = <<<TEXT | |
469 -----BEGIN PGP SIGNATURE----- | |
470 Version: GnuPG v1.4.6 (GNU/Linux) | |
471 | |
472 iD8DBQBI0vkCwJfZ7JTAY2MRAj8mAKC4IN01tGaEtNxWYS5eQiNT4Fua9ACeKum3 | |
473 BdQ5rTOK2pp2X2vy/k2aCPo= | |
474 =upYI | |
475 -----END PGP SIGNATURE----- | |
476 | |
477 TEXT; | |
478 // }}} | |
479 | |
480 $expectedSignatures = array($signature); | |
481 | |
482 $signatures = $this->gpg->verify($modifiedData, $detachedSignature); | |
483 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
484 } | |
485 | |
486 // }}} | |
487 // {{{ testVerifyDualBadSignatures() | |
488 | |
489 /** | |
490 * @group string | |
491 */ | |
492 public function testVerifyDualBadSignatures() | |
493 { | |
494 $modifiedData = 'Hello, Bob! Goodbye, Alice!'; | |
495 | |
496 // {{{ first signature | |
497 $firstSignature = new Crypt_GPG_Signature(); | |
498 $firstSignature->setExpirationDate(0); | |
499 $firstSignature->setValid(false); | |
500 $firstSignature->setKeyId('03CC890AFA1DAD4B'); | |
501 $userId = new Crypt_GPG_UserId(); | |
502 $userId->setName('Second Keypair Test Key'); | |
503 $userId->setComment('do not encrypt important data with this key'); | |
504 $userId->setEmail('second-keypair@example.com'); | |
505 $firstSignature->setUserId($userId); | |
506 // }}} | |
507 // {{{ second signature | |
508 $secondSignature = new Crypt_GPG_Signature(); | |
509 $secondSignature->setValid(false); | |
510 $secondSignature->setKeyId('C097D9EC94C06363'); | |
511 $userId = new Crypt_GPG_UserId(); | |
512 $userId->setName('First Keypair Test Key'); | |
513 $userId->setComment('do not encrypt important data with this key'); | |
514 $userId->setEmail('first-keypair@example.com'); | |
515 $secondSignature->setUserId($userId); | |
516 // }}} | |
517 // {{{ dual detached signature | |
518 $dualDetachedSignature = <<<TEXT | |
519 -----BEGIN PGP SIGNATURE----- | |
520 Version: GnuPG v1.4.6 (GNU/Linux) | |
521 | |
522 iD8DBQBI0vkCA8yJCvodrUsRAj8mAKCJWz3ANeG9SPGUHMg04gH0rCOqKwCfaxUR | |
523 Dypdcanj3VE3inTxleaQtdqIPwMFAEjS+QLAl9nslMBjYxECPyYAoN+Y3tibHIg+ | |
524 9+fdvxAEvANir2RQAKCuD2BsKzSmyV3G4/i6oPNhOrwtPg== | |
525 =8P1D | |
526 -----END PGP SIGNATURE----- | |
527 | |
528 TEXT; | |
529 // }}} | |
530 | |
531 $expectedSignatures = array($firstSignature, $secondSignature); | |
532 | |
533 $signatures = $this->gpg->verify($modifiedData, $dualDetachedSignature); | |
534 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
535 } | |
536 | |
537 // }}} | |
538 // {{{ testVerifyFileNormalSignedData() | |
539 | |
540 /** | |
541 * @group file | |
542 */ | |
543 public function testVerifyFileNormalSignedData() | |
544 { | |
545 // {{{ signature | |
546 $signature = new Crypt_GPG_Signature(); | |
547 $signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU'); | |
548 $signature->setKeyFingerprint( | |
549 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
550 | |
551 $signature->setKeyId('C097D9EC94C06363'); | |
552 $signature->setCreationDate(1221960707); | |
553 $signature->setExpirationDate(0); | |
554 $signature->setValid(true); | |
555 | |
556 $userId = new Crypt_GPG_UserId(); | |
557 $userId->setName('First Keypair Test Key'); | |
558 $userId->setComment('do not encrypt important data with this key'); | |
559 $userId->setEmail('first-keypair@example.com'); | |
560 $signature->setUserId($userId); | |
561 // }}} | |
562 | |
563 $expectedSignatures = array($signature); | |
564 | |
565 $filename = | |
566 $this->getDataFilename('testVerifyFileNormalSignedData.asc'); | |
567 | |
568 $signatures = $this->gpg->verifyFile($filename); | |
569 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
570 } | |
571 | |
572 // }}} | |
573 // {{{ testVerifyFileClearsignedData() | |
574 | |
575 /** | |
576 * @group file | |
577 */ | |
578 public function testVerifyFileClearsignedData() | |
579 { | |
580 // {{{ signature | |
581 $signature = new Crypt_GPG_Signature(); | |
582 $signature->setId('6sXJXKZB5lvRSCXBAYl6R2EiDmw'); | |
583 $signature->setKeyFingerprint( | |
584 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
585 | |
586 $signature->setKeyId('C097D9EC94C06363'); | |
587 $signature->setCreationDate(1221960707); | |
588 $signature->setExpirationDate(0); | |
589 $signature->setValid(true); | |
590 | |
591 $userId = new Crypt_GPG_UserId(); | |
592 $userId->setName('First Keypair Test Key'); | |
593 $userId->setComment('do not encrypt important data with this key'); | |
594 $userId->setEmail('first-keypair@example.com'); | |
595 $signature->setUserId($userId); | |
596 // }}} | |
597 | |
598 $expectedSignatures = array($signature); | |
599 | |
600 $filename = $this->getDataFilename('testVerifyFileClearsignedData.asc'); | |
601 | |
602 $signatures = $this->gpg->verifyFile($filename); | |
603 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
604 } | |
605 | |
606 // }}} | |
607 // {{{ testVerifyFileDetachedSignature() | |
608 | |
609 /** | |
610 * @group file | |
611 */ | |
612 public function testVerifyFileDetachedSignature() | |
613 { | |
614 // {{{ signature | |
615 $signature = new Crypt_GPG_Signature(); | |
616 $signature->setId('tdsH/ulxOnoWEMPDamZTq7wzF/0'); | |
617 $signature->setKeyFingerprint( | |
618 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
619 | |
620 $signature->setKeyId('C097D9EC94C06363'); | |
621 $signature->setCreationDate(1221960707); | |
622 $signature->setExpirationDate(0); | |
623 $signature->setValid(true); | |
624 | |
625 $userId = new Crypt_GPG_UserId(); | |
626 $userId->setName('First Keypair Test Key'); | |
627 $userId->setComment('do not encrypt important data with this key'); | |
628 $userId->setEmail('first-keypair@example.com'); | |
629 $signature->setUserId($userId); | |
630 // }}} | |
631 // {{{ signatureData | |
632 $signatureData = <<<TEXT | |
633 -----BEGIN PGP SIGNATURE----- | |
634 Version: GnuPG v1.4.6 (GNU/Linux) | |
635 | |
636 iD8DBQBI1aQDwJfZ7JTAY2MRAvkzAJ0RAW0wtlfEgDccgq+N5IgbpA4BOQCfS8vV | |
637 Of32/RcteCLdt73awNJ0CwI= | |
638 =RVco | |
639 -----END PGP SIGNATURE----- | |
640 | |
641 TEXT; | |
642 // }}} | |
643 | |
644 $expectedSignatures = array($signature); | |
645 | |
646 $filename = $this->getDataFilename('testFileMedium.plain'); | |
647 | |
648 $signatures = $this->gpg->verifyFile($filename, $signatureData); | |
649 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
650 } | |
651 | |
652 // }}} | |
653 // {{{ testVerifyFileDualNormalSignedData() | |
654 | |
655 /** | |
656 * @group file | |
657 */ | |
658 public function testVerifyFileDualNormalSignedData() | |
659 { | |
660 // {{{ first signature | |
661 $firstSignature = new Crypt_GPG_Signature(); | |
662 $firstSignature->setId('Kl3Mds4ABT9JyE3iqfPGpUHzKQs'); | |
663 $firstSignature->setKeyFingerprint( | |
664 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
665 | |
666 $firstSignature->setKeyId('C097D9EC94C06363'); | |
667 $firstSignature->setCreationDate(1221960707); | |
668 $firstSignature->setExpirationDate(0); | |
669 $firstSignature->setValid(true); | |
670 | |
671 $userId = new Crypt_GPG_UserId(); | |
672 $userId->setName('First Keypair Test Key'); | |
673 $userId->setComment('do not encrypt important data with this key'); | |
674 $userId->setEmail('first-keypair@example.com'); | |
675 $firstSignature->setUserId($userId); | |
676 // }}} | |
677 // {{{ second signature | |
678 $secondSignature = new Crypt_GPG_Signature(); | |
679 $secondSignature->setId('KGrEm3hGqiKaLbjvOUO9kvUjRXc'); | |
680 $secondSignature->setKeyFingerprint( | |
681 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
682 | |
683 $secondSignature->setKeyId('03CC890AFA1DAD4B'); | |
684 $secondSignature->setCreationDate(1221960707); | |
685 $secondSignature->setExpirationDate(0); | |
686 $secondSignature->setValid(true); | |
687 | |
688 $userId = new Crypt_GPG_UserId(); | |
689 $userId->setName('Second Keypair Test Key'); | |
690 $userId->setComment('do not encrypt important data with this key'); | |
691 $userId->setEmail('second-keypair@example.com'); | |
692 $secondSignature->setUserId($userId); | |
693 // }}} | |
694 | |
695 $expectedSignatures = array($firstSignature, $secondSignature); | |
696 | |
697 $filename = | |
698 $this->getDataFilename('testVerifyFileDualNormalSignedData.asc'); | |
699 | |
700 $signatures = $this->gpg->verifyFile($filename); | |
701 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
702 } | |
703 | |
704 // }}} | |
705 // {{{ testVerifyFileDualClearsignedData() | |
706 | |
707 /** | |
708 * @group file | |
709 */ | |
710 public function testVerifyFileDualClearsignedData() | |
711 { | |
712 // {{{ first signature | |
713 $firstSignature = new Crypt_GPG_Signature(); | |
714 $firstSignature->setId('eRRcEecpFk0YK/iswddS/KBxEXI'); | |
715 $firstSignature->setKeyFingerprint( | |
716 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
717 | |
718 $firstSignature->setKeyId('C097D9EC94C06363'); | |
719 $firstSignature->setCreationDate(1221960707); | |
720 $firstSignature->setExpirationDate(0); | |
721 $firstSignature->setValid(true); | |
722 | |
723 $userId = new Crypt_GPG_UserId(); | |
724 $userId->setName('First Keypair Test Key'); | |
725 $userId->setComment('do not encrypt important data with this key'); | |
726 $userId->setEmail('first-keypair@example.com'); | |
727 $firstSignature->setUserId($userId); | |
728 // }}} | |
729 // {{{ second signature | |
730 $secondSignature = new Crypt_GPG_Signature(); | |
731 $secondSignature->setId('jsWYGJe/0hmte7tYt8zuJd7rFMM'); | |
732 $secondSignature->setKeyFingerprint( | |
733 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
734 | |
735 $secondSignature->setKeyId('03CC890AFA1DAD4B'); | |
736 $secondSignature->setCreationDate(1221960707); | |
737 $secondSignature->setExpirationDate(0); | |
738 $secondSignature->setValid(true); | |
739 | |
740 $userId = new Crypt_GPG_UserId(); | |
741 $userId->setName('Second Keypair Test Key'); | |
742 $userId->setComment('do not encrypt important data with this key'); | |
743 $userId->setEmail('second-keypair@example.com'); | |
744 $secondSignature->setUserId($userId); | |
745 // }}} | |
746 | |
747 $expectedSignatures = array($firstSignature, $secondSignature); | |
748 | |
749 $filename = | |
750 $this->getDataFilename('testVerifyFileDualClearsignedData.asc'); | |
751 | |
752 $signatures = $this->gpg->verifyFile($filename); | |
753 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
754 } | |
755 | |
756 // }}} | |
757 // {{{ testVerifyFileDualDetachedSignature() | |
758 | |
759 /** | |
760 * @group file | |
761 */ | |
762 public function testVerifyFileDualDetachedSignature() | |
763 { | |
764 // {{{ first signature | |
765 $firstSignature = new Crypt_GPG_Signature(); | |
766 $firstSignature->setId('T7+toJbsFr8KMTWN+M7lF3xSmmA'); | |
767 $firstSignature->setKeyFingerprint( | |
768 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
769 | |
770 $firstSignature->setKeyId('C097D9EC94C06363'); | |
771 $firstSignature->setCreationDate(1221960707); | |
772 $firstSignature->setExpirationDate(0); | |
773 $firstSignature->setValid(true); | |
774 | |
775 $userId = new Crypt_GPG_UserId(); | |
776 $userId->setName('First Keypair Test Key'); | |
777 $userId->setComment('do not encrypt important data with this key'); | |
778 $userId->setEmail('first-keypair@example.com'); | |
779 $firstSignature->setUserId($userId); | |
780 // }}} | |
781 // {{{ second signature | |
782 $secondSignature = new Crypt_GPG_Signature(); | |
783 $secondSignature->setId('HJd1yvMbEbW5facuxkDtvwymKrw'); | |
784 $secondSignature->setKeyFingerprint( | |
785 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
786 | |
787 $secondSignature->setKeyId('03CC890AFA1DAD4B'); | |
788 $secondSignature->setCreationDate(1221960707); | |
789 $secondSignature->setExpirationDate(0); | |
790 $secondSignature->setValid(true); | |
791 | |
792 $userId = new Crypt_GPG_UserId(); | |
793 $userId->setName('Second Keypair Test Key'); | |
794 $userId->setComment('do not encrypt important data with this key'); | |
795 $userId->setEmail('second-keypair@example.com'); | |
796 $secondSignature->setUserId($userId); | |
797 // }}} | |
798 // {{{ signature data | |
799 $signatureData = <<<TEXT | |
800 -----BEGIN PGP SIGNATURE----- | |
801 Version: GnuPG v1.4.6 (GNU/Linux) | |
802 | |
803 iD8DBQBI1aQDwJfZ7JTAY2MRAvkzAKDPnJ030GdYE15mE8smz2oV7zYziwCeJFxf | |
804 UaTrAgP1Dck9DhHOBhvhwLuIPwMFAEjVpAMDzIkK+h2tSxEC+TMAn38yx3mXk6wP | |
805 JaPThD7lRVE9ve57AJ0Yy7JwiT9sGXomln4JtRvuSpGtsg== | |
806 =Gw9D | |
807 -----END PGP SIGNATURE----- | |
808 | |
809 TEXT; | |
810 // }}} | |
811 | |
812 $expectedSignatures = array($firstSignature, $secondSignature); | |
813 | |
814 $filename = $this->getDataFilename('testFileMedium.plain'); | |
815 | |
816 $signatures = $this->gpg->verifyFile($filename, $signatureData); | |
817 $this->assertSignaturesEquals($expectedSignatures, $signatures); | |
818 } | |
819 | |
820 // }}} | |
821 // {{{ testVerifyFileFileException() | |
822 | |
823 /** | |
824 * @expectedException Crypt_GPG_FileException | |
825 * | |
826 * @group file | |
827 */ | |
828 public function testVerifyFileFileException() | |
829 { | |
830 $filename = './non-existent/testVerifyFileFileException.asc'; | |
831 $this->gpg->verifyFile($filename); | |
832 } | |
833 | |
834 // }}} | |
835 // {{{ testVerifyFileNoDataException() | |
836 | |
837 /** | |
838 * @expectedException Crypt_GPG_NoDataException | |
839 * | |
840 * @group file | |
841 */ | |
842 public function testVerifyFileNoDataException() | |
843 { | |
844 $filename = $this->getDataFilename('testFileEmpty.plain'); | |
845 $this->gpg->verifyFile($filename); | |
846 } | |
847 | |
848 // }}} | |
849 } | |
850 | |
851 ?> |