Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/DecryptAndVerifyTest.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 * Decrypt 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 DecryptAndVefifyTestCase | |
| 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-2010 silverorange | |
| 38 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
| 39 * @version $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 decrypt verify abilities of Crypt_GPG. | |
| 50 * | |
| 51 * @category Encryption | |
| 52 * @package Crypt_GPG | |
| 53 * @author Michael Gauthier <mike@silverorange.com> | |
| 54 * @copyright 2005-2010 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 DecryptAndVerifyTestCase extends Crypt_GPG_TestCase | |
| 59 { | |
| 60 // string | |
| 61 // {{{ testDecryptVerify() | |
| 62 | |
| 63 /** | |
| 64 * @group string | |
| 65 */ | |
| 66 public function testDecryptVerify() | |
| 67 { | |
| 68 // {{{ signature | |
| 69 $signature = new Crypt_GPG_Signature(); | |
| 70 $signature->setId('5dGf4//0CqBmlexYjyS7agt4Zn4'); | |
| 71 $signature->setKeyFingerprint( | |
| 72 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 73 | |
| 74 $signature->setKeyId('C097D9EC94C06363'); | |
| 75 $signature->setCreationDate(1258956392); | |
| 76 $signature->setExpirationDate(0); | |
| 77 $signature->setValid(true); | |
| 78 | |
| 79 $userId = new Crypt_GPG_UserId(); | |
| 80 $userId->setName('First Keypair Test Key'); | |
| 81 $userId->setComment('do not encrypt important data with this key'); | |
| 82 $userId->setEmail('first-keypair@example.com'); | |
| 83 $signature->setUserId($userId); | |
| 84 // }}} | |
| 85 | |
| 86 $expectedResults = array( | |
| 87 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 88 'signatures' => array($signature) | |
| 89 ); | |
| 90 | |
| 91 // encrypted with first-keypair@example.com, signed with | |
| 92 // first-keypair@example.com | |
| 93 // {{{ encrypted data no passphrase | |
| 94 $encryptedData = <<<TEXT | |
| 95 -----BEGIN PGP MESSAGE----- | |
| 96 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 97 | |
| 98 hQIOA5+T+RFnKO8SEAf+M1KnzLUvmJMtRTMpy3G2C8iJN1oQPznWDlL6NqxNeS6N | |
| 99 8ie5dXmaG9csQUx1Ys8QRaPDg6ElVIrJOXQ0CIW3mqxZS7+5X5akH5DQ0Ye4Rggx | |
| 100 yqADpE2z99tlYiNlpEqtG4oAUXzJjWiw8Y6MFg/xAHQUYMhEhZRB4OaSQGVPpxYs | |
| 101 s6YBfRGmWdNrGgPgcwoEmoHvmVKtVOfBNzO9cpl7k2pV12p6eG6jZ1qcCQkSJZlY | |
| 102 z2WsnDYZ9wbXuLM4XanGiJiBau0f+nJqDozmOVvc5Avz1qrQD3Dd5C5cy/e+XPdn | |
| 103 wzTgg3myMrwudAeJZzwMrpcrGwvdzAKE8/7TbNO+3Qf+NqfrApMVUrsFQBdzlLp9 | |
| 104 7cV8nD0uF8ioQjPg0lzJajJdqjEkKB7h9i9fQgL/SBZ29HupsUqDoqmpCVU/B6M0 | |
| 105 YzphMp1qWDRkk5dmpcTppTBsVx1KXCqLQFBIy+Fhc31NZRs1ccaVF3uxaOyMzFhb | |
| 106 FaWlUq03SjU9SlkYiFwyfyDysK3uoGeLfFh5yhH6ly5kthwLo2ov/GANF3pL0cxv | |
| 107 mGUcnZbkhk+MWjmz83loedhh2XpTLqRGuhzWPTQlOUQzf6xbj5zCkzWdnbqFQu19 | |
| 108 Et5O3whgv+ufNvD5LGc/lGQeV8wV7EXcde0ISUa8LKyU+eseS+W6IHsQLPupkCQG | |
| 109 u9KoAQUL3Q3vX1C7WmzS2sudcAulSR8bRYfr6lJ5udRvek7M7tYdLbE1ZLua23T8 | |
| 110 NId1euFhWftuaFjGDRvY37ab+M+zTnMtogSZDkCVyFrM2n4/hFfX9eKX6ljPxPmk | |
| 111 lEmn966i8e4K0jL0Ydvf7qWEVc5uov7xorYnkwvIbaW8SyUPowenfN3qODv7C0Yj | |
| 112 0kOgiJnRxZq+MYOR1b1L6fS0y7jDPI+er8ft | |
| 113 =pycC | |
| 114 -----END PGP MESSAGE----- | |
| 115 | |
| 116 TEXT; | |
| 117 // }}} | |
| 118 | |
| 119 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 120 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 121 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 122 } | |
| 123 | |
| 124 // }}} | |
| 125 // {{{ testDecryptVerifyNoPassphrase() | |
| 126 | |
| 127 /** | |
| 128 * @group string | |
| 129 */ | |
| 130 public function testDecryptVerifyNoPassphrase() | |
| 131 { | |
| 132 // {{{ signature | |
| 133 $signature = new Crypt_GPG_Signature(); | |
| 134 $signature->setId('0YWPoUQhN5G4uTi45QLy3GG3RWg'); | |
| 135 $signature->setKeyFingerprint( | |
| 136 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 137 | |
| 138 $signature->setKeyId('C097D9EC94C06363'); | |
| 139 $signature->setCreationDate(1258956262); | |
| 140 $signature->setExpirationDate(0); | |
| 141 $signature->setValid(true); | |
| 142 | |
| 143 $userId = new Crypt_GPG_UserId(); | |
| 144 $userId->setName('First Keypair Test Key'); | |
| 145 $userId->setComment('do not encrypt important data with this key'); | |
| 146 $userId->setEmail('first-keypair@example.com'); | |
| 147 $signature->setUserId($userId); | |
| 148 // }}} | |
| 149 | |
| 150 $expectedResults = array( | |
| 151 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 152 'signatures' => array($signature) | |
| 153 ); | |
| 154 | |
| 155 // encrypted with no-passphrase@example.com, signed with | |
| 156 // first-keypair@example.com | |
| 157 // {{{ encrypted data no passphrase | |
| 158 $encryptedData = <<<TEXT | |
| 159 -----BEGIN PGP MESSAGE----- | |
| 160 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 161 | |
| 162 hQIOAyS/OAcAwUtPEAf+KCytTYgKglBxxU9jAr2i0WVXhBcfyVyFq0N4or4HGMSz | |
| 163 zBw3eXw/JI77PY4pBxtBDCzPgSox8T8abh6OU3LDu3Zy9kvKcbQxYCSOeJkPBDpK | |
| 164 OtJ2Sw7CJ7QIvoSyqmRmCjrji9OU3k9ulQQ/5GauAP4QnUnt6lNkz+FOWVl5wzqc | |
| 165 yjXkRgfmKNBzYVscgdH+YDEUTM+edN+NflzqLk8HLU98TmINbbVJwnPvpCCvRGh4 | |
| 166 SDDaF7WmiIjSqI15Bn7F/l+8ScxvC8EH6wxR9gqS+B9DlqVpjIoYa57SPXLcshvQ | |
| 167 r02OjC8d8u2oyW9TLqnTirsf347Dzo7rRwm3GbdSrgf9FoQjymAzSx6izx9BsMg+ | |
| 168 6XJV0jSHW+jDjiJRoMAYXKc/s/y8MWRo/irCTPjReLEHWvKmISXynXqxHy1Dw5SN | |
| 169 1VQAPIH1ftqEVZvGtA11vLPjPYenCRCkkwz8AHqLmqZt6V2A49zPen4+H+Tp/5xr | |
| 170 s7TQhygo9vmTTzniBqV4lYbOyshcUTVlUErba+ffivKQPNnM+oCZXyUbJTsMlGv+ | |
| 171 elZqUKlNEBXivHnmIbwP/vpZ1WMMewCeij1/Z6OGbbT51dh9qeqPRj96dF351Lbk | |
| 172 GPxLw5uP2bIzGQjGIBeKHrl2kkRxKk/MX6QPrMHR4KlUpPRfKcQLC0TGPTEPu6ya | |
| 173 5tKoAdoBuKYNoFk2txsseRQTI/3v5pudNsdh5R/s+PMs+HpxyaFemI3eJb05E4Jx | |
| 174 zGJX5UiMIb/Yr0zCvlOaDx0NjPwIoUDqtZw6YqA59/BKmaRyqGoXk0UJMK2hAJKN | |
| 175 yTrj0nUDWFgoKzLHu3EQtYffLUrrjVc6BB8pUmrZKBisGnXFBQvShkzdWmzUT655 | |
| 176 JQfVfeZmgq+UAsfqIlrWBfDcqfyvWeAAZ7qH | |
| 177 =1oh0 | |
| 178 -----END PGP MESSAGE----- | |
| 179 | |
| 180 TEXT; | |
| 181 // }}} | |
| 182 | |
| 183 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 184 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 185 } | |
| 186 | |
| 187 // }}} | |
| 188 // {{{ testDecryptVerifyKeyNotFoundException_decrypt() | |
| 189 | |
| 190 /** | |
| 191 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 192 * | |
| 193 * @group string | |
| 194 */ | |
| 195 public function testDecryptVerifyKeyNotFoundException_decrypt() | |
| 196 { | |
| 197 // was encrypted with missing-key@example.com, signed with | |
| 198 // first-keypair@example.com | |
| 199 // {{{ encrypted data | |
| 200 $encryptedData = <<<TEXT | |
| 201 -----BEGIN PGP MESSAGE----- | |
| 202 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 203 | |
| 204 hQIOA82wFXJyxZnNEAgAwSoWLKDj/dyotGwYCT60IHC7vPGKbcbd9LMEQ8hOobKS | |
| 205 21aHeUBft9vlAnZabzPSqeQGYoD0BugONncV45HWlA3QD0KGcVuE6FaWIkexRNsK | |
| 206 S8MwVpcCgTuVkmSBgZbAS9jl7ODGGNdfGCb20fpgWFx8rv6q14aPUrD1bw5VVWeS | |
| 207 vLGuRGA+pcBwFlDTRvYtM0UnggfPMn6uH0CKI8uZsKkyHCu2zSCBLYsuo87sY6zJ | |
| 208 2UwEDyuYvr38HmcNZkb8vk7gpLCeJvFLeLYwpRrQcQy0Q+iElNPFXl5HzlwTNDq5 | |
| 209 5IIiQNlaCV6vUKeX5VhU4i6h4yUWegVoIro4h7KwYQf8CxTrKUnI6WfDuvttU5Z7 | |
| 210 q+7WCTDEnmOT7C2AvOKyfNXlERQnDtY1LHjJe6AEyP2RHnTrHR6Nbi4zQfl4BSZX | |
| 211 hH+ojM/001ir5/m8cOaMpQzHnMyUIi1HenpjJFo5fsMYg+K7j88X4KWlu3YFeB+O | |
| 212 xAp/mf7qUiiTKeDdGJE0u3NkFmXz/G/QDp8zwpqG+/UpiEjMm4OdFMwP68l9FWRX | |
| 213 d1ql5Rfeb50HPIjcmoa1iHq0IJCbT2xXxCm7QyGRy5PwSTMsQnrDUvj6zIBhqusZ | |
| 214 CTHqBXBH3jsDKTBJGQNwOGA418kcEpRsHY+C53rPhoUDnjzBY7dzIstQFsCy1bPZ | |
| 215 qNKoAfFsNjinvrwexRqkDypYLxEKs/nrMM4q+yz8n6Q2BqPT6YvOciHAkE0k4I46 | |
| 216 STZqsFTwWxgWmhLlEFvYul3BWEp5Ow5J6+6TZrHCDIFhoQIHesxmsWVxxlgTG+0M | |
| 217 TS1210ua1nkP+DdWQUBzdDHFxAWWG2pUxzApIPBD2wyeLd1HMVpOjQGpFxMuO8Pd | |
| 218 ZcGqhMpjECMzc4DOAPFbdKwgWKXi95v4zeUf | |
| 219 =Ze0h | |
| 220 -----END PGP MESSAGE----- | |
| 221 | |
| 222 TEXT; | |
| 223 // }}} | |
| 224 | |
| 225 $this->gpg->decryptAndVerify($encryptedData); | |
| 226 } | |
| 227 | |
| 228 // }}} | |
| 229 // {{{ testDecryptVerifyKeyNotFoundException_verify() | |
| 230 | |
| 231 /** | |
| 232 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 233 * | |
| 234 * @group string | |
| 235 */ | |
| 236 public function testDecryptVerifyKeyNotFoundException_verify() | |
| 237 { | |
| 238 // was encrypted with first-keypair@example.com, signed with | |
| 239 // missing-key@example.com | |
| 240 // {{{ encrypted data | |
| 241 $encryptedData = <<<TEXT | |
| 242 -----BEGIN PGP MESSAGE----- | |
| 243 Version: GnuPG v1 | |
| 244 | |
| 245 hQIOA5+T+RFnKO8SEAgAnQrKNrq6O4F0tlex+I5aklo7ElBbSPfa0k4SvX80m+n3 | |
| 246 raM84mpnUzpoXrRa6zSM2IxzF7oWLHHAkBkWaTYdFFWegPbQk4G5rlURZDsLtamb | |
| 247 y3tXcOMuSMhj3b9XrR2YzfREj0AnuEvYOsd++KpjcEYgcVZOb5tCn+9UKfjop/pZ | |
| 248 i9sAJMYbdavxoa8DUuIMT6v0C/zNiuSFlQ23kRWB+LUR0tTIoHpb+0U0ITFLSMIr | |
| 249 jc9K6Zz805Tbu6xX8UXRMIdfJTJkmVWTOD8u8OUPGBxhBuZmbVfH4x+fKybcSVJJ | |
| 250 akqX28LjaqI+WvD/zh9l78V7foMEWd7porUzBC7z+wgAzh3LBHb2naFg4CZSVlYa | |
| 251 uuQ64G1ct0uxwVr0p0/4jA5nEK+WgFABPu1YPnIO3md8dBnkfs92g+0msKgB3FOn | |
| 252 T5+FlgkR+p2Y4knNggSmJGErCMYAq17lCu3bAlHFKwaowCBFoXrFCGBH2qgXD+CM | |
| 253 Rgq5gWXPLrcqnGPefdV56i+8X+t7oHCzIxX836IQICWMpOdhWMzDz44ctC5IBTJp | |
| 254 bDgx2pmkU+i51Q+PfK7k8eBIvlrvBGCQcUiNjCoPKAM3OjGNAQF0JraWPG2q0OSM | |
| 255 aZXKg9aCrQRHceCjwTf8dYRDm6yqGNeVzOnkDibPT3ySYmXKaVDbB8AquS72wE1n | |
| 256 ktLAxwGOjaM4MSQOGT+8eggngFidGak7957SWZRaqsXdeh6HtxKWni+XTBmWAg2m | |
| 257 6MnCIiVxD5A75m75ncdbRgtx2Sl9B/kCTC6Ak6hQ3iFpJKuQSZcD2gyGRSE8Ly7u | |
| 258 cX4jPXcYQaWLi+wVpLaYr3hSsjx2WgVk4oz+X2Kt0qQw+yWIkRw7ErmMl0ML0L7j | |
| 259 YePAE6UbBSR131nDKmXDUlLsV4GavAclENL5Kp6Yd8ia3h1Jdtl0waH5cCLswhf3 | |
| 260 oi0u0bIalnZwDkFSDGiWgDQyJ8XgPFcUx8fp3dC8FVxXbd3quMxZU6/5K/dQ0LIh | |
| 261 +Ldlz797sLtl1lHmlaLEzTzJZriLiEiOCZeOrhbgqcGMLurzfsCWYH+BZFzH8iFJ | |
| 262 yDoUVsWLlvY+6gelAE9Dlzdq9m8rIALwf0Udlsdn/NBaFxarT0nl68u5fSJo8UA2 | |
| 263 MuZd2EB/BKXWvAo5Ea9CQ3DrrDkbwlE3PKrWlMos6dFb/SWxtmKfEeNYhYJsbwsv | |
| 264 x5MBl/I2kBCHeH4= | |
| 265 =hojs | |
| 266 -----END PGP MESSAGE----- | |
| 267 | |
| 268 TEXT; | |
| 269 // }}} | |
| 270 | |
| 271 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 272 $this->gpg->decryptAndVerify($encryptedData); | |
| 273 } | |
| 274 | |
| 275 // }}} | |
| 276 // {{{ testDecryptVerifyKeyNotFoundException_both() | |
| 277 | |
| 278 /** | |
| 279 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 280 * | |
| 281 * @group string | |
| 282 */ | |
| 283 public function testDecryptVerifyKeyNotFoundException_both() | |
| 284 { | |
| 285 // was encrypted and signed with missing-key@example.com | |
| 286 // {{{ encrypted data | |
| 287 $encryptedData = <<<TEXT | |
| 288 -----BEGIN PGP MESSAGE----- | |
| 289 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 290 | |
| 291 hQIOA82wFXJyxZnNEAgA0oz13vLInSM0GlhLyIQ5fRXlttY6jOO6xgUH3MhCqExN | |
| 292 KWLBp9VE+iAzdsnF8hjP+u48qNjYj7Jvyiu8vf1SD9ScYoEiKar0EhZVLfCxX7PC | |
| 293 4ZWCSEWD5h5nBSabdL00f3vL//GrQtMAwcKP4p+pEyxTEoSg7xp10+F0JqnhlIqh | |
| 294 vsOeP4vAeYi1v7x0UyoNxzHbfGb3gjwNaWEixBPMekoEnZ8SOORL5yrOctOjcFxz | |
| 295 hKQFIcJv5vG/Ozs6Wm5q+uvzkZDc2X2dOnb1SpCP5cxNC0g37CiwPIL8ArBcu+yP | |
| 296 5HSC8YhyyVcQTuIdb0a9t/IK0HNfEOF5gCBCQ462Xwf/X3PQgKvvK76DQ8xvukB8 | |
| 297 6yKwaHv2K8NWFyTuPppiiRztVI13zPt/Jjw/YPNE/qUzONiggqWM0tGtVkbNRzic | |
| 298 dMEaAfwmZSix0alMPnDuVNyq9AnCUEjkXKTByWDL4pejvB541dA+rtU1D8pV1/8X | |
| 299 P+oQ+j1EnJitYSTdsnD4YC88/q2RnQTmibmyMclVVk3el6OvZN0Gj0Y2bd9c4LC+ | |
| 300 1reFYZHrX0FcsGIVuHEK/VikTqoWhFOTYUFXFGSE/AGvotfHj2QG3sd297IaSbVi | |
| 301 C1LwWGvpdZ2yw4RV4Zgrqvg8WOL9maj/mX8aE9/gzs9XH2vuucDBOC0RrQPsM6wb | |
| 302 ANKoAdExlp+92b69YSNjP2bRQFjN3gFKaGfBm4ULUhRTFnlfBGIIa+2KHUNB7dYk | |
| 303 obUon363/o/8wdmlXewIwPLK8nQsYXhAyxJcf9o90tqv1L83ZMMLU7FqBkUCmT4a | |
| 304 9EPXbxnaeO3sa8ZuGm0ilGuIFsK24pBOXtYESZ4ix6y7PZOXCJDun4+dFKcfMG+0 | |
| 305 t8TnSlDaIKEuve9kUGwmO8Z3LsYJEsRCsHyN | |
| 306 =YNhC | |
| 307 -----END PGP MESSAGE----- | |
| 308 | |
| 309 TEXT; | |
| 310 // }}} | |
| 311 | |
| 312 $this->gpg->decryptAndVerify($encryptedData); | |
| 313 } | |
| 314 | |
| 315 // }}} | |
| 316 // {{{ testDecryptVerifyKeyNotFoundVerifyIgnoreErrors() | |
| 317 | |
| 318 /** | |
| 319 * @group string | |
| 320 */ | |
| 321 public function testDecryptVerifyKeyNotFoundIgnoreVerifyErrors() | |
| 322 { | |
| 323 $signature = new Crypt_GPG_Signature(); | |
| 324 $signature->setKeyId('8E3D36B1EA5AC75E'); | |
| 325 | |
| 326 $expectedResults = array( | |
| 327 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 328 'signatures' => array($signature) | |
| 329 ); | |
| 330 | |
| 331 // was encrypted with first-keypair@example.com, signed with | |
| 332 // missing-key@example.com | |
| 333 // {{{ encrypted data | |
| 334 $encryptedData = <<<TEXT | |
| 335 -----BEGIN PGP MESSAGE----- | |
| 336 Version: GnuPG v1 | |
| 337 | |
| 338 hQIOA5+T+RFnKO8SEAgAnQrKNrq6O4F0tlex+I5aklo7ElBbSPfa0k4SvX80m+n3 | |
| 339 raM84mpnUzpoXrRa6zSM2IxzF7oWLHHAkBkWaTYdFFWegPbQk4G5rlURZDsLtamb | |
| 340 y3tXcOMuSMhj3b9XrR2YzfREj0AnuEvYOsd++KpjcEYgcVZOb5tCn+9UKfjop/pZ | |
| 341 i9sAJMYbdavxoa8DUuIMT6v0C/zNiuSFlQ23kRWB+LUR0tTIoHpb+0U0ITFLSMIr | |
| 342 jc9K6Zz805Tbu6xX8UXRMIdfJTJkmVWTOD8u8OUPGBxhBuZmbVfH4x+fKybcSVJJ | |
| 343 akqX28LjaqI+WvD/zh9l78V7foMEWd7porUzBC7z+wgAzh3LBHb2naFg4CZSVlYa | |
| 344 uuQ64G1ct0uxwVr0p0/4jA5nEK+WgFABPu1YPnIO3md8dBnkfs92g+0msKgB3FOn | |
| 345 T5+FlgkR+p2Y4knNggSmJGErCMYAq17lCu3bAlHFKwaowCBFoXrFCGBH2qgXD+CM | |
| 346 Rgq5gWXPLrcqnGPefdV56i+8X+t7oHCzIxX836IQICWMpOdhWMzDz44ctC5IBTJp | |
| 347 bDgx2pmkU+i51Q+PfK7k8eBIvlrvBGCQcUiNjCoPKAM3OjGNAQF0JraWPG2q0OSM | |
| 348 aZXKg9aCrQRHceCjwTf8dYRDm6yqGNeVzOnkDibPT3ySYmXKaVDbB8AquS72wE1n | |
| 349 ktLAxwGOjaM4MSQOGT+8eggngFidGak7957SWZRaqsXdeh6HtxKWni+XTBmWAg2m | |
| 350 6MnCIiVxD5A75m75ncdbRgtx2Sl9B/kCTC6Ak6hQ3iFpJKuQSZcD2gyGRSE8Ly7u | |
| 351 cX4jPXcYQaWLi+wVpLaYr3hSsjx2WgVk4oz+X2Kt0qQw+yWIkRw7ErmMl0ML0L7j | |
| 352 YePAE6UbBSR131nDKmXDUlLsV4GavAclENL5Kp6Yd8ia3h1Jdtl0waH5cCLswhf3 | |
| 353 oi0u0bIalnZwDkFSDGiWgDQyJ8XgPFcUx8fp3dC8FVxXbd3quMxZU6/5K/dQ0LIh | |
| 354 +Ldlz797sLtl1lHmlaLEzTzJZriLiEiOCZeOrhbgqcGMLurzfsCWYH+BZFzH8iFJ | |
| 355 yDoUVsWLlvY+6gelAE9Dlzdq9m8rIALwf0Udlsdn/NBaFxarT0nl68u5fSJo8UA2 | |
| 356 MuZd2EB/BKXWvAo5Ea9CQ3DrrDkbwlE3PKrWlMos6dFb/SWxtmKfEeNYhYJsbwsv | |
| 357 x5MBl/I2kBCHeH4= | |
| 358 =hojs | |
| 359 -----END PGP MESSAGE----- | |
| 360 | |
| 361 TEXT; | |
| 362 // }}} | |
| 363 | |
| 364 $this->gpg = new Crypt_GPG(array_merge(array('ignoreVerifyKeyErrors' => true) + $this->getOptions())); | |
| 365 | |
| 366 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 367 $results = $this->gpg->decryptAndVerify($encryptedData, true); | |
| 368 | |
| 369 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 370 } | |
| 371 | |
| 372 // }}} | |
| 373 // {{{ testDecryptVerifyNoDataException_invalid() | |
| 374 | |
| 375 /** | |
| 376 * @expectedException Crypt_GPG_NoDataException | |
| 377 * | |
| 378 * @group string | |
| 379 */ | |
| 380 public function testDecryptVerifyNoDataException_invalid() | |
| 381 { | |
| 382 $encryptedData = 'Invalid OpenPGP data.'; | |
| 383 $this->gpg->decryptAndVerify($encryptedData); | |
| 384 } | |
| 385 | |
| 386 // }}} | |
| 387 // {{{ testDecryptVerifyNoDataException_empty() | |
| 388 | |
| 389 /** | |
| 390 * @expectedException Crypt_GPG_NoDataException | |
| 391 * | |
| 392 * @group string | |
| 393 */ | |
| 394 public function testDecryptVerifyNoDataException_empty() | |
| 395 { | |
| 396 $encryptedData = ''; | |
| 397 $this->gpg->decryptAndVerify($encryptedData); | |
| 398 } | |
| 399 | |
| 400 // }}} | |
| 401 // {{{ testDecryptVerifyBadPassphraseException_missing() | |
| 402 | |
| 403 /** | |
| 404 * @expectedException Crypt_GPG_BadPassphraseException | |
| 405 * | |
| 406 * @group string | |
| 407 */ | |
| 408 public function testDecryptVerifyBadPassphraseException_missing() | |
| 409 { | |
| 410 // encrypted with first-keypair@example.com, signed with | |
| 411 // first-keypair@example.com | |
| 412 // {{{ encrypted data no passphrase | |
| 413 $encryptedData = <<<TEXT | |
| 414 -----BEGIN PGP MESSAGE----- | |
| 415 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 416 | |
| 417 hQIOA5+T+RFnKO8SEAf+M1KnzLUvmJMtRTMpy3G2C8iJN1oQPznWDlL6NqxNeS6N | |
| 418 8ie5dXmaG9csQUx1Ys8QRaPDg6ElVIrJOXQ0CIW3mqxZS7+5X5akH5DQ0Ye4Rggx | |
| 419 yqADpE2z99tlYiNlpEqtG4oAUXzJjWiw8Y6MFg/xAHQUYMhEhZRB4OaSQGVPpxYs | |
| 420 s6YBfRGmWdNrGgPgcwoEmoHvmVKtVOfBNzO9cpl7k2pV12p6eG6jZ1qcCQkSJZlY | |
| 421 z2WsnDYZ9wbXuLM4XanGiJiBau0f+nJqDozmOVvc5Avz1qrQD3Dd5C5cy/e+XPdn | |
| 422 wzTgg3myMrwudAeJZzwMrpcrGwvdzAKE8/7TbNO+3Qf+NqfrApMVUrsFQBdzlLp9 | |
| 423 7cV8nD0uF8ioQjPg0lzJajJdqjEkKB7h9i9fQgL/SBZ29HupsUqDoqmpCVU/B6M0 | |
| 424 YzphMp1qWDRkk5dmpcTppTBsVx1KXCqLQFBIy+Fhc31NZRs1ccaVF3uxaOyMzFhb | |
| 425 FaWlUq03SjU9SlkYiFwyfyDysK3uoGeLfFh5yhH6ly5kthwLo2ov/GANF3pL0cxv | |
| 426 mGUcnZbkhk+MWjmz83loedhh2XpTLqRGuhzWPTQlOUQzf6xbj5zCkzWdnbqFQu19 | |
| 427 Et5O3whgv+ufNvD5LGc/lGQeV8wV7EXcde0ISUa8LKyU+eseS+W6IHsQLPupkCQG | |
| 428 u9KoAQUL3Q3vX1C7WmzS2sudcAulSR8bRYfr6lJ5udRvek7M7tYdLbE1ZLua23T8 | |
| 429 NId1euFhWftuaFjGDRvY37ab+M+zTnMtogSZDkCVyFrM2n4/hFfX9eKX6ljPxPmk | |
| 430 lEmn966i8e4K0jL0Ydvf7qWEVc5uov7xorYnkwvIbaW8SyUPowenfN3qODv7C0Yj | |
| 431 0kOgiJnRxZq+MYOR1b1L6fS0y7jDPI+er8ft | |
| 432 =pycC | |
| 433 -----END PGP MESSAGE----- | |
| 434 | |
| 435 TEXT; | |
| 436 // }}} | |
| 437 | |
| 438 $this->gpg->decryptAndVerify($encryptedData); | |
| 439 } | |
| 440 | |
| 441 // }}} | |
| 442 // {{{ testDecryptVerifyBadPassphraseException_bad() | |
| 443 | |
| 444 /** | |
| 445 * @expectedException Crypt_GPG_BadPassphraseException | |
| 446 * | |
| 447 * @group string | |
| 448 */ | |
| 449 public function testDecryptVerifyBadPassphraseException_bad() | |
| 450 { | |
| 451 // encrypted with first-keypair@example.com, signed with | |
| 452 // first-keypair@example.com | |
| 453 // {{{ encrypted data no passphrase | |
| 454 $encryptedData = <<<TEXT | |
| 455 -----BEGIN PGP MESSAGE----- | |
| 456 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 457 | |
| 458 hQIOA5+T+RFnKO8SEAf+M1KnzLUvmJMtRTMpy3G2C8iJN1oQPznWDlL6NqxNeS6N | |
| 459 8ie5dXmaG9csQUx1Ys8QRaPDg6ElVIrJOXQ0CIW3mqxZS7+5X5akH5DQ0Ye4Rggx | |
| 460 yqADpE2z99tlYiNlpEqtG4oAUXzJjWiw8Y6MFg/xAHQUYMhEhZRB4OaSQGVPpxYs | |
| 461 s6YBfRGmWdNrGgPgcwoEmoHvmVKtVOfBNzO9cpl7k2pV12p6eG6jZ1qcCQkSJZlY | |
| 462 z2WsnDYZ9wbXuLM4XanGiJiBau0f+nJqDozmOVvc5Avz1qrQD3Dd5C5cy/e+XPdn | |
| 463 wzTgg3myMrwudAeJZzwMrpcrGwvdzAKE8/7TbNO+3Qf+NqfrApMVUrsFQBdzlLp9 | |
| 464 7cV8nD0uF8ioQjPg0lzJajJdqjEkKB7h9i9fQgL/SBZ29HupsUqDoqmpCVU/B6M0 | |
| 465 YzphMp1qWDRkk5dmpcTppTBsVx1KXCqLQFBIy+Fhc31NZRs1ccaVF3uxaOyMzFhb | |
| 466 FaWlUq03SjU9SlkYiFwyfyDysK3uoGeLfFh5yhH6ly5kthwLo2ov/GANF3pL0cxv | |
| 467 mGUcnZbkhk+MWjmz83loedhh2XpTLqRGuhzWPTQlOUQzf6xbj5zCkzWdnbqFQu19 | |
| 468 Et5O3whgv+ufNvD5LGc/lGQeV8wV7EXcde0ISUa8LKyU+eseS+W6IHsQLPupkCQG | |
| 469 u9KoAQUL3Q3vX1C7WmzS2sudcAulSR8bRYfr6lJ5udRvek7M7tYdLbE1ZLua23T8 | |
| 470 NId1euFhWftuaFjGDRvY37ab+M+zTnMtogSZDkCVyFrM2n4/hFfX9eKX6ljPxPmk | |
| 471 lEmn966i8e4K0jL0Ydvf7qWEVc5uov7xorYnkwvIbaW8SyUPowenfN3qODv7C0Yj | |
| 472 0kOgiJnRxZq+MYOR1b1L6fS0y7jDPI+er8ft | |
| 473 =pycC | |
| 474 -----END PGP MESSAGE----- | |
| 475 | |
| 476 TEXT; | |
| 477 // }}} | |
| 478 | |
| 479 $this->gpg->addDecryptKey('first-keypair@example.com', 'incorrect'); | |
| 480 $this->gpg->decryptAndVerify($encryptedData); | |
| 481 } | |
| 482 | |
| 483 // }}} | |
| 484 // {{{ testDecryptVerifyDual() | |
| 485 | |
| 486 /** | |
| 487 * @group string | |
| 488 */ | |
| 489 public function testDecryptVerifyDual() | |
| 490 { | |
| 491 // {{{ signature | |
| 492 $signature = new Crypt_GPG_Signature(); | |
| 493 $signature->setId('TAsI7RYUgZAud0wMZu3Iab3bZXo'); | |
| 494 $signature->setKeyFingerprint( | |
| 495 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 496 | |
| 497 $signature->setKeyId('C097D9EC94C06363'); | |
| 498 $signature->setCreationDate(1258955651); | |
| 499 $signature->setExpirationDate(0); | |
| 500 $signature->setValid(true); | |
| 501 | |
| 502 $userId = new Crypt_GPG_UserId(); | |
| 503 $userId->setName('First Keypair Test Key'); | |
| 504 $userId->setComment('do not encrypt important data with this key'); | |
| 505 $userId->setEmail('first-keypair@example.com'); | |
| 506 $signature->setUserId($userId); | |
| 507 // }}} | |
| 508 | |
| 509 $expectedResults = array( | |
| 510 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 511 'signatures' => array($signature) | |
| 512 ); | |
| 513 | |
| 514 // encrypted with both first-keypair@example.com and | |
| 515 // second-keypair@example.com, signed with first-keypair@example.com | |
| 516 // {{{ dual encrypted, signed data | |
| 517 $encryptedData = <<<TEXT | |
| 518 -----BEGIN PGP MESSAGE----- | |
| 519 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 520 | |
| 521 hQIOA5+T+RFnKO8SEAgA2lVokiF7FeQvT0EjgH/X2mXNbz8ukKM7WdIAsIFumg1a | |
| 522 Skfsqn1plAHs3f3OhY16tBb1WW4J8WXEt6g3yHls92XpRUgRTUjVCr4HIvMwSB3A | |
| 523 V/ZQdGs3NK3wh0rMu6q/Ski10dEwP7SUE+w19AmiCQfmKYLUJmCgPLmVm4IapAad | |
| 524 lIpNalUHzXhHuuIzKut9H0n6+p0jUPW2JehFFGud66MS5PaGbDPZS2lKiPjytSzl | |
| 525 pYipuglregaaMR5KsBYxP4A6MnMaRaZriTeItROJ0PTBMaq93+IyrnwulqEsWk6t | |
| 526 8ahRM4FmC+U/Z9tgWxTEKU28zthjxKXW5JOceGxeBQgAoxRAhd75Ok406YG4VucC | |
| 527 rxLSLIKIt0TAlbTWncJq9qhLA86+RL4oqUYfDjq9o9lrfkPQO3xfHam/43j2yaF3 | |
| 528 HeJwSDwU0V4YZ6R9ZVdHMYw7w7yynn2HmNesDUWRfI7IRwMFtgKGvv6qpdUOYmWN | |
| 529 MhQ+HxnwMgvHNaz6TRYpQzVvtpB6q9J3/xCM3+uKxDaJLbJux50s6FpnCRnLpGWs | |
| 530 1Tj8l9BSMlAGtP6dMR3MysZS/UnXwdTmDFR9ARS+HxsP89I95UAKLWaouShoo9dX | |
| 531 QIs0pLkQs+CWpjPVAp8TT0Vj1juThk4bJarti/BaZOyzUAOrleDWOO8VVsuM1Bw2 | |
| 532 xIUCDgOy9U5HV+IkUBAIANU8DKkvHNzkx68XvxXXVsBsWTGNznrNGUjqSfhyS9pW | |
| 533 lRnq7qB2c2UgMvMTnMWyogQ/gKEotdeqKCXdMLBkataB1xkMbCvUZzdj2A/OPtDD | |
| 534 xT7ogqn82YaEjlfEqEbqBi1lvq2tuC/YsGti0c6zDUFoZax6QWL+NU3eCY6ZxBSx | |
| 535 NuZ4hiBJqPeHVP92SCnsC2BwqUy7W0rUuKnXo3VM1syd98TZjdM6SqBVQ61YX3u2 | |
| 536 rS1YiphYd2WeNU/bSZ79bHMMPt3joQ+nCGKvGSIlCVxAy4EPWDb2KFw0yUmXUub1 | |
| 537 tLnrKAOdufWC780LuhgINLb1PSmzogRmvk4ih687h9wH/0hx4olXvkUHZAcpnMHT | |
| 538 zGK8NQeoxfSmcJrYNa1TpQ8FjLad7eycnoIASC4qS7IsJ0xzedWd2eqLdc+9qIiv | |
| 539 68gW2MjZOqQ5PvcZk1eqOVUNH8Ua8Wfv82ljk1VE0L9zzrS8nGLq5prjaK400Vwh | |
| 540 MVh129jyjkpgGZhIHC4cNGBQl1zKDw9WWd1Rk92rpmsvb7JZVNDg0DjW3hrwc7v2 | |
| 541 WbGqEXG5Sown6J1gX4wKIpn9roOE9ZSu1hvugPc28IZIne4rL05Pd4qVnp87SiUh | |
| 542 wHs82nXGhqcscZx2NiT2F///6j97+ccd+619iabKkpfwGunQZHfxit+7bfHuX+5O | |
| 543 tFHSqQEsRi3gNrRlMRDnPjLHXjR+x80anNOwxBfZP1qjdTsFucqmZ57KUdIpUGmi | |
| 544 uRgBZhuVRz8ryTcw5/nACkeKLkxOJLHGgNDilJtNO8tv+BbQDRZzsNYTM7ZNcAo4 | |
| 545 JqkWrMb43BTbAbdgTyEkWhqw6cFQEePYqXcbeDh3c77U5joGZW+iPZQlJbBCMC6e | |
| 546 KBH+5iH8NzPpP6yZq5e5p1ZOkb2PY3EXtL8aemU= | |
| 547 =S/2J | |
| 548 -----END PGP MESSAGE----- | |
| 549 | |
| 550 TEXT; | |
| 551 // }}} | |
| 552 | |
| 553 // decrypt with first key | |
| 554 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 555 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 556 $this->gpg->clearDecryptKeys(); | |
| 557 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 558 | |
| 559 // decrypt with second key | |
| 560 $this->gpg->addDecryptKey('second-keypair@example.com', 'test2'); | |
| 561 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 562 $this->gpg->clearDecryptKeys(); | |
| 563 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 564 } | |
| 565 | |
| 566 // }}} | |
| 567 // {{{ testDecryptVerifyDualOnePassphrase() | |
| 568 | |
| 569 /** | |
| 570 * @group string | |
| 571 */ | |
| 572 public function testDecryptVerifyDualOnePassphrase() | |
| 573 { | |
| 574 // {{{ signature | |
| 575 $signature = new Crypt_GPG_Signature(); | |
| 576 $signature->setId('3OJnX+PqHI0YUCeFxICCxhPHY1Q'); | |
| 577 $signature->setKeyFingerprint( | |
| 578 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 579 | |
| 580 $signature->setKeyId('C097D9EC94C06363'); | |
| 581 $signature->setCreationDate(1258955916); | |
| 582 $signature->setExpirationDate(0); | |
| 583 $signature->setValid(true); | |
| 584 | |
| 585 $userId = new Crypt_GPG_UserId(); | |
| 586 $userId->setName('First Keypair Test Key'); | |
| 587 $userId->setComment('do not encrypt important data with this key'); | |
| 588 $userId->setEmail('first-keypair@example.com'); | |
| 589 $signature->setUserId($userId); | |
| 590 // }}} | |
| 591 | |
| 592 $expectedResults = array( | |
| 593 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 594 'signatures' => array($signature) | |
| 595 ); | |
| 596 | |
| 597 // encrypted with both first-keypair@example.com and | |
| 598 // no-passhprase@example.com, signed with first-keypair@example.com | |
| 599 // {{{ dual encrypted, signed data | |
| 600 $encryptedData = <<<TEXT | |
| 601 -----BEGIN PGP MESSAGE----- | |
| 602 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 603 | |
| 604 hQIOA5+T+RFnKO8SEAgA7zHd9KH/C2GCM9H7pdMS76PXGfmhGPyQAtokBQgF8G1/ | |
| 605 orldCnTUnxmZejbOwYhYVEh5zlnYshlCpUSsGBw+sH7XiC8eorCD0YJj5NDBp8W6 | |
| 606 VtvGkMqqG9tDJk6TfKornFl+H7xpiwXox5T/swnpJcJ6qaTXBtLb7HViiwTTu5Zk | |
| 607 QbWqSvIOigIkiuTnv898/eeEIh9gg6ScRVZOyZ7P2usDaOWqVVNJmkaLIaWxOYck | |
| 608 Go3hnYAhkfjpMcgAMkqtXPWIS8OrfY8wOXxXNA4EjvrHs+5/yHbZmj/5bBA9CuGJ | |
| 609 UctQqF9ZtZsagSpK0WTJCt4RkX3jKqK9tJVQzBuKZgf/Up3Zi6Lfg6iINm4qsd1h | |
| 610 Dusuuxw0vgGoMc6P7QOMFmeSs3g/yYQKaHomWqEVg0LpC2FHOqceqZRZJd4XMcsz | |
| 611 uCF95lx7Tm1ozgEhBgQNSQVoAA5/MYXlKo3YQGEIyU9Gx4f2v/8XV3umYXjGfJY9 | |
| 612 adBHLIvPFeeze1/f11ztZsgLr3DBP01/O6qLi91dwsqpzQXzjurVYIHJdCD+JviZ | |
| 613 2CjwkcpUTHx5vXNiobMcBjtogjP7d4W8DJ0La5+WVujV0nxHiE9mEXuct8TajCY6 | |
| 614 /40UIdtHEPWc08ccXXjQaFKbJxYGDMOJzQ8LPdHqa3RubmMADqzH4W3/SSmRsibd | |
| 615 4YUCDgMkvzgHAMFLTxAH/R3ryj2BUP6C/aYfgGqi+FOVoHVR5kiz6Z2nBEKqntwZ | |
| 616 njdKD+pvuw9fxaNhNNZy3UlKnIdonNb/A3upEeR81opP+HWCgXUlcgucQ7VXiUPd | |
| 617 mnQAR+cTrFgTXf+B54VHwDED5RVDm4/e29casiNyULm6xWFYqfJMGBvEGrflq1BW | |
| 618 QSYlpc0ijqkER+VNy49Dy/qY1TRUBZ84+RmL2L/18zQbdekMoLUDxJOEoo0C65ER | |
| 619 5ReLlFN2nI0MC8O5ZU8PfjDXXQ7qnQhz/2kxorNiQl654V7ZsEWkVLF9yejZXSzU | |
| 620 ynWANJdCnWLMjOnrQPm1+b2Yi8pcgtpIPsBdTIHn4fAH/iW0Uxltx9ZrV7kvrDDj | |
| 621 Izc4/ocn3Z0c/47Rv62MTYcxVYzFdP+WxisMI2LV88g1Zu9rOKR1k7UkNGNlfklS | |
| 622 5CSApTnm3MC9/w54dacPohZ7SrQlTSHJxfRINH7H3DOuaH9awf+ntwUks73mXjT5 | |
| 623 ikSJ2D05Kbf8++jLhRRKLPZS8bOmSw2KTaCbtk7LX4pEIu9d6kig6g8Wj3h9dlQs | |
| 624 QXCKL14/8cSGrxXXWHOuL9abnxZTwenbn5B5FqBPoiRKqSFToiLd/pBWjG/aieju | |
| 625 Rm+Uyyddl+ISJUnv0AAiOxfifJmTdUsT5LZLkYG4CUyX2T3JiZ2L4msF4S3U70wp | |
| 626 PtbSqAG3xVRFlZY2jLeW8btez7XkzB9fhvVd1Hee6EXRnF5/BcLkqy8sYvx1MHkT | |
| 627 eMzttOs1NRrjXy4+zUqo//59gQ46zwYd0NA/Ga6pl1kn8+xM76DCcI4LhdZN75rR | |
| 628 ZUcyEqBKX9RNefMD7cR6kYoljGfnT3Mjd+0eTdF/Glk0ElVjbMtQclG0o/7wlI7m | |
| 629 +b2E6/e0qZedOCq48+mIRv0tjRuoFiydM88aGg== | |
| 630 =IgJ0 | |
| 631 -----END PGP MESSAGE----- | |
| 632 | |
| 633 TEXT; | |
| 634 // }}} | |
| 635 | |
| 636 // decrypt with no passphrase | |
| 637 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 638 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 639 | |
| 640 // decrypt with first key | |
| 641 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 642 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 643 $this->gpg->clearDecryptKeys(); | |
| 644 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 645 } | |
| 646 | |
| 647 // }}} | |
| 648 // {{{ testDecryptAndVerifyDualNoPassphraseKeyMissing() | |
| 649 | |
| 650 /** | |
| 651 * @expectedException Crypt_GPG_BadPassphraseException | |
| 652 * | |
| 653 * @group string | |
| 654 */ | |
| 655 public function testDecryptAndVerifyDualNoPassphraseKeyMissing() | |
| 656 { | |
| 657 // encrypted with both first-keypair@example.com and | |
| 658 // second-keypair@example.com | |
| 659 // {{{ dual encrypted data | |
| 660 $encryptedData = <<<TEXT | |
| 661 -----BEGIN PGP MESSAGE----- | |
| 662 Version: GnuPG v1.4.6 (GNU/Linux) | |
| 663 | |
| 664 hQIOA5+T+RFnKO8SEAf7BO/zLK6gDt5epMOEnHc9ESdSTy8yExdoSxHhvTFxWfwi | |
| 665 AwMtBEur8sotSVt+Q87xYzjzE77+FQYS9oYCivlK/Nedblj3MiRuUWhM+Q9tbP3b | |
| 666 KbwEwaQlrpNphQsKZOWkliZWmFJWnQ1s1Pm6lPlhwTNhcwkapm8EXuWFExJnY9yW | |
| 667 EZjUOhVmnkitKykKup8Brvfm2QpGXoFZtHFKXTi162Lue9N0tDm6s3JnCIhMFQgI | |
| 668 fyAikcsJKpbUgeGmzlWJO8QkH81QMuKpqfUb8R1dswhDp6RKXhoXS43zkhH8QSbM | |
| 669 Cp9AWdv3qsWBUqzWavCxjtIsogYO+gFLl/Vuw5Y87Af/b7OQgLP1v6xKZcrTvFCF | |
| 670 hxGxn+5M8E2GyJaKpQ1GZ+Wv+IzPGetm7rWf6q71hchAkxFMczIPSK7aARm9CNVo | |
| 671 7tCdcUmUTgLhG1/0OfmkbwJUjdSpOtz8+TvIZa20Jj9a1G8WT3KTeivKMqBPhgk4 | |
| 672 sD7OJPDCYQNSQEw6pAn4oBrhJlDUkpCK6wIbUhzeq3MUwtM1e+qpCr/k4In4NVq6 | |
| 673 cmoC7W//9J69ecuxmiUHRhZ4CALRxQMAsSxMRnNJ26JY4ko82Rfvbrz8QEmKcIyT | |
| 674 bTdAMsZ18m9XXrnc2ACDDMQyUkneQDUZSt7V67ZiN4Upi295CynIbNEMmcH/13Aa | |
| 675 aoUCDgOy9U5HV+IkUBAIALGICOFzyfquWZ0ZhPGVdDWx1yNcApnzIgZx1JbBpMyc | |
| 676 2jb9aQHwGId26gv/ym/M/3FJ0lv+IAcktMjO4dwYLnUuBa6BOFFybZi3gYvXtSuy | |
| 677 iW4ygVjIsYixhvbsyaVCoB/MsNBFrQAHEShaxALBkI/dv+yyD8BifU4Yj9LFcAZO | |
| 678 mFDraOgYfHsur5eevYTXozf5wU7phu9v6zo5bk8zgZSqs8AgyscstZWCqCtR/cG0 | |
| 679 t9lAIovGPsIcA12qvkm/A0WiBMEWhGryzHTv9oRsFztOFtqH+MmLdlvWjElw8hKt | |
| 680 fFJB+bhHNO9BUIrwnuH79cA4aXOy1+xG+ECs7oJbcisIANqJKalQLgBYEjbucpDg | |
| 681 O8i/c4RmV9J7VczpZp7ZREMpTmv9nV849OFXT1strsb/+vXOXOyLToG1gOxRfJr2 | |
| 682 q9jFjpyMAtrr/aHhXMKK1OMhhcdkQMEKuHTvon5KleZOQoVmIqa3kUtWNW1vFBIP | |
| 683 UfJFH202EJLOLC25rXCtzRsJE0HWiYDyLqKMQcSQhTcngLBLmeDLH3DeGUIDwcZe | |
| 684 oWgUg8wB/oSoU4AchShzO+yM6bcmffcaHFqwll9gdu9walnJAAOb8+r6LGGlsGTV | |
| 685 qhnR0LM3Khp+HOFdaxcQT6BV1aw/D6Z5hIi+Am0VTi0HlFr/gwleyYaP+742Z6K0 | |
| 686 s8bSVgFT2Pjik+byARWzRwWjmi0jT7QsgITM73aBKPDXiArEPkv8YtC9HzUj0lCY | |
| 687 gX7Eg2ZqISULFydBckMJ6drojMMQiqZBeEc09GupSBL1zldnKHfiXBTw | |
| 688 =QYjj | |
| 689 -----END PGP MESSAGE----- | |
| 690 | |
| 691 TEXT; | |
| 692 // }}} | |
| 693 | |
| 694 // #21148: Make sure that proper exception is thrown | |
| 695 // when decrypting without specyfying a passphrase | |
| 696 | |
| 697 // in this case we remove one of private keys to make | |
| 698 // sure proper exception is thrown also in this case | |
| 699 $this->gpg->deletePrivateKey('first-keypair@example.com'); | |
| 700 | |
| 701 $this->gpg->decryptAndVerify($encryptedData); | |
| 702 } | |
| 703 | |
| 704 // }}} | |
| 705 // {{{ testDecryptVerifyDualSignatories() | |
| 706 | |
| 707 /** | |
| 708 * @group string | |
| 709 */ | |
| 710 public function testDecryptVerifyDualSignatories() | |
| 711 { | |
| 712 // {{{ signature1 | |
| 713 $signature1 = new Crypt_GPG_Signature(); | |
| 714 $signature1->setId('7PujVkx4qk28IejcD6BirrwBmRE'); | |
| 715 $signature1->setKeyFingerprint( | |
| 716 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 717 | |
| 718 $signature1->setKeyId('C097D9EC94C06363'); | |
| 719 $signature1->setCreationDate(1258956025); | |
| 720 $signature1->setExpirationDate(0); | |
| 721 $signature1->setValid(true); | |
| 722 | |
| 723 $userId1 = new Crypt_GPG_UserId(); | |
| 724 $userId1->setName('First Keypair Test Key'); | |
| 725 $userId1->setComment('do not encrypt important data with this key'); | |
| 726 $userId1->setEmail('first-keypair@example.com'); | |
| 727 $signature1->setUserId($userId1); | |
| 728 // }}} | |
| 729 // {{{ signature2 | |
| 730 $signature2 = new Crypt_GPG_Signature(); | |
| 731 $signature2->setId('AhrDdkdcBsEsOSQOYENhl5C7auc'); | |
| 732 $signature2->setKeyFingerprint( | |
| 733 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
| 734 | |
| 735 $signature2->setKeyId('03CC890AFA1DAD4B'); | |
| 736 $signature2->setCreationDate(1258956025); | |
| 737 $signature2->setExpirationDate(0); | |
| 738 $signature2->setValid(true); | |
| 739 | |
| 740 $userId2 = new Crypt_GPG_UserId(); | |
| 741 $userId2->setName('Second Keypair Test Key'); | |
| 742 $userId2->setComment('do not encrypt important data with this key'); | |
| 743 $userId2->setEmail('second-keypair@example.com'); | |
| 744 $signature2->setUserId($userId2); | |
| 745 // }}} | |
| 746 | |
| 747 $expectedResults = array( | |
| 748 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 749 'signatures' => array($signature1, $signature2) | |
| 750 ); | |
| 751 | |
| 752 // encrypted with first-keypair@example.com and signed with | |
| 753 // first-keypair@example.com and second-keypair@example.com | |
| 754 // {{{ encrypted, dual signed data | |
| 755 $encryptedData = <<<TEXT | |
| 756 -----BEGIN PGP MESSAGE----- | |
| 757 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 758 | |
| 759 hQIOA5+T+RFnKO8SEAgAzllqH/z2ThJcXteCxPJu97EmMpqdipbcSUAjGZJ5hQFe | |
| 760 YlKbrxL30W6VYgZIPqP5FubZkI8WHWqDZwbtphk5l+o8nfyNV4el/JHHEmf/mzIM | |
| 761 UmBXJFVa6g9CmS/SdhYhO/ovMeBsNVA1+Er+Cdyh9sTpX89I3zlehgwcXtv/di6W | |
| 762 fjzeg5Na/39KfYWEyXPB5EUkWG4hmnGo63GPUEsxfNXbKDafUtTwOFop+1+wMVyA | |
| 763 kJbOEaaiTSzvbpa+ruRisv34a6vX8u6QGqPSZ43vgmKeWfPEBS8p7bdRFGECLNvP | |
| 764 gK4tIwlBI0o13JJ/lnjL6dR2f7qls/0dxBGxhjFpjAf/bn5d8r7e2N1yJqh1C5T0 | |
| 765 /n/ngN1bHDsQhrAPMJfJre7qJxZEiHa8dfagdDU6I/EC4w1ouUYKWrzf9sPKTxs+ | |
| 766 QosiqrGKYUO1V46EzRXc72PZBKf5CZBBvRZv3GzzcVtroViiIshyAp3TBPk2GC+N | |
| 767 ilmEm72CWgQHKqg4vX1hbTCbOEu/YDmjF9Vb9a/zT5RAKDjBrcc9tkPdVMfDfI2Y | |
| 768 Ly6CvL2DSvBUNbAShl2TXdTdylYbopyiFhOBvJoeidFVwIFX303nFUBMUfbCT6WK | |
| 769 MGZGzXrNZlRyKfH9UCj+5pxom2TMpu+URfvXtByUGfNst+ZRi+ADOnbc51canwWc | |
| 770 M9LAKgG6SF2OhrDTTe+KASz3dFbpD4xnczl+686GGT76W55YKQNDff72bhx8lBnP | |
| 771 XiM+CsWGPLZdoOCQU+SEWD7lJ1I6fB+l/oFWC2PVlDjrCS1Nn/L9i5p+EqNzcUVB | |
| 772 JR62EaLPsOFOfNeHhltuz2aYkvQT4sDPeKkpBKJDp2ejMy3V9ZXia1D2ZTCfMp+J | |
| 773 GEu2SS68qlZV12gpSwY8BpS/nirx5aUQ9VhjlSN3GHF/r6j91VsHJhmU+nmWPWaF | |
| 774 mHfMGHS5sw6+gz3SyW6b4TlUnnx412nhFinanxBlwkuAcukgL8k+OesoDX2a1Q== | |
| 775 =TW+z | |
| 776 -----END PGP MESSAGE----- | |
| 777 | |
| 778 TEXT; | |
| 779 // }}} | |
| 780 | |
| 781 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 782 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 783 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 784 } | |
| 785 | |
| 786 // }}} | |
| 787 // {{{ testDecryptVerifySignedOnly() | |
| 788 | |
| 789 /** | |
| 790 * @group string | |
| 791 */ | |
| 792 public function testDecryptVerifySignedOnly() | |
| 793 { | |
| 794 // {{{ signature | |
| 795 $signature = new Crypt_GPG_Signature(); | |
| 796 $signature->setId('LS9EdhGLaEUllGk3Snc0Bk+Cn3E'); | |
| 797 $signature->setKeyFingerprint( | |
| 798 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 799 | |
| 800 $signature->setKeyId('C097D9EC94C06363'); | |
| 801 $signature->setCreationDate(1258956761); | |
| 802 $signature->setExpirationDate(0); | |
| 803 $signature->setValid(true); | |
| 804 | |
| 805 $userId = new Crypt_GPG_UserId(); | |
| 806 $userId->setName('First Keypair Test Key'); | |
| 807 $userId->setComment('do not encrypt important data with this key'); | |
| 808 $userId->setEmail('first-keypair@example.com'); | |
| 809 $signature->setUserId($userId); | |
| 810 // }}} | |
| 811 | |
| 812 $expectedResults = array( | |
| 813 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 814 'signatures' => array($signature) | |
| 815 ); | |
| 816 | |
| 817 // signed with first-keypair@example.com | |
| 818 // {{{ signed data | |
| 819 $signedData = <<<TEXT | |
| 820 -----BEGIN PGP MESSAGE----- | |
| 821 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 822 | |
| 823 owGbwMvMwCR4YPrNN1MOJCcznlZMYvDmUr/pkZqTk6+j4JiTmZyqqOCen5+SVJmq | |
| 824 o+CUn6TY4cbCIMjEwMbKBFLIwMUpANNttphhwWm3a/VsLcc+u0x4/Xtyuk/Xiqd3 | |
| 825 ZzMsuHZrvkPCHgUTgcXFLt6GVRlPYvT5AQ== | |
| 826 =ehgC | |
| 827 -----END PGP MESSAGE----- | |
| 828 | |
| 829 TEXT; | |
| 830 // }}} | |
| 831 | |
| 832 $results = $this->gpg->decryptAndVerify($signedData); | |
| 833 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 834 } | |
| 835 | |
| 836 // }}} | |
| 837 // {{{ testDecryptVerifyFirstSubKey() | |
| 838 | |
| 839 /** | |
| 840 * @group string | |
| 841 */ | |
| 842 public function testDecryptVerifyFirstSubKey() | |
| 843 { | |
| 844 // {{{ signature | |
| 845 $signature = new Crypt_GPG_Signature(); | |
| 846 $signature->setId('YUeHL9fEAK4hMokvXsNgUP5vaJ8'); | |
| 847 $signature->setKeyFingerprint( | |
| 848 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 849 | |
| 850 $signature->setKeyId('C097D9EC94C06363'); | |
| 851 $signature->setCreationDate(1267228319); | |
| 852 $signature->setExpirationDate(0); | |
| 853 $signature->setValid(true); | |
| 854 | |
| 855 $userId = new Crypt_GPG_UserId(); | |
| 856 $userId->setName('First Keypair Test Key'); | |
| 857 $userId->setComment('do not encrypt important data with this key'); | |
| 858 $userId->setEmail('first-keypair@example.com'); | |
| 859 $signature->setUserId($userId); | |
| 860 // }}} | |
| 861 | |
| 862 $expectedResults = array( | |
| 863 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 864 'signatures' => array($signature) | |
| 865 ); | |
| 866 | |
| 867 // encrypted with first subkey (ELG-E) of multiple-subkeys@example.com, | |
| 868 // signed with first-keypair@example.com | |
| 869 // {{{ encrypted data | |
| 870 $encryptedData = <<<TEXT | |
| 871 -----BEGIN PGP MESSAGE----- | |
| 872 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 873 | |
| 874 hQEMAykh4NP/Ww9KAQgAhB2Ww2jNhy9ISQ/+S52eROzbN8ij65GoL9tTHK5TZp82 | |
| 875 mv+ieGwobe5PGYdBEvQdsSrKyF3x25oaEyjaOa+39DtmF82OZKZ3tIO3EJ1qvn8q | |
| 876 SHxwiKYa4MOgwER9pT7i/YZOZuIdII/NeuVuGxbsa5qdISltKkE7WS7yWStcDJi1 | |
| 877 goaPx3G1cZIVnTgSncK1YE4j2TZXBxI/zuuuH0pbZk7rK+K9zIeyYD1YZFagrjJh | |
| 878 REN5QbnT1v+1HXno1WRp4Obo072i3FjF505U1XLQ5p2/d55m73jfBJoqpb2NExdU | |
| 879 KimXnQZ+8/8ddzL3ZP4+g982dmLFvl2/h7KGtPOMbdKoAeMQYVolMDoQp6+nyQHP | |
| 880 CgpeFJY5+VnxNq1wEgJgXTo79xohN59wwad1ltcUGAVC49RMHbX+xBjR/HPCG9yt | |
| 881 QTwMes514uPYbNL6cGoKm7dt/zQL8YsjvfswGE06bj/rU3JCTDnR+iOUDHzUMDEn | |
| 882 jH7Vbs+9D1E9t5bSJs/8e7rzhZKF1AhunUdDmc4vPPJMV8xKF+o3h3nKQ6wEoOMz | |
| 883 f6XGFW8cvNAl | |
| 884 =vSGT | |
| 885 -----END PGP MESSAGE----- | |
| 886 | |
| 887 TEXT; | |
| 888 // }}} | |
| 889 | |
| 890 $this->gpg->addDecryptKey('multiple-subkeys@example.com', 'test'); | |
| 891 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 892 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 893 } | |
| 894 | |
| 895 // }}} | |
| 896 // {{{ testDecryptVerifySecondSubKey() | |
| 897 | |
| 898 /** | |
| 899 * @group string | |
| 900 */ | |
| 901 public function testDecryptVerifySecondSubKey() | |
| 902 { | |
| 903 // {{{ signature | |
| 904 $signature = new Crypt_GPG_Signature(); | |
| 905 $signature->setId('ZLZFDxxO+zdCEklUu6eppBCPCsA'); | |
| 906 $signature->setKeyFingerprint( | |
| 907 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 908 | |
| 909 $signature->setKeyId('C097D9EC94C06363'); | |
| 910 $signature->setCreationDate(1267229043); | |
| 911 $signature->setExpirationDate(0); | |
| 912 $signature->setValid(true); | |
| 913 | |
| 914 $userId = new Crypt_GPG_UserId(); | |
| 915 $userId->setName('First Keypair Test Key'); | |
| 916 $userId->setComment('do not encrypt important data with this key'); | |
| 917 $userId->setEmail('first-keypair@example.com'); | |
| 918 $signature->setUserId($userId); | |
| 919 // }}} | |
| 920 | |
| 921 $expectedResults = array( | |
| 922 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 923 'signatures' => array($signature) | |
| 924 ); | |
| 925 | |
| 926 // encrypted with second subkey (RSA) of multiple-subkeys@example.com, | |
| 927 // signed with first-keypair@example.com | |
| 928 // {{{ encrypted data | |
| 929 $encryptedData = <<<TEXT | |
| 930 -----BEGIN PGP MESSAGE----- | |
| 931 Version: GnuPG v1.4.9 (GNU/Linux) | |
| 932 | |
| 933 hQEMAykh4NP/Ww9KAQgAs1xviSlaTTGXWNzT43giUSf7SnYoeoyYqZt/eo7c9eHu | |
| 934 sLGdhhpQeUiU5vW6UsOvs3QLx3hR9wYunUOKmDJmrrtVglsZIjuHU7oYlveozYwG | |
| 935 wlHNbesQlWyMNSQPDeGWAQAnOUU2jv/9nb93SLYlkDKr1qjn9qjZ4Kl2q1Yi4PSu | |
| 936 LaqI3r1LdJbFmEB6vQ8o6GiIpaFaZapK6vloPoq5xbaALAfAiSg58+IwV/Mn190L | |
| 937 T0tmFCUuTm/Px8fv5xe+mPW2pMUovhJhBrhBopEcWNHpxuNbxwac1T54COZxjC8W | |
| 938 L0XpYW7c3XVdO6VqS4pSnz+zo5EYcU2Sk6mfpN5ki9KoAdPZ4ICMe0OWIjMxgApI | |
| 939 AVHaKowZ6+xSW8vLRzWjJTZrlEoMjwJSOJwCsMcsu6MwJOFcVEl4Mc3TiAMsUHWf | |
| 940 6f/pHb7W2Am12CfJaaU0+nDQrlKOw5DfQG5YEG/LrpjXGugVWMQH/31MMKawSAP3 | |
| 941 QgdXe417ZeMtsHVaz/W1Za5ZpRpcwoT5N31LfNV+SoIpajhmtr79aeg8d6OH8H+l | |
| 942 7kLEDVlh9DP0 | |
| 943 =I21n | |
| 944 -----END PGP MESSAGE----- | |
| 945 | |
| 946 TEXT; | |
| 947 // }}} | |
| 948 | |
| 949 $this->gpg->addDecryptKey('multiple-subkeys@example.com', 'test'); | |
| 950 $results = $this->gpg->decryptAndVerify($encryptedData); | |
| 951 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 952 } | |
| 953 | |
| 954 // }}} | |
| 955 // {{{ testDecryptVerifySignedOnlyBadSignature() | |
| 956 | |
| 957 /** | |
| 958 * @group string | |
| 959 */ | |
| 960 public function testDecryptVerifySignedOnlyBadSignature() | |
| 961 { | |
| 962 // {{{ signature | |
| 963 $signature = new Crypt_GPG_Signature(); | |
| 964 $signature->setValid(false); | |
| 965 $signature->setKeyId('C097D9EC94C06363'); | |
| 966 $userId = new Crypt_GPG_UserId(); | |
| 967 $userId->setName('First Keypair Test Key'); | |
| 968 $userId->setComment('do not encrypt important data with this key'); | |
| 969 $userId->setEmail('first-keypair@example.com'); | |
| 970 $signature->setUserId($userId); | |
| 971 // }}} | |
| 972 | |
| 973 $expectedResults = array( | |
| 974 'data' => "Hello, Bob! Goodbye, Alice!\n", | |
| 975 'signatures' => array($signature) | |
| 976 ); | |
| 977 | |
| 978 // {{{ clearsigned data | |
| 979 $clearsignedData = <<<TEXT | |
| 980 -----BEGIN PGP SIGNED MESSAGE----- | |
| 981 Hash: SHA1 | |
| 982 | |
| 983 Hello, Bob! Goodbye, Alice! | |
| 984 -----BEGIN PGP SIGNATURE----- | |
| 985 Version: GnuPG v1.4.6 (GNU/Linux) | |
| 986 | |
| 987 iD8DBQFI0vkCwJfZ7JTAY2MRAgzTAKCRecYZsCS+PE46Fa2QLTEP8XGLwwCfQEAL | |
| 988 qO+KlKcldtYdMZH9AA+KOLQ= | |
| 989 =EO2G | |
| 990 -----END PGP SIGNATURE----- | |
| 991 | |
| 992 TEXT; | |
| 993 // }}} | |
| 994 | |
| 995 $results = $this->gpg->decryptAndVerify($clearsignedData); | |
| 996 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 997 } | |
| 998 | |
| 999 // }}} | |
| 1000 // {{{ testDecryptVerifyFile() | |
| 1001 | |
| 1002 /** | |
| 1003 * @group file | |
| 1004 */ | |
| 1005 public function testDecryptVerifyFile() | |
| 1006 { | |
| 1007 // {{{ signature | |
| 1008 $signature = new Crypt_GPG_Signature(); | |
| 1009 $signature->setId('kVwy2yYB0TlXyGd9FUvVYp5jCoI'); | |
| 1010 $signature->setKeyFingerprint( | |
| 1011 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1012 | |
| 1013 $signature->setKeyId('C097D9EC94C06363'); | |
| 1014 $signature->setCreationDate(1258220197); | |
| 1015 $signature->setExpirationDate(0); | |
| 1016 $signature->setValid(true); | |
| 1017 | |
| 1018 $userId = new Crypt_GPG_UserId(); | |
| 1019 $userId->setName('First Keypair Test Key'); | |
| 1020 $userId->setComment('do not encrypt important data with this key'); | |
| 1021 $userId->setEmail('first-keypair@example.com'); | |
| 1022 $signature->setUserId($userId); | |
| 1023 // }}} | |
| 1024 | |
| 1025 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1026 $expectedResults = array( | |
| 1027 'data' => null, | |
| 1028 'signatures' => array($signature) | |
| 1029 ); | |
| 1030 | |
| 1031 $inputFilename = $this->getDataFilename('testDecryptVerifyFile.asc'); | |
| 1032 $outputFilename = $this->getTempFilename('testDecryptVerifyFile.plain'); | |
| 1033 | |
| 1034 // file is encrypted with first-keypair@example.com | |
| 1035 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1036 $results = $this->gpg->decryptAndVerifyFile( | |
| 1037 $inputFilename, | |
| 1038 $outputFilename | |
| 1039 ); | |
| 1040 | |
| 1041 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1042 | |
| 1043 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1044 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1045 } | |
| 1046 | |
| 1047 // }}} | |
| 1048 // {{{ testDecryptVerifyFileToString() | |
| 1049 | |
| 1050 /** | |
| 1051 * @group file | |
| 1052 */ | |
| 1053 public function testDecryptVerifyFileToString() | |
| 1054 { | |
| 1055 // {{{ signature | |
| 1056 $signature = new Crypt_GPG_Signature(); | |
| 1057 $signature->setId('GTvYFmQ5yfMM/UOffkYCx21Se2M'); | |
| 1058 $signature->setKeyFingerprint( | |
| 1059 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1060 | |
| 1061 $signature->setKeyId('C097D9EC94C06363'); | |
| 1062 $signature->setCreationDate(1258221035); | |
| 1063 $signature->setExpirationDate(0); | |
| 1064 $signature->setValid(true); | |
| 1065 | |
| 1066 $userId = new Crypt_GPG_UserId(); | |
| 1067 $userId->setName('First Keypair Test Key'); | |
| 1068 $userId->setComment('do not encrypt important data with this key'); | |
| 1069 $userId->setEmail('first-keypair@example.com'); | |
| 1070 $signature->setUserId($userId); | |
| 1071 // }}} | |
| 1072 | |
| 1073 $expectedSignatures = array($signature); | |
| 1074 $expectedResults = array( | |
| 1075 'data' => 'Hello, Alice! Goodbye, Bob!', | |
| 1076 'signatures' => $expectedSignatures | |
| 1077 ); | |
| 1078 | |
| 1079 $inputFilename = $this->getDataFilename( | |
| 1080 'testDecryptVerifyFileToString.asc' | |
| 1081 ); | |
| 1082 | |
| 1083 // file is encrypted with first-keypair@example.com | |
| 1084 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1085 $results = $this->gpg->decryptAndVerifyFile($inputFilename); | |
| 1086 | |
| 1087 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1088 } | |
| 1089 | |
| 1090 // }}} | |
| 1091 // {{{ testDecryptVerifyFileNoPassphrase() | |
| 1092 | |
| 1093 /** | |
| 1094 * @group file | |
| 1095 */ | |
| 1096 public function testDecryptVerifyFileNoPassphrase() | |
| 1097 { | |
| 1098 // {{{ signature | |
| 1099 $signature = new Crypt_GPG_Signature(); | |
| 1100 $signature->setId('unMY9l/f9sFaMvMV0H1ZuNJRY6Q'); | |
| 1101 $signature->setKeyFingerprint( | |
| 1102 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1103 | |
| 1104 $signature->setKeyId('C097D9EC94C06363'); | |
| 1105 $signature->setCreationDate(1258220226); | |
| 1106 $signature->setExpirationDate(0); | |
| 1107 $signature->setValid(true); | |
| 1108 | |
| 1109 $userId = new Crypt_GPG_UserId(); | |
| 1110 $userId->setName('First Keypair Test Key'); | |
| 1111 $userId->setComment('do not encrypt important data with this key'); | |
| 1112 $userId->setEmail('first-keypair@example.com'); | |
| 1113 $signature->setUserId($userId); | |
| 1114 // }}} | |
| 1115 | |
| 1116 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1117 $expectedResults = array( | |
| 1118 'data' => null, | |
| 1119 'signatures' => array($signature) | |
| 1120 ); | |
| 1121 | |
| 1122 $inputFilename = $this->getDataFilename( | |
| 1123 'testDecryptVerifyFileNoPassphrase.asc' | |
| 1124 ); | |
| 1125 $outputFilename = $this->getTempFilename( | |
| 1126 'testDecryptVerifyFileNoPassphrase.plain' | |
| 1127 ); | |
| 1128 | |
| 1129 // file is encrypted with no-passphrase@example.com | |
| 1130 $results = $this->gpg->decryptAndVerifyFile( | |
| 1131 $inputFilename, | |
| 1132 $outputFilename | |
| 1133 ); | |
| 1134 | |
| 1135 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1136 | |
| 1137 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1138 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1139 } | |
| 1140 | |
| 1141 // }}} | |
| 1142 // {{{ testDecryptVerifyFileFileException_input() | |
| 1143 | |
| 1144 /** | |
| 1145 * @expectedException Crypt_GPG_FileException | |
| 1146 * | |
| 1147 * @group file | |
| 1148 */ | |
| 1149 public function testDecryptVerifyFileFileException_input() | |
| 1150 { | |
| 1151 // input file does not exist | |
| 1152 $inputFilename = $this->getDataFilename( | |
| 1153 'testDecryptVerifyFileFileException_input.asc' | |
| 1154 ); | |
| 1155 | |
| 1156 $this->gpg->decryptAndVerifyFile($inputFilename); | |
| 1157 } | |
| 1158 | |
| 1159 // }}} | |
| 1160 // {{{ testDecryptVerifyFileFileException_output() | |
| 1161 | |
| 1162 /** | |
| 1163 * @expectedException Crypt_GPG_FileException | |
| 1164 * | |
| 1165 * @group file | |
| 1166 */ | |
| 1167 public function testDecryptVerifyFileFileException_output() | |
| 1168 { | |
| 1169 // input file is encrypted with first-keypair@example.com | |
| 1170 // output file does not exist | |
| 1171 $inputFilename = $this->getDataFilename('testDecryptVerifyFile.asc'); | |
| 1172 $outputFilename = './non-existent' . | |
| 1173 '/testDecryptVerifyFileFileException_output.plain'; | |
| 1174 | |
| 1175 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1176 $this->gpg->decryptAndVerifyFile($inputFilename, $outputFilename); | |
| 1177 } | |
| 1178 | |
| 1179 // }}} | |
| 1180 // {{{ testDecryptVerifyFileKeyNotFoundException_decrypt() | |
| 1181 | |
| 1182 /** | |
| 1183 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 1184 * | |
| 1185 * @group file | |
| 1186 */ | |
| 1187 public function testDecryptVerifyFileKeyNotFoundException_decrypt() | |
| 1188 { | |
| 1189 // file is encrypted with missing-key@example.com, not signed | |
| 1190 $inputFilename = $this->getDataFilename( | |
| 1191 'testDecryptFileKeyNotFoundException.asc' | |
| 1192 ); | |
| 1193 | |
| 1194 $outputFilename = $this->getTempFilename( | |
| 1195 'testDecryptVerifyFileKeyNotFoundException.plain' | |
| 1196 ); | |
| 1197 | |
| 1198 $this->gpg->decryptAndVerifyFile($inputFilename, $outputFilename); | |
| 1199 } | |
| 1200 | |
| 1201 // }}} | |
| 1202 // {{{ testDecryptVerifyFileDual() | |
| 1203 | |
| 1204 /** | |
| 1205 * @group file | |
| 1206 */ | |
| 1207 public function testDecryptVerifyFileDual() | |
| 1208 { | |
| 1209 // {{{ signature | |
| 1210 $signature = new Crypt_GPG_Signature(); | |
| 1211 $signature->setId('7TYk0hpio90QZHHHb4UtgCWAEq4'); | |
| 1212 $signature->setKeyFingerprint( | |
| 1213 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1214 | |
| 1215 $signature->setKeyId('C097D9EC94C06363'); | |
| 1216 $signature->setCreationDate(1258220362); | |
| 1217 $signature->setExpirationDate(0); | |
| 1218 $signature->setValid(true); | |
| 1219 | |
| 1220 $userId = new Crypt_GPG_UserId(); | |
| 1221 $userId->setName('First Keypair Test Key'); | |
| 1222 $userId->setComment('do not encrypt important data with this key'); | |
| 1223 $userId->setEmail('first-keypair@example.com'); | |
| 1224 $signature->setUserId($userId); | |
| 1225 // }}} | |
| 1226 | |
| 1227 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1228 $expectedResults = array( | |
| 1229 'data' => null, | |
| 1230 'signatures' => array($signature) | |
| 1231 ); | |
| 1232 | |
| 1233 $inputFilename = $this->getDataFilename( | |
| 1234 'testDecryptVerifyFileDual.asc' | |
| 1235 ); | |
| 1236 $outputFilename = $this->getTempFilename( | |
| 1237 'testDecryptVerifyFileDual.plain' | |
| 1238 ); | |
| 1239 | |
| 1240 // decrypt with first key | |
| 1241 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1242 $results = $this->gpg->decryptAndVerifyFile( | |
| 1243 $inputFilename, | |
| 1244 $outputFilename | |
| 1245 ); | |
| 1246 $this->gpg->clearDecryptKeys(); | |
| 1247 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1248 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1249 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1250 | |
| 1251 // decrypt with second key | |
| 1252 $this->gpg->addDecryptKey('second-keypair@example.com', 'test2'); | |
| 1253 $results = $this->gpg->decryptAndVerifyFile( | |
| 1254 $inputFilename, | |
| 1255 $outputFilename | |
| 1256 ); | |
| 1257 $this->gpg->clearDecryptKeys(); | |
| 1258 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1259 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1260 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1261 } | |
| 1262 | |
| 1263 // }}} | |
| 1264 // {{{ testDecryptVerifyFileDualSignatories() | |
| 1265 | |
| 1266 /** | |
| 1267 * @group file | |
| 1268 */ | |
| 1269 public function testDecryptVerifyFileDualSignatories() | |
| 1270 { | |
| 1271 // {{{ signature1 | |
| 1272 $signature1 = new Crypt_GPG_Signature(); | |
| 1273 $signature1->setId('MF8xqL325bs7KiokMHTnHirF4go'); | |
| 1274 $signature1->setKeyFingerprint( | |
| 1275 '880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
| 1276 | |
| 1277 $signature1->setKeyId('03CC890AFA1DAD4B'); | |
| 1278 $signature1->setCreationDate(1258220269); | |
| 1279 $signature1->setExpirationDate(0); | |
| 1280 $signature1->setValid(true); | |
| 1281 | |
| 1282 $userId1 = new Crypt_GPG_UserId(); | |
| 1283 $userId1->setName('Second Keypair Test Key'); | |
| 1284 $userId1->setComment('do not encrypt important data with this key'); | |
| 1285 $userId1->setEmail('second-keypair@example.com'); | |
| 1286 $signature1->setUserId($userId1); | |
| 1287 // }}} | |
| 1288 // {{{ signature2 | |
| 1289 $signature2 = new Crypt_GPG_Signature(); | |
| 1290 $signature2->setId('d0q7jibZpJSLpGAhNWhpSkZZeUg'); | |
| 1291 $signature2->setKeyFingerprint( | |
| 1292 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1293 | |
| 1294 $signature2->setKeyId('C097D9EC94C06363'); | |
| 1295 $signature2->setCreationDate(1258220269); | |
| 1296 $signature2->setExpirationDate(0); | |
| 1297 $signature2->setValid(true); | |
| 1298 | |
| 1299 $userId2 = new Crypt_GPG_UserId(); | |
| 1300 $userId2->setName('First Keypair Test Key'); | |
| 1301 $userId2->setComment('do not encrypt important data with this key'); | |
| 1302 $userId2->setEmail('first-keypair@example.com'); | |
| 1303 $signature2->setUserId($userId2); | |
| 1304 // }}} | |
| 1305 | |
| 1306 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1307 $expectedResults = array( | |
| 1308 'data' => null, | |
| 1309 'signatures' => array($signature1, $signature2) | |
| 1310 ); | |
| 1311 | |
| 1312 $inputFilename = $this->getDataFilename( | |
| 1313 'testDecryptVerifyFileDualSignatories.asc' | |
| 1314 ); | |
| 1315 $outputFilename = $this->getTempFilename( | |
| 1316 'testDecryptVerifyFileDualSignatories.plain' | |
| 1317 ); | |
| 1318 | |
| 1319 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1320 $results = $this->gpg->decryptAndVerifyFile( | |
| 1321 $inputFilename, | |
| 1322 $outputFilename | |
| 1323 ); | |
| 1324 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1325 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1326 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1327 } | |
| 1328 | |
| 1329 // }}} | |
| 1330 // {{{ testDecryptVerifyFileDualOnePassphrase() | |
| 1331 | |
| 1332 /** | |
| 1333 * @group file | |
| 1334 */ | |
| 1335 public function testDecryptVerifyFileDualOnePassphrase() | |
| 1336 { | |
| 1337 // {{{ signature | |
| 1338 $signature = new Crypt_GPG_Signature(); | |
| 1339 $signature->setId('kgyLjfFigxOrliyc8XlS6NaLJuw'); | |
| 1340 $signature->setKeyFingerprint( | |
| 1341 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1342 | |
| 1343 $signature->setKeyId('C097D9EC94C06363'); | |
| 1344 $signature->setCreationDate(1258220334); | |
| 1345 $signature->setExpirationDate(0); | |
| 1346 $signature->setValid(true); | |
| 1347 | |
| 1348 $userId = new Crypt_GPG_UserId(); | |
| 1349 $userId->setName('First Keypair Test Key'); | |
| 1350 $userId->setComment('do not encrypt important data with this key'); | |
| 1351 $userId->setEmail('first-keypair@example.com'); | |
| 1352 $signature->setUserId($userId); | |
| 1353 // }}} | |
| 1354 | |
| 1355 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1356 $expectedResults = array( | |
| 1357 'data' => null, | |
| 1358 'signatures' => array($signature) | |
| 1359 ); | |
| 1360 | |
| 1361 $inputFilename = $this->getDataFilename( | |
| 1362 'testDecryptVerifyFileDualOnePassphrase.asc' | |
| 1363 ); | |
| 1364 $outputFilename = $this->getTempFilename( | |
| 1365 'testDecryptVerifyFileDualOnePassphrase.plain' | |
| 1366 ); | |
| 1367 | |
| 1368 // decrypt with no-passphrase | |
| 1369 $results = $this->gpg->decryptAndVerifyFile( | |
| 1370 $inputFilename, | |
| 1371 $outputFilename | |
| 1372 ); | |
| 1373 $this->gpg->clearDecryptKeys(); | |
| 1374 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1375 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1376 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1377 | |
| 1378 // decrypt with second key | |
| 1379 $this->gpg->addDecryptKey('first-keypair@example.com', 'test1'); | |
| 1380 $results = $this->gpg->decryptAndVerifyFile( | |
| 1381 $inputFilename, | |
| 1382 $outputFilename | |
| 1383 ); | |
| 1384 $this->gpg->clearDecryptKeys(); | |
| 1385 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1386 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1387 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1388 } | |
| 1389 | |
| 1390 // }}} | |
| 1391 // {{{ testDecryptVerifyFileNoDataException() | |
| 1392 | |
| 1393 /** | |
| 1394 * @expectedException Crypt_GPG_NoDataException | |
| 1395 * | |
| 1396 * @group file | |
| 1397 */ | |
| 1398 public function testDecryptVerifyFileNoDataException() | |
| 1399 { | |
| 1400 $filename = $this->getDataFilename('testFileEmpty.plain'); | |
| 1401 $this->gpg->decryptAndVerifyFile($filename); | |
| 1402 } | |
| 1403 | |
| 1404 // }}} | |
| 1405 // {{{ testDecryptVerifyFileSignedOnly() | |
| 1406 | |
| 1407 /** | |
| 1408 * @group file | |
| 1409 */ | |
| 1410 public function testDecryptVerifyFileSignedOnly() | |
| 1411 { | |
| 1412 // {{{ signature | |
| 1413 $signature = new Crypt_GPG_Signature(); | |
| 1414 $signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU'); | |
| 1415 $signature->setKeyFingerprint( | |
| 1416 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 1417 | |
| 1418 $signature->setKeyId('C097D9EC94C06363'); | |
| 1419 $signature->setCreationDate(1221960707); | |
| 1420 $signature->setExpirationDate(0); | |
| 1421 $signature->setValid(true); | |
| 1422 | |
| 1423 $userId = new Crypt_GPG_UserId(); | |
| 1424 $userId->setName('First Keypair Test Key'); | |
| 1425 $userId->setComment('do not encrypt important data with this key'); | |
| 1426 $userId->setEmail('first-keypair@example.com'); | |
| 1427 $signature->setUserId($userId); | |
| 1428 // }}} | |
| 1429 | |
| 1430 $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1'; | |
| 1431 $expectedResults = array( | |
| 1432 'data' => null, | |
| 1433 'signatures' => array($signature) | |
| 1434 ); | |
| 1435 | |
| 1436 $inputFilename = $this->getDataFilename( | |
| 1437 'testVerifyFileNormalSignedData.asc' | |
| 1438 ); | |
| 1439 | |
| 1440 $outputFilename = $this->getTempFilename( | |
| 1441 'testDecryptVerifyFileSignedData.plain' | |
| 1442 ); | |
| 1443 | |
| 1444 $results = $this->gpg->decryptAndVerifyFile( | |
| 1445 $inputFilename, | |
| 1446 $outputFilename | |
| 1447 ); | |
| 1448 | |
| 1449 $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results); | |
| 1450 | |
| 1451 $md5Sum = $this->getMd5Sum($outputFilename); | |
| 1452 $this->assertEquals($expectedMd5Sum, $md5Sum); | |
| 1453 } | |
| 1454 | |
| 1455 // }}} | |
| 1456 } | |
| 1457 | |
| 1458 ?> |
