* $ phpunit VerifyTestCase * * * LICENSE: * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of the * License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see * * * @category Encryption * @package Crypt_GPG * @author Michael Gauthier * @copyright 2005-2008 silverorange * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/Crypt_GPG */ /** * Base test case. */ require_once 'TestCase.php'; /** * Tests verification abilities of Crypt_GPG. * * @category Encryption * @package Crypt_GPG * @author Michael Gauthier * @copyright 2005-2008 silverorange * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/Crypt_GPG */ class VerifyTest extends Crypt_GPG_TestCase { /** * @group string */ public function testVerifyNoDataExceptionInvalid() { $this->expectException('Crypt_GPG_NoDataException'); $signedData = 'Invalid OpenPGP data.'; $this->gpg->verify($signedData); } /** * @group string */ public function testVerifyNoDataExceptionEmpty() { $this->expectException('Crypt_GPG_NoDataException'); $signedData = ''; $this->gpg->verify($signedData); } /** * @group string */ public function testVerifyKeyNotFoundException() { $this->expectException('Crypt_GPG_KeyNotFoundException'); $data = 'Hello, Alice! Goodbye, Bob!'; // {{{ detached signature $detachedSignature = <<gpg->verify($data, $detachedSignature); } /** * @group string */ public function testVerifyNormalSignedData() { // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('KuhELanvhPRXozEjFWb2mam1q20'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221785858); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} // {{{ normal signed data $normalSignedData = <<gpg->verify($normalSignedData); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyClearsignedData() { // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('wwm5gqNiFS+E/tmqbt1uXvVy3Ck'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221785858); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} // {{{ clearsigned data $clearsignedData = <<gpg->verify($clearsignedData); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyDetachedSignature() { $data = 'Hello, Alice! Goodbye, Bob!'; // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('E4HEDmMtecF457JFb88UAtPBVWY'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221785858); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} // {{{ detached signature $detachedSignature = <<gpg->verify($data, $detachedSignature); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyDualNormalSignedData() { // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('4BunvSK18HPx6Xt4tEzyAqcNVzY'); $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $firstSignature->setKeyId('03CC890AFA1DAD4B'); $firstSignature->setCreationDate(1221785858); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('oAZ64v4sFarc7dssFOAJPB0D7zs'); $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $secondSignature->setKeyId('C097D9EC94C06363'); $secondSignature->setCreationDate(1221785858); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $secondSignature->setUserId($userId); // }}} // {{{ dual normal signed data $dualNormalSignedData = <<gpg->verify($dualNormalSignedData); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyDualClearsignedData() { // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('MCn4/0Giq0njPh2smOs3Lrdc7yY'); $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $firstSignature->setKeyId('03CC890AFA1DAD4B'); $firstSignature->setCreationDate(1221785858); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('O5tcpOAXJhd0v5TBxqhIixgphn8'); $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $secondSignature->setKeyId('C097D9EC94C06363'); $secondSignature->setCreationDate(1221785858); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $secondSignature->setUserId($userId); // }}} // {{{ dual clearsigned data $dualClearsignedData = <<gpg->verify($dualClearsignedData); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyDualDetachedSignature() { $data = 'Hello, Alice! Goodbye, Bob!'; // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('tejKd9+9OBUM+EsrbV3fVuOiBeE'); $firstSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $firstSignature->setKeyId('03CC890AFA1DAD4B'); $firstSignature->setCreationDate(1221785858); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('7oizks/aha+bSONesnWDu1x2jn8'); $secondSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $secondSignature->setKeyId('C097D9EC94C06363'); $secondSignature->setCreationDate(1221785858); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $secondSignature->setUserId($userId); // }}} // {{{ dual detached signature $dualDetachedSignature = <<gpg->verify($data, $dualDetachedSignature); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyBadSignature() { $modifiedData = 'Hello, Bob! Goodbye, Alice!'; // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setKeyId('C097D9EC94C06363'); $signature->setValid(false); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} // {{{ detached signature $detachedSignature = <<gpg->verify($modifiedData, $detachedSignature); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group string */ public function testVerifyDualBadSignatures() { $modifiedData = 'Hello, Bob! Goodbye, Alice!'; // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setExpirationDate(0); $firstSignature->setValid(false); $firstSignature->setKeyId('03CC890AFA1DAD4B'); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setValid(false); $secondSignature->setKeyId('C097D9EC94C06363'); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $secondSignature->setUserId($userId); // }}} // {{{ dual detached signature $dualDetachedSignature = <<gpg->verify($modifiedData, $dualDetachedSignature); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileNormalSignedData() { // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221960707); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} $expectedSignatures = array($signature); $filename = $this->getDataFilename('testVerifyFileNormalSignedData.asc'); $signatures = $this->gpg->verifyFile($filename); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileClearsignedData() { // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('6sXJXKZB5lvRSCXBAYl6R2EiDmw'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221960707); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} $expectedSignatures = array($signature); $filename = $this->getDataFilename('testVerifyFileClearsignedData.asc'); $signatures = $this->gpg->verifyFile($filename); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileDetachedSignature() { // {{{ signature $signature = new Crypt_GPG_Signature(); $signature->setId('tdsH/ulxOnoWEMPDamZTq7wzF/0'); $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $signature->setKeyId('C097D9EC94C06363'); $signature->setCreationDate(1221960707); $signature->setExpirationDate(0); $signature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $signature->setUserId($userId); // }}} // {{{ signatureData $signatureData = <<getDataFilename('testFileMedium.plain'); $signatures = $this->gpg->verifyFile($filename, $signatureData); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileDualNormalSignedData() { // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('Kl3Mds4ABT9JyE3iqfPGpUHzKQs'); $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $firstSignature->setKeyId('C097D9EC94C06363'); $firstSignature->setCreationDate(1221960707); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('KGrEm3hGqiKaLbjvOUO9kvUjRXc'); $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $secondSignature->setKeyId('03CC890AFA1DAD4B'); $secondSignature->setCreationDate(1221960707); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $secondSignature->setUserId($userId); // }}} $expectedSignatures = array($firstSignature, $secondSignature); $filename = $this->getDataFilename('testVerifyFileDualNormalSignedData.asc'); $signatures = $this->gpg->verifyFile($filename); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileDualClearsignedData() { // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('eRRcEecpFk0YK/iswddS/KBxEXI'); $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $firstSignature->setKeyId('C097D9EC94C06363'); $firstSignature->setCreationDate(1221960707); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('jsWYGJe/0hmte7tYt8zuJd7rFMM'); $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $secondSignature->setKeyId('03CC890AFA1DAD4B'); $secondSignature->setCreationDate(1221960707); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $secondSignature->setUserId($userId); // }}} $expectedSignatures = array($firstSignature, $secondSignature); $filename = $this->getDataFilename('testVerifyFileDualClearsignedData.asc'); $signatures = $this->gpg->verifyFile($filename); $this->assertSignaturesEquals($expectedSignatures, $signatures); } /** * @group file */ public function testVerifyFileDualDetachedSignature() { // {{{ first signature $firstSignature = new Crypt_GPG_Signature(); $firstSignature->setId('T7+toJbsFr8KMTWN+M7lF3xSmmA'); $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $firstSignature->setKeyId('C097D9EC94C06363'); $firstSignature->setCreationDate(1221960707); $firstSignature->setExpirationDate(0); $firstSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('first-keypair@example.com'); $firstSignature->setUserId($userId); // }}} // {{{ second signature $secondSignature = new Crypt_GPG_Signature(); $secondSignature->setId('HJd1yvMbEbW5facuxkDtvwymKrw'); $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); $secondSignature->setKeyId('03CC890AFA1DAD4B'); $secondSignature->setCreationDate(1221960707); $secondSignature->setExpirationDate(0); $secondSignature->setValid(true); $userId = new Crypt_GPG_UserId(); $userId->setName('Second Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('second-keypair@example.com'); $secondSignature->setUserId($userId); // }}} // {{{ signature data $signatureData = <<getDataFilename('testFileMedium.plain'); $signatures = $this->gpg->verifyFile($filename, $signatureData); $this->assertSignaturesEquals($expectedSignatures, $signatures); $warnings = $this->gpg->getWarnings(); $this->assertTrue(is_array($warnings)); } /** * @group file */ public function testVerifyFileFileException() { $this->expectException('Crypt_GPG_FileException'); $filename = './non-existent/testVerifyFileFileException.asc'; $this->gpg->verifyFile($filename); } /** * @group file */ public function testVerifyFileNoDataException() { $this->expectException('Crypt_GPG_NoDataException'); $filename = $this->getDataFilename('testFileEmpty.plain'); $this->gpg->verifyFile($filename); } }