Message signature verification tests

This commit is contained in:
Stephen Paul Weber 2013-01-20 19:00:49 -05:00
parent 7d44211fc8
commit 22585344c0
7 changed files with 59 additions and 13 deletions

View File

@ -182,7 +182,7 @@ class OpenPGP_Message implements IteratorAggregate, ArrayAccess {
$i++;
}
if($p instanceof OpenPGP_LiteralDataPacket) $data_packet = $p;
if($signature_packet && $data_packet) break;
if(isset($signature_packet) && isset($data_packet)) break;
}
return array($signature_packet, $data_packet);

View File

@ -56,7 +56,7 @@ class OpenPGP_Crypt_RSA {
$key = $this->public_key($signature_packet->issuer());
if(!$key || $signature_packet->key_algorithm_name() != 'RSA') return NULL;
$key->setHash(strtolower($signature_packet->hash_algorithm_name()));
return $packet->verify(array('RSA' => array($signature_packet->hash_algorithm_name() => array($key, 'verify'))));
return $packet->verify(array('RSA' => array($signature_packet->hash_algorithm_name() => function($m, $s) use($key) {return $key->verify($m, $s[0]);})));
} else {
list($signature_packet, $data_packet) = $this->message->signature_and_data($index);
if(!$this->message || $signature_packet->key_algorithm_name() != 'RSA') return NULL;
@ -65,7 +65,7 @@ class OpenPGP_Crypt_RSA {
$packet = $packet->public_key($signature_packet->issuer());
}
$packet->setHash(strtolower($signature_packet->hash_algorithm_name()));
return $this->message->verify(array('RSA' => array($signature_packet->hash_algorithm_name() => array($packet, 'verify'))));
return $this->message->verify(array('RSA' => array($signature_packet->hash_algorithm_name() => function($m, $s) use($packet) {return $packet->verify($m, $s[0]);})));
}
}
@ -141,11 +141,12 @@ class OpenPGP_Crypt_RSA {
static function crypt_rsa_key($mod, $exp, $hash='SHA256') {
$rsa = new Crypt_RSA();
$rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->setHash(strtolower($hash));
$rsa->modulus = new Math_BigInteger($mod, 256);
$rsa->k = strlen($rsa->modulus->toBytes());
$rsa->exponent = new Math_BigInteger($exp, 256);
$rsa->setPublicKey();
return $rsa;
}

View File

@ -1,11 +1,15 @@
<phpunit>
<testsuites>
<testsuite name="Serialization">
<file>tests/suite.php</file>
</testsuite>
<testsuites>
<testsuite name="Serialization">
<file>tests/suite.php</file>
</testsuite>
<testsuite name="Fingerprint">
<file>tests/suite.php</file>
</testsuite>
</testsuites>
<testsuite name="Fingerprint">
<file>tests/suite.php</file>
</testsuite>
<testsuite name="MessageVerification">
<file>tests/phpseclib_suite.php</file>
</testsuite>
</testsuites>
</phpunit>

Binary file not shown.

Binary file not shown.

41
tests/phpseclib_suite.php Normal file
View File

@ -0,0 +1,41 @@
<?php
/* The tests which require phpseclib */
require_once dirname(__FILE__).'/../lib/openpgp.php';
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
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), TRUE);
}
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');
}
/*
public function testUncompressedOpsDSA() {
$this->oneMessageDSA('pubring.gpg', 'uncompressed-ops-dsa.gpg');
}
public function testUncompressedOpsDSAsha384() {
$this->oneMessageDSA('pubring.gpg', 'uncompressed-ops-dsa-sha384.gpg');
}
*/
}

View File

@ -1,6 +1,6 @@
<?php
require dirname(__FILE__).'/../lib/openpgp.php';
require_once dirname(__FILE__).'/../lib/openpgp.php';
class Serialization extends PHPUnit_Framework_TestCase {
public function oneSerialization($path) {