diff --git a/lib/openpgp.php b/lib/openpgp.php index 04a1009..d529ef2 100644 --- a/lib/openpgp.php +++ b/lib/openpgp.php @@ -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); diff --git a/lib/openpgp_crypt_rsa.php b/lib/openpgp_crypt_rsa.php index 8cf4495..1e9456b 100644 --- a/lib/openpgp_crypt_rsa.php +++ b/lib/openpgp_crypt_rsa.php @@ -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; } diff --git a/phpunit.xml b/phpunit.xml index 00cfad3..8049722 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,11 +1,15 @@ - - - tests/suite.php - + + + tests/suite.php + - - tests/suite.php - - + + tests/suite.php + + + + tests/phpseclib_suite.php + + diff --git a/tests/data/pubring.gpg b/tests/data/pubring.gpg index a1519ee..56e0599 100644 Binary files a/tests/data/pubring.gpg and b/tests/data/pubring.gpg differ diff --git a/tests/data/secring.gpg b/tests/data/secring.gpg index 1359875..9e43912 100644 Binary files a/tests/data/secring.gpg and b/tests/data/secring.gpg differ diff --git a/tests/phpseclib_suite.php b/tests/phpseclib_suite.php new file mode 100644 index 0000000..4f23a84 --- /dev/null +++ b/tests/phpseclib_suite.php @@ -0,0 +1,41 @@ +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'); + } +*/ +} diff --git a/tests/suite.php b/tests/suite.php index 1fabf72..b417098 100644 --- a/tests/suite.php +++ b/tests/suite.php @@ -1,6 +1,6 @@