This commit is contained in:
Thilo Raufeisen 2006-05-18 19:32:32 +00:00
parent abaa52b97a
commit dc666cc840
12 changed files with 487 additions and 0 deletions

View file

@ -0,0 +1,33 @@
--TEST--n
import a new key into the keyring
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
@unlink (dirname(__FILE__)."/pubring.gpg");
@unlink (dirname(__FILE__)."/secring.gpg");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> import($testkey);
var_dump($ret);
?>
--EXPECT--
array(9) {
["imported"]=>
int(1)
["unchanged"]=>
int(0)
["newuserids"]=>
int(0)
["newsubkeys"]=>
int(0)
["secretimported"]=>
int(1)
["secretunchanged"]=>
int(0)
["newsignatures"]=>
int(0)
["skippedkeys"]=>
int(0)
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
}

View file

@ -0,0 +1,20 @@
--TEST--
encrypt and decrypt a text
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> addencryptkey($fingerprint);
$enc = $gpg -> encrypt($plaintext);
$gpg = NULL;
$gpg = new gnupg();
$gpg -> adddecryptkey($fingerprint, $passphrase);
$ret = $gpg -> decrypt ($enc);
var_dump($ret);
?>
--EXPECTF--
string(7) "foo bar"

View file

@ -0,0 +1,38 @@
--TEST--
encryptsign and decryptverify a text
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> addencryptkey($fingerprint);
$gpg -> addsignkey($fingerprint, $passphrase);
$enc = $gpg -> encryptsign($plaintext);
$gpg = NULL;
$plaintext = false;
$gpg = new gnupg();
$gpg -> adddecryptkey($fingerprint, $passphrase);
$ret = $gpg -> decryptverify ($enc, $plaintext);
var_dump($ret);
var_dump($plaintext);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(7) "foo bar"

View file

@ -0,0 +1,36 @@
--TEST--
export a key
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> export($fingerprint);
var_dump($ret);
?>
--EXPECTF--
string(1336) "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.3 (GNU/Linux)
mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3
afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z
/samjTHLR+VKZ031B5/8p5Y49yvkkEyBkF1G85yeIXK0WZorKBPncRKuUwCgxOi/
IEa+ZuqHlmlDF2LTRIBOfrkEAK+WLRMWUD0bqj1TYwnxwPWiuns32/ZXLWuPfb5o
crNt7x5LSe7wJhjyIiFhiU0qR33X/FrT2umzOxlRYfINXT9DUHDocxxbED6fxAHw
X2IDd5tWXgCkSBHn2yAneNY6ycPdS3RvqJGlYFg7cOc0kz4urjqRt9fIagzpZQtL
fXHfBACl3EWgvLhVBo5ExZbrtlOA2q0x9UGhhNaSkeBWBr2qDeZErQjMTO0+viaN
/SX0zxeWtM3z06rkUHd1DKORDRM5R7shBTv9/Quojn0gbYbOem+e1mlCe27TRxcP
yeIKk00PqbVuff9QlK9GqKEWGzsEXCmxZ160Dul3CGlf/vQZHbQkdGVzdGtleSAo
dGVzdGtleSkgPHRlc3RAZXhhbXBsZS5uZXQ+iF4EExECAB4FAkNQAKwCGwMGCwkI
BwMCAxUCAwMWAgECHgECF4AACgkQLpbxQbPdKy58pwCcDz9qEBEVt1gcKCwNay0f
m4vLqCkAn1P0KV1giECUVXBuZ5YUndDB1QqtuQENBENQAK0QBACNXzJQG4NHUJqL
PImezbl+ii+93MjMo8LpSlv9Np5ruWIKtxuqmVEe4k+r1DDmSl8hppifpRtx2hef
bDTl8Tdf5MNGvf5JE3AHYUehZ+ldjgYCOZ53fJDgKV65ZidQSGGXsRcyE7SHgMQ6
rTL92PA2IQmkcf9xkg6xM2h55UusMwADBQP9EGQ0BAdWRUtA21/cR6F+t97KZnVS
et225UYv8azv8p8cK4R1lrZXChFadK9Kt+/My4HAx7J7zd1IPuKQ0QniuvuLT3Mw
z19B7FGXaJenwTw0P1ihtmSPq9GAOkOA4ZPhHLl9OFwIeAZzjfshRfvm0haO3vwl
xdjhwxyJ/a/JEF2ISQQYEQIACQUCQ1AArQIbDAAKCRAulvFBs90rLrBkAJ9tScp6
drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI=
=twR+
-----END PGP PUBLIC KEY BLOCK-----
"

View file

