openpgp-php/tests/phpseclib_suite.php

97 lines
3.1 KiB
PHP
Raw Normal View History

2013-01-21 00:00:49 +00:00
<?php
/* The tests which require phpseclib */
require_once dirname(__FILE__).'/../lib/openpgp.php';
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
2013-01-26 16:08:18 +00:00
require_once dirname(__FILE__).'/../lib/openpgp_crypt_aes_tripledes.php';
2013-01-21 00:00:49 +00:00
class MessageVerification extends PHPUnit_Framework_TestCase {
public function oneMessageRSA($pkey, $path) {
$pkeyM = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $pkey));
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
$verify = new OpenPGP_Crypt_RSA($pkeyM);
$this->assertSame($verify->verify($m), $m->signatures());
2013-01-21 00:00:49 +00:00
}
public function testUncompressedOpsRSA() {
$this->oneMessageRSA('pubring.gpg', 'uncompressed-ops-rsa.gpg');
}
public function testCompressedSig() {
$this->oneMessageRSA('pubring.gpg', 'compressedsig.gpg');
}
public function testCompressedSigZLIB() {
$this->oneMessageRSA('pubring.gpg', 'compressedsig-zlib.gpg');
}
public function testCompressedSigBzip2() {
$this->oneMessageRSA('pubring.gpg', 'compressedsig-bzip2.gpg');
}
2013-01-21 03:15:49 +00:00
public function testSigningMessages() {
$wkey = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
$sign = new OpenPGP_Crypt_RSA($wkey);
$m = $sign->sign($data)->to_bytes();
$reparsedM = OpenPGP_Message::parse($m);
$this->assertSame($sign->verify($reparsedM), $reparsedM->signatures());
}
2013-01-21 00:00:49 +00:00
/*
public function testUncompressedOpsDSA() {
$this->oneMessageDSA('pubring.gpg', 'uncompressed-ops-dsa.gpg');
}
public function testUncompressedOpsDSAsha384() {
$this->oneMessageDSA('pubring.gpg', 'uncompressed-ops-dsa-sha384.gpg');
}
*/
}
class KeyVerification extends PHPUnit_Framework_TestCase {
public function oneKeyRSA($path) {
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
$verify = new OpenPGP_Crypt_RSA($m);
$this->assertSame($verify->verify($m), $m->signatures());
}
public function testHelloKey() {
$this->oneKeyRSA("helloKey.gpg");
}
}
2013-01-21 23:18:13 +00:00
class Decryption extends PHPUnit_Framework_TestCase {
public function oneSymmetric($pass, $cnt, $path) {
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
2013-01-26 16:08:18 +00:00
$m2 = OpenPGP_Crypt_AES_TripleDES::decryptSymmetric($pass, $m);
2013-01-21 23:18:13 +00:00
while($m2[0] instanceof OpenPGP_CompressedDataPacket) $m2 = $m2[0]->data;
foreach($m2 as $p) {
if($p instanceof OpenPGP_LiteralDataPacket) {
$this->assertEquals($p->data, $cnt);
}
}
}
public function testDecryptAES() {
$this->oneSymmetric("hello", "PGP\n", "symmetric-aes.gpg");
}
2013-01-26 16:08:18 +00:00
public function testDecrypt3DES() {
$this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg");
}
2013-01-21 23:18:13 +00:00
/* TODO
public function testDecryptSessionKey() {
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
}
2013-01-26 16:17:11 +00:00
*/
2013-01-21 23:18:13 +00:00
public function testDecryptNoMDC() {
$this->oneSymmetric("hello", "PGP\n", "symmetric-no-mdc.gpg");
}
}