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 */
46require_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 */
58class VerifyTest extends Crypt_GPG_TestCase
59{
60    /**
61     * @group string
62     */
63    public function testVerifyNoDataExceptionInvalid()
64    {
65        $this->expectException('Crypt_GPG_NoDataException');
66
67        $signedData = 'Invalid OpenPGP data.';
68        $this->gpg->verify($signedData);
69    }
70
71    /**
72     * @group string
73     */
74    public function testVerifyNoDataExceptionEmpty()
75    {
76        $this->expectException('Crypt_GPG_NoDataException');
77
78        $signedData = '';
79        $this->gpg->verify($signedData);
80    }
81
82    /**
83     * @group string
84     */
85    public function testVerifyKeyNotFoundException()
86    {
87        $this->expectException('Crypt_GPG_KeyNotFoundException');
88
89        $data = 'Hello, Alice! Goodbye, Bob!';
90        // {{{ detached signature
91        $detachedSignature = <<<TEXT
92-----BEGIN PGP SIGNATURE-----
93Version: GnuPG v1.4.6 (GNU/Linux)
94
95iD8DBQBI1xN9CuJ9bDb23VARAkKSAKCG5/jPq1H7+mpMEpDITFnAJhSqlwCggzRx
96laNWOZOef2zfm1yANtWjPyU=
97=fhME
98-----END PGP SIGNATURE-----
99
100TEXT;
101        // }}}
102        $this->gpg->verify($data, $detachedSignature);
103    }
104
105    /**
106     * @group string
107     */
108    public function testVerifyNormalSignedData()
109    {
110        // {{{ signature
111        $signature = new Crypt_GPG_Signature();
112        $signature->setId('KuhELanvhPRXozEjFWb2mam1q20');
113        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
114
115        $signature->setKeyId('C097D9EC94C06363');
116        $signature->setCreationDate(1221785858);
117        $signature->setExpirationDate(0);
118        $signature->setValid(true);
119
120        $userId = new Crypt_GPG_UserId();
121        $userId->setName('First Keypair Test Key');
122        $userId->setComment('do not encrypt important data with this key');
123        $userId->setEmail('first-keypair@example.com');
124        $signature->setUserId($userId);
125        // }}}
126        // {{{ normal signed data
127        $normalSignedData = <<<TEXT
128-----BEGIN PGP MESSAGE-----
129Version: GnuPG v1.4.6 (GNU/Linux)
130
131owGbwMvMwCR4YPrNN1MOJCczrjFOEsrLL8pNzNEtzkzPS03RTUksSfS49JPJIzUn
132J19HwTEnMzlVUcE9Pz8lqTJVR8EpP0mxw56ZlQGkBmaMIJO9GsOCo2L3pk5y2DNT
133yiFKb0X03YSJqscaGRb0BKjZ3P+6SvjG160/WOa9vpey4QUDAA==
134=wtCB
135-----END PGP MESSAGE-----
136
137TEXT;
138        // }}}
139
140        $expectedSignatures = array($signature);
141
142        $signatures = $this->gpg->verify($normalSignedData);
143        $this->assertSignaturesEquals($expectedSignatures, $signatures);
144    }
145
146    /**
147     * @group string
148     */
149    public function testVerifyClearsignedData()
150    {
151        // {{{ signature
152        $signature = new Crypt_GPG_Signature();
153        $signature->setId('wwm5gqNiFS+E/tmqbt1uXvVy3Ck');
154        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
155
156        $signature->setKeyId('C097D9EC94C06363');
157        $signature->setCreationDate(1221785858);
158        $signature->setExpirationDate(0);
159        $signature->setValid(true);
160
161        $userId = new Crypt_GPG_UserId();
162        $userId->setName('First Keypair Test Key');
163        $userId->setComment('do not encrypt important data with this key');
164        $userId->setEmail('first-keypair@example.com');
165        $signature->setUserId($userId);
166        // }}}
167        // {{{ clearsigned data
168        $clearsignedData = <<<TEXT
169-----BEGIN PGP SIGNED MESSAGE-----
170Hash: SHA1
171
172Hello, Alice! Goodbye, Bob!
173-----BEGIN PGP SIGNATURE-----
174Version: GnuPG v1.4.6 (GNU/Linux)
175
176iD8DBQFI0vkCwJfZ7JTAY2MRAgzTAKCRecYZsCS+PE46Fa2QLTEP8XGLwwCfQEAL
177qO+KlKcldtYdMZH9AA+KOLQ=
178=EO2G
179-----END PGP SIGNATURE-----
180
181TEXT;
182        // }}}
183
184        $expectedSignatures = array($signature);
185
186        $signatures = $this->gpg->verify($clearsignedData);
187        $this->assertSignaturesEquals($expectedSignatures, $signatures);
188    }
189
190    /**
191     * @group string
192     */
193    public function testVerifyDetachedSignature()
194    {
195        $data = 'Hello, Alice! Goodbye, Bob!';
196
197        // {{{ signature
198        $signature = new Crypt_GPG_Signature();
199        $signature->setId('E4HEDmMtecF457JFb88UAtPBVWY');
200        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
201
202        $signature->setKeyId('C097D9EC94C06363');
203        $signature->setCreationDate(1221785858);
204        $signature->setExpirationDate(0);
205        $signature->setValid(true);
206
207        $userId = new Crypt_GPG_UserId();
208        $userId->setName('First Keypair Test Key');
209        $userId->setComment('do not encrypt important data with this key');
210        $userId->setEmail('first-keypair@example.com');
211        $signature->setUserId($userId);
212        // }}}
213        // {{{ detached signature
214        $detachedSignature = <<<TEXT
215-----BEGIN PGP SIGNATURE-----
216Version: GnuPG v1.4.6 (GNU/Linux)
217
218iD8DBQBI0vkCwJfZ7JTAY2MRAj8mAKC4IN01tGaEtNxWYS5eQiNT4Fua9ACeKum3
219BdQ5rTOK2pp2X2vy/k2aCPo=
220=upYI
221-----END PGP SIGNATURE-----
222
223TEXT;
224        // }}}
225
226        $expectedSignatures = array($signature);
227
228        $signatures = $this->gpg->verify($data, $detachedSignature);
229        $this->assertSignaturesEquals($expectedSignatures, $signatures);
230    }
231
232    /**
233     * @group string
234     */
235    public function testVerifyDualNormalSignedData()
236    {
237        // {{{ first signature
238        $firstSignature = new Crypt_GPG_Signature();
239        $firstSignature->setId('4BunvSK18HPx6Xt4tEzyAqcNVzY');
240        $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
241
242        $firstSignature->setKeyId('03CC890AFA1DAD4B');
243        $firstSignature->setCreationDate(1221785858);
244        $firstSignature->setExpirationDate(0);
245        $firstSignature->setValid(true);
246
247        $userId = new Crypt_GPG_UserId();
248        $userId->setName('Second Keypair Test Key');
249        $userId->setComment('do not encrypt important data with this key');
250        $userId->setEmail('second-keypair@example.com');
251        $firstSignature->setUserId($userId);
252        // }}}
253        // {{{ second signature
254        $secondSignature = new Crypt_GPG_Signature();
255        $secondSignature->setId('oAZ64v4sFarc7dssFOAJPB0D7zs');
256        $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
257
258        $secondSignature->setKeyId('C097D9EC94C06363');
259        $secondSignature->setCreationDate(1221785858);
260        $secondSignature->setExpirationDate(0);
261        $secondSignature->setValid(true);
262
263        $userId = new Crypt_GPG_UserId();
264        $userId->setName('First Keypair Test Key');
265        $userId->setComment('do not encrypt important data with this key');
266        $userId->setEmail('first-keypair@example.com');
267        $secondSignature->setUserId($userId);
268        // }}}
269        // {{{ dual normal signed data
270        $dualNormalSignedData = <<<TEXT
271-----BEGIN PGP MESSAGE-----
272Version: GnuPG v1.4.6 (GNU/Linux)
273
274owGbwMvMwCR4YPrNN1MOJCczTABzmc90cv2SXevNuMYiSTylNDFHNy+/KBdIFWem
27556Wm6KYkliR6XPrJ5JGak5Ovo+CYk5mcqqjgnp+fklSZqqPglJ+k2GHPzMoAUgMz
276S5DJXo1hns0D5bkxpVHbI8+1y866l6K4yE1vHcNcOS1T45mf+VMn1NxQnnVn3Uab
277dx7z4AbA3AY2YMGDvnnpCe982TwPTGyZdn+fMbu0fQDDgn098wSP/O79+/aYgon9
278y/y/MVtYcwE=
279=7EC6
280-----END PGP MESSAGE-----
281
282TEXT;
283        // }}}
284
285        $expectedSignatures = array($firstSignature, $secondSignature);
286
287        $signatures = $this->gpg->verify($dualNormalSignedData);
288        $this->assertSignaturesEquals($expectedSignatures, $signatures);
289    }
290
291    /**
292     * @group string
293     */
294    public function testVerifyDualClearsignedData()
295    {
296        // {{{ first signature
297        $firstSignature = new Crypt_GPG_Signature();
298        $firstSignature->setId('MCn4/0Giq0njPh2smOs3Lrdc7yY');
299        $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
300
301        $firstSignature->setKeyId('03CC890AFA1DAD4B');
302        $firstSignature->setCreationDate(1221785858);
303        $firstSignature->setExpirationDate(0);
304        $firstSignature->setValid(true);
305
306        $userId = new Crypt_GPG_UserId();
307        $userId->setName('Second Keypair Test Key');
308        $userId->setComment('do not encrypt important data with this key');
309        $userId->setEmail('second-keypair@example.com');
310        $firstSignature->setUserId($userId);
311        // }}}
312        // {{{ second signature
313        $secondSignature = new Crypt_GPG_Signature();
314        $secondSignature->setId('O5tcpOAXJhd0v5TBxqhIixgphn8');
315        $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
316
317        $secondSignature->setKeyId('C097D9EC94C06363');
318        $secondSignature->setCreationDate(1221785858);
319        $secondSignature->setExpirationDate(0);
320        $secondSignature->setValid(true);
321
322        $userId = new Crypt_GPG_UserId();
323        $userId->setName('First Keypair Test Key');
324        $userId->setComment('do not encrypt important data with this key');
325        $userId->setEmail('first-keypair@example.com');
326        $secondSignature->setUserId($userId);
327        // }}}
328        // {{{ dual clearsigned data
329        $dualClearsignedData = <<<TEXT
330-----BEGIN PGP SIGNED MESSAGE-----
331Hash: SHA1
332
333Hello, Alice! Goodbye, Bob!
334-----BEGIN PGP SIGNATURE-----
335Version: GnuPG v1.4.6 (GNU/Linux)
336
337iD8DBQFI0vkCA8yJCvodrUsRAgzTAJ9xSosvdq3fqaseRS6YV9VgnSGo2gCgiD+2
338TRUrY67ZzdfTjCd6cFZHqauIPwMFAUjS+QLAl9nslMBjYxECDNMAoKdQQAWe8EwG
339kZ/cCDE/fgToHk+7AJ9sU0NweUfUP3KNe2UK808Epd0Avg==
340=j0ot
341-----END PGP SIGNATURE-----
342
343TEXT;
344        // }}}
345
346        $expectedSignatures = array($firstSignature, $secondSignature);
347
348        $signatures = $this->gpg->verify($dualClearsignedData);
349        $this->assertSignaturesEquals($expectedSignatures, $signatures);
350    }
351
352    /**
353     * @group string
354     */
355    public function testVerifyDualDetachedSignature()
356    {
357        $data = 'Hello, Alice! Goodbye, Bob!';
358
359        // {{{ first signature
360        $firstSignature = new Crypt_GPG_Signature();
361        $firstSignature->setId('tejKd9+9OBUM+EsrbV3fVuOiBeE');
362        $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
363
364        $firstSignature->setKeyId('03CC890AFA1DAD4B');
365        $firstSignature->setCreationDate(1221785858);
366        $firstSignature->setExpirationDate(0);
367        $firstSignature->setValid(true);
368
369        $userId = new Crypt_GPG_UserId();
370        $userId->setName('Second Keypair Test Key');
371        $userId->setComment('do not encrypt important data with this key');
372        $userId->setEmail('second-keypair@example.com');
373        $firstSignature->setUserId($userId);
374        // }}}
375        // {{{ second signature
376        $secondSignature = new Crypt_GPG_Signature();
377        $secondSignature->setId('7oizks/aha+bSONesnWDu1x2jn8');
378        $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
379
380        $secondSignature->setKeyId('C097D9EC94C06363');
381        $secondSignature->setCreationDate(1221785858);
382        $secondSignature->setExpirationDate(0);
383        $secondSignature->setValid(true);
384
385        $userId = new Crypt_GPG_UserId();
386        $userId->setName('First Keypair Test Key');
387        $userId->setComment('do not encrypt important data with this key');
388        $userId->setEmail('first-keypair@example.com');
389        $secondSignature->setUserId($userId);
390        // }}}
391        // {{{ dual detached signature
392        $dualDetachedSignature = <<<TEXT
393-----BEGIN PGP SIGNATURE-----
394Version: GnuPG v1.4.6 (GNU/Linux)
395
396iD8DBQBI0vkCA8yJCvodrUsRAj8mAKCJWz3ANeG9SPGUHMg04gH0rCOqKwCfaxUR
397Dypdcanj3VE3inTxleaQtdqIPwMFAEjS+QLAl9nslMBjYxECPyYAoN+Y3tibHIg+
3989+fdvxAEvANir2RQAKCuD2BsKzSmyV3G4/i6oPNhOrwtPg==
399=8P1D
400-----END PGP SIGNATURE-----
401
402TEXT;
403        // }}}
404
405        $expectedSignatures = array($firstSignature, $secondSignature);
406
407        $signatures = $this->gpg->verify($data, $dualDetachedSignature);
408        $this->assertSignaturesEquals($expectedSignatures, $signatures);
409    }
410
411    /**
412     * @group string
413     */
414    public function testVerifyBadSignature()
415    {
416        $modifiedData = 'Hello, Bob! Goodbye, Alice!';
417
418        // {{{ signature
419        $signature = new Crypt_GPG_Signature();
420        $signature->setKeyId('C097D9EC94C06363');
421        $signature->setValid(false);
422        $userId = new Crypt_GPG_UserId();
423        $userId->setName('First Keypair Test Key');
424        $userId->setComment('do not encrypt important data with this key');
425        $userId->setEmail('first-keypair@example.com');
426        $signature->setUserId($userId);
427        // }}}
428        // {{{ detached signature
429        $detachedSignature = <<<TEXT
430-----BEGIN PGP SIGNATURE-----
431Version: GnuPG v1.4.6 (GNU/Linux)
432
433iD8DBQBI0vkCwJfZ7JTAY2MRAj8mAKC4IN01tGaEtNxWYS5eQiNT4Fua9ACeKum3
434BdQ5rTOK2pp2X2vy/k2aCPo=
435=upYI
436-----END PGP SIGNATURE-----
437
438TEXT;
439        // }}}
440
441        $expectedSignatures = array($signature);
442
443        $signatures = $this->gpg->verify($modifiedData, $detachedSignature);
444        $this->assertSignaturesEquals($expectedSignatures, $signatures);
445    }
446
447    /**
448     * @group string
449     */
450    public function testVerifyDualBadSignatures()
451    {
452        $modifiedData = 'Hello, Bob! Goodbye, Alice!';
453
454        // {{{ first signature
455        $firstSignature = new Crypt_GPG_Signature();
456        $firstSignature->setExpirationDate(0);
457        $firstSignature->setValid(false);
458        $firstSignature->setKeyId('03CC890AFA1DAD4B');
459        $userId = new Crypt_GPG_UserId();
460        $userId->setName('Second Keypair Test Key');
461        $userId->setComment('do not encrypt important data with this key');
462        $userId->setEmail('second-keypair@example.com');
463        $firstSignature->setUserId($userId);
464        // }}}
465        // {{{ second signature
466        $secondSignature = new Crypt_GPG_Signature();
467        $secondSignature->setValid(false);
468        $secondSignature->setKeyId('C097D9EC94C06363');
469        $userId = new Crypt_GPG_UserId();
470        $userId->setName('First Keypair Test Key');
471        $userId->setComment('do not encrypt important data with this key');
472        $userId->setEmail('first-keypair@example.com');
473        $secondSignature->setUserId($userId);
474        // }}}
475        // {{{ dual detached signature
476        $dualDetachedSignature = <<<TEXT
477-----BEGIN PGP SIGNATURE-----
478Version: GnuPG v1.4.6 (GNU/Linux)
479
480iD8DBQBI0vkCA8yJCvodrUsRAj8mAKCJWz3ANeG9SPGUHMg04gH0rCOqKwCfaxUR
481Dypdcanj3VE3inTxleaQtdqIPwMFAEjS+QLAl9nslMBjYxECPyYAoN+Y3tibHIg+
4829+fdvxAEvANir2RQAKCuD2BsKzSmyV3G4/i6oPNhOrwtPg==
483=8P1D
484-----END PGP SIGNATURE-----
485
486TEXT;
487        // }}}
488
489        $expectedSignatures = array($firstSignature, $secondSignature);
490
491        $signatures = $this->gpg->verify($modifiedData, $dualDetachedSignature);
492        $this->assertSignaturesEquals($expectedSignatures, $signatures);
493    }
494
495    /**
496     * @group file
497     */
498    public function testVerifyFileNormalSignedData()
499    {
500        // {{{ signature
501        $signature = new Crypt_GPG_Signature();
502        $signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU');
503        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
504
505        $signature->setKeyId('C097D9EC94C06363');
506        $signature->setCreationDate(1221960707);
507        $signature->setExpirationDate(0);
508        $signature->setValid(true);
509
510        $userId = new Crypt_GPG_UserId();
511        $userId->setName('First Keypair Test Key');
512        $userId->setComment('do not encrypt important data with this key');
513        $userId->setEmail('first-keypair@example.com');
514        $signature->setUserId($userId);
515        // }}}
516
517        $expectedSignatures = array($signature);
518
519        $filename = $this->getDataFilename('testVerifyFileNormalSignedData.asc');
520
521        $signatures = $this->gpg->verifyFile($filename);
522        $this->assertSignaturesEquals($expectedSignatures, $signatures);
523    }
524
525    /**
526     * @group file
527     */
528    public function testVerifyFileClearsignedData()
529    {
530        // {{{ signature
531        $signature = new Crypt_GPG_Signature();
532        $signature->setId('6sXJXKZB5lvRSCXBAYl6R2EiDmw');
533        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
534
535        $signature->setKeyId('C097D9EC94C06363');
536        $signature->setCreationDate(1221960707);
537        $signature->setExpirationDate(0);
538        $signature->setValid(true);
539
540        $userId = new Crypt_GPG_UserId();
541        $userId->setName('First Keypair Test Key');
542        $userId->setComment('do not encrypt important data with this key');
543        $userId->setEmail('first-keypair@example.com');
544        $signature->setUserId($userId);
545        // }}}
546
547        $expectedSignatures = array($signature);
548
549        $filename = $this->getDataFilename('testVerifyFileClearsignedData.asc');
550
551        $signatures = $this->gpg->verifyFile($filename);
552        $this->assertSignaturesEquals($expectedSignatures, $signatures);
553    }
554
555    /**
556     * @group file
557     */
558    public function testVerifyFileDetachedSignature()
559    {
560        // {{{ signature
561        $signature = new Crypt_GPG_Signature();
562        $signature->setId('tdsH/ulxOnoWEMPDamZTq7wzF/0');
563        $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
564
565        $signature->setKeyId('C097D9EC94C06363');
566        $signature->setCreationDate(1221960707);
567        $signature->setExpirationDate(0);
568        $signature->setValid(true);
569
570        $userId = new Crypt_GPG_UserId();
571        $userId->setName('First Keypair Test Key');
572        $userId->setComment('do not encrypt important data with this key');
573        $userId->setEmail('first-keypair@example.com');
574        $signature->setUserId($userId);
575        // }}}
576        // {{{ signatureData
577        $signatureData = <<<TEXT
578-----BEGIN PGP SIGNATURE-----
579Version: GnuPG v1.4.6 (GNU/Linux)
580
581iD8DBQBI1aQDwJfZ7JTAY2MRAvkzAJ0RAW0wtlfEgDccgq+N5IgbpA4BOQCfS8vV
582Of32/RcteCLdt73awNJ0CwI=
583=RVco
584-----END PGP SIGNATURE-----
585
586TEXT;
587        // }}}
588
589        $expectedSignatures = array($signature);
590
591        $filename = $this->getDataFilename('testFileMedium.plain');
592
593        $signatures = $this->gpg->verifyFile($filename, $signatureData);
594        $this->assertSignaturesEquals($expectedSignatures, $signatures);
595    }
596
597    /**
598     * @group file
599     */
600    public function testVerifyFileDualNormalSignedData()
601    {
602        // {{{ first signature
603        $firstSignature = new Crypt_GPG_Signature();
604        $firstSignature->setId('Kl3Mds4ABT9JyE3iqfPGpUHzKQs');
605        $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
606
607        $firstSignature->setKeyId('C097D9EC94C06363');
608        $firstSignature->setCreationDate(1221960707);
609        $firstSignature->setExpirationDate(0);
610        $firstSignature->setValid(true);
611
612        $userId = new Crypt_GPG_UserId();
613        $userId->setName('First Keypair Test Key');
614        $userId->setComment('do not encrypt important data with this key');
615        $userId->setEmail('first-keypair@example.com');
616        $firstSignature->setUserId($userId);
617        // }}}
618        // {{{ second signature
619        $secondSignature = new Crypt_GPG_Signature();
620        $secondSignature->setId('KGrEm3hGqiKaLbjvOUO9kvUjRXc');
621        $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
622
623        $secondSignature->setKeyId('03CC890AFA1DAD4B');
624        $secondSignature->setCreationDate(1221960707);
625        $secondSignature->setExpirationDate(0);
626        $secondSignature->setValid(true);
627
628        $userId = new Crypt_GPG_UserId();
629        $userId->setName('Second Keypair Test Key');
630        $userId->setComment('do not encrypt important data with this key');
631        $userId->setEmail('second-keypair@example.com');
632        $secondSignature->setUserId($userId);
633        // }}}
634
635        $expectedSignatures = array($firstSignature, $secondSignature);
636
637        $filename = $this->getDataFilename('testVerifyFileDualNormalSignedData.asc');
638
639        $signatures = $this->gpg->verifyFile($filename);
640        $this->assertSignaturesEquals($expectedSignatures, $signatures);
641    }
642
643    /**
644     * @group file
645     */
646    public function testVerifyFileDualClearsignedData()
647    {
648        // {{{ first signature
649        $firstSignature = new Crypt_GPG_Signature();
650        $firstSignature->setId('eRRcEecpFk0YK/iswddS/KBxEXI');
651        $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
652
653        $firstSignature->setKeyId('C097D9EC94C06363');
654        $firstSignature->setCreationDate(1221960707);
655        $firstSignature->setExpirationDate(0);
656        $firstSignature->setValid(true);
657
658        $userId = new Crypt_GPG_UserId();
659        $userId->setName('First Keypair Test Key');
660        $userId->setComment('do not encrypt important data with this key');
661        $userId->setEmail('first-keypair@example.com');
662        $firstSignature->setUserId($userId);
663        // }}}
664        // {{{ second signature
665        $secondSignature = new Crypt_GPG_Signature();
666        $secondSignature->setId('jsWYGJe/0hmte7tYt8zuJd7rFMM');
667        $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
668
669        $secondSignature->setKeyId('03CC890AFA1DAD4B');
670        $secondSignature->setCreationDate(1221960707);
671        $secondSignature->setExpirationDate(0);
672        $secondSignature->setValid(true);
673
674        $userId = new Crypt_GPG_UserId();
675        $userId->setName('Second Keypair Test Key');
676        $userId->setComment('do not encrypt important data with this key');
677        $userId->setEmail('second-keypair@example.com');
678        $secondSignature->setUserId($userId);
679        // }}}
680
681        $expectedSignatures = array($firstSignature, $secondSignature);
682
683        $filename = $this->getDataFilename('testVerifyFileDualClearsignedData.asc');
684
685        $signatures = $this->gpg->verifyFile($filename);
686        $this->assertSignaturesEquals($expectedSignatures, $signatures);
687    }
688
689    /**
690     * @group file
691     */
692    public function testVerifyFileDualDetachedSignature()
693    {
694        // {{{ first signature
695        $firstSignature = new Crypt_GPG_Signature();
696        $firstSignature->setId('T7+toJbsFr8KMTWN+M7lF3xSmmA');
697        $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
698
699        $firstSignature->setKeyId('C097D9EC94C06363');
700        $firstSignature->setCreationDate(1221960707);
701        $firstSignature->setExpirationDate(0);
702        $firstSignature->setValid(true);
703
704        $userId = new Crypt_GPG_UserId();
705        $userId->setName('First Keypair Test Key');
706        $userId->setComment('do not encrypt important data with this key');
707        $userId->setEmail('first-keypair@example.com');
708        $firstSignature->setUserId($userId);
709        // }}}
710        // {{{ second signature
711        $secondSignature = new Crypt_GPG_Signature();
712        $secondSignature->setId('HJd1yvMbEbW5facuxkDtvwymKrw');
713        $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
714
715        $secondSignature->setKeyId('03CC890AFA1DAD4B');
716        $secondSignature->setCreationDate(1221960707);
717        $secondSignature->setExpirationDate(0);
718        $secondSignature->setValid(true);
719
720        $userId = new Crypt_GPG_UserId();
721        $userId->setName('Second Keypair Test Key');
722        $userId->setComment('do not encrypt important data with this key');
723        $userId->setEmail('second-keypair@example.com');
724        $secondSignature->setUserId($userId);
725        // }}}
726        // {{{ signature data
727        $signatureData = <<<TEXT
728-----BEGIN PGP SIGNATURE-----
729Version: GnuPG v1.4.6 (GNU/Linux)
730
731iD8DBQBI1aQDwJfZ7JTAY2MRAvkzAKDPnJ030GdYE15mE8smz2oV7zYziwCeJFxf
732UaTrAgP1Dck9DhHOBhvhwLuIPwMFAEjVpAMDzIkK+h2tSxEC+TMAn38yx3mXk6wP
733JaPThD7lRVE9ve57AJ0Yy7JwiT9sGXomln4JtRvuSpGtsg==
734=Gw9D
735-----END PGP SIGNATURE-----
736
737TEXT;
738        // }}}
739
740        $expectedSignatures = array($firstSignature, $secondSignature);
741
742        $filename = $this->getDataFilename('testFileMedium.plain');
743
744        $signatures = $this->gpg->verifyFile($filename, $signatureData);
745        $this->assertSignaturesEquals($expectedSignatures, $signatures);
746
747        $warnings = $this->gpg->getWarnings();
748        $this->assertTrue(is_array($warnings));
749    }
750
751    /**
752     * @group file
753     */
754    public function testVerifyFileFileException()
755    {
756        $this->expectException('Crypt_GPG_FileException');
757
758        $filename = './non-existent/testVerifyFileFileException.asc';
759        $this->gpg->verifyFile($filename);
760    }
761
762    /**
763     * @group file
764     */
765    public function testVerifyFileNoDataException()
766    {
767        $this->expectException('Crypt_GPG_NoDataException');
768
769        $filename = $this->getDataFilename('testFileEmpty.plain');
770        $this->gpg->verifyFile($filename);
771    }
772}
773