@ -0,0 +1,97 @@
--TEST--n
get keyinfo
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> keyinfo($fingerprint);
var_dump($ret);
?>
--EXPECT--
array(1) {
[0]=>
array(8) {
["disabled"]=>
bool(false)
["expired"]=>
bool(false)
["revoked"]=>
bool(false)
["is_secret"]=>
bool(false)
["can_sign"]=>
bool(true)
["can_encrypt"]=>
bool(true)
["uids"]=>
array(1) {
[0]=>
array(6) {
["name"]=>
string(7) "testkey"
["comment"]=>
string(7) "testkey"
["email"]=>
string(16) "test@example.net"
["uid"]=>
string(36) "testkey (testkey) <test@example.net>"
["revoked"]=>
bool(false)
["invalid"]=>
bool(false)
}
}
["subkeys"]=>
array(2) {
[0]=>
array(11) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["keyid"]=>
string(16) "2E96F141B3DD2B2E"
["timestamp"]=>
int(1129316524)
["expires"]=>
int(0)
["is_secret"]=>
bool(false)
["invalid"]=>
bool(false)
["can_encrypt"]=>
bool(false)
["can_sign"]=>
bool(true)
["disabled"]=>
bool(false)
["expired"]=>
bool(false)
["revoked"]=>
bool(false)
}
[1]=>
array(10) {
["keyid"]=>
string(16) "BFE8D07DDACDEAC8"
["timestamp"]=>
int(1129316525)
["expires"]=>
int(0)
["is_secret"]=>
bool(false)
["invalid"]=>
bool(false)
["can_encrypt"]=>
bool(true)
["can_sign"]=>
bool(false)
["disabled"]=>
bool(false)
["expired"]=>
bool(false)
["revoked"]=>
bool(false)
}
}
}
}

View file

@ -0,0 +1,35 @@
--TEST--n
list signatures
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> listsignatures($fingerprint);
var_dump($ret);
?>
--EXPECT--
array(1) {
["testkey (testkey) <test@example.net>"]=>
array(1) {
["2E96F141B3DD2B2E"]=>
array(8) {
["uid"]=>
string(36) "testkey (testkey) <test@example.net>"
["name"]=>
string(7) "testkey"
["email"]=>
string(16) "test@example.net"
["comment"]=>
string(7) "testkey"
["expires"]=>
int(0)
["revoked"]=>
bool(false)
["expired"]=>
bool(false)
["invalid"]=>
bool(false)
}
}
}

View file

@ -0,0 +1,38 @@
--TEST--n
sign a text with sigmode SIG_MODE_CLEAR
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_CLEAR);
$gpg -> addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext);
$gpg = NULL;
$gpg = new gnupg();
$tmp = false;
$ret = $gpg -> verify($ret, false, $tmp);
var_dump($ret);
var_dump($tmp);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(8) "foo bar
"

View file

@ -0,0 +1,38 @@
--TEST--n
sign a text with mode SIG_MODE_DETACH and without armored output
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> setarmor(0);
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH);
$gpg -> addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext);
$gpg = NULL;
$gpg = new gnupg();
$tmp = false;
$ret = $gpg -> verify($plaintext, $ret);
var_dump($ret);
var_dump($plaintext);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(7) "foo bar"

View file

@ -0,0 +1,37 @@
--TEST--n
sign a text with mode SIG_MODE_DETACH
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH);
$gpg -> addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext);
$gpg = NULL;
$gpg = new gnupg();
$tmp = false;
$ret = $gpg -> verify($plaintext, $ret);
var_dump($ret);
var_dump($plaintext);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(7) "foo bar"

View file

@ -0,0 +1,38 @@
--TEST--n
sign a text with mode SIG_MODE_NORMAL
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL);
$gpg -> addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext);
$gpg = NULL;
$gpg = new gnupg();
$tmp = false;
$plaintext = false;
$ret = $gpg -> verify($ret, false, $plaintext);
var_dump($ret);
var_dump($plaintext);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(7) "foo bar"

View file

@ -0,0 +1,39 @@
--TEST--n
sign a text with mode SIG_MODE_NORMAL and without armored output
--FILE--
<?php
require_once(dirname(__FILE__)."/vars.inc");
$gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING);
$gpg -> setarmor(0);
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL);
$gpg -> addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext);
$gpg = NULL;
$gpg = new gnupg();
//$ret = $gpg -> verify($plaintext, $ret);
$plaintext = false;
$ret = $gpg -> verify($ret, false, $plaintext);
var_dump($ret);
var_dump($plaintext);
?>
--EXPECTF--
array(1) {
[0]=>
array(5) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
["validity"]=>
int(0)
["timestamp"]=>
int(%d)
["status"]=>
int(0)
["summary"]=>
int(0)
}
}
string(7) "foo bar"

38
tests/vars.inc Normal file
View file

@ -0,0 +1,38 @@
<?php
putenv("GNUPGHOME=".dirname(__FILE__));
$fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E";
$passphrase = "blabla";
$plaintext = "foo bar";
$testkey =<<<EOF
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1.4.3 (GNU/Linux)
lQHhBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3
afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH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