Merge branch 'next'

This commit is contained in:
Jakub Zelenka 2018-05-17 20:24:29 +01:00
commit 337ccfb4a0
30 changed files with 252 additions and 114 deletions

1
.gitignore vendored
View file

@ -15,6 +15,7 @@ config.nice
config.status config.status
config.sub config.sub
configure configure
configure.ac
configure.in configure.in
extras extras
include include

7
TODO.md Normal file
View file

@ -0,0 +1,7 @@
# TODO list
- Introduce gnupg_geterrorinfo with more info about the error
- including error message from gpgme
- Allow setting engine info on object construction
- Add __construct / res init with gpgme_ctx_set_engine_info
- Return decrypt result if extra param supplied

View file

@ -3,7 +3,7 @@ PHP GNUPG UPGRADING NOTES
This document lists backward incompatible change in the extension This document lists backward incompatible change in the extension
1.4.0 1.4.0
- gnupg_decryptverify $plaintext reference cannot be longer passed in - gnupg_decryptverify $plaintext reference can no longer be passed in
call_user_func_array which is conformant to user space code. call_user_func_array which is conformant to user space code.
See https://github.com/php-gnupg/php-gnupg/issues/4 for more details. See https://github.com/php-gnupg/php-gnupg/issues/4 for more details.

30
gnupg.c
View file

@ -82,8 +82,8 @@ PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg);
} while (0) } while (0)
/* }}} */ /* }}} */
/* {{{ gnupg_free_encryptkeys */ /* {{{ php_gnupg_free_encryptkeys */
static void gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) static void php_gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
{ {
if (PHPC_THIS) { if (PHPC_THIS) {
int idx; int idx;
@ -100,8 +100,8 @@ static void gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
} }
/* }}} */ /* }}} */
/* {{{ gnupg_free_resource_ptr */ /* {{{ php_gnupg_free_resource_ptr */
static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) static void php_gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
{ {
if (PHPC_THIS) { if (PHPC_THIS) {
if (PHPC_THIS->ctx) { if (PHPC_THIS->ctx) {
@ -111,7 +111,7 @@ static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
PHPC_THIS->ctx = NULL; PHPC_THIS->ctx = NULL;
} }
/* basic cleanup */ /* basic cleanup */
gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); php_gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC);
zend_hash_destroy(PHPC_THIS->signkeys); zend_hash_destroy(PHPC_THIS->signkeys);
FREE_HASHTABLE(PHPC_THIS->signkeys); FREE_HASHTABLE(PHPC_THIS->signkeys);
zend_hash_destroy(PHPC_THIS->decryptkeys); zend_hash_destroy(PHPC_THIS->decryptkeys);
@ -120,17 +120,17 @@ static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
} }
/* }}} */ /* }}} */
/* {{{ gnupg_res_dtor */ /* {{{ php_gnupg_res_dtor */
static void gnupg_res_dtor(phpc_res_entry_t *rsrc TSRMLS_DC) /* {{{ */ static void php_gnupg_res_dtor(phpc_res_entry_t *rsrc TSRMLS_DC) /* {{{ */
{ {
PHPC_THIS_DECLARE(gnupg) = rsrc->ptr; PHPC_THIS_DECLARE(gnupg) = rsrc->ptr;
gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); php_gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC);
efree(PHPC_THIS); efree(PHPC_THIS);
} }
/* }}} */ /* }}} */
/* {{{ gnupg_res_init */ /* {{{ php_gnupg_res_init */
static void gnupg_res_init(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) static void php_gnupg_res_init(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
{ {
/* init the gpgme-lib and set the default values */ /* init the gpgme-lib and set the default values */
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
@ -161,7 +161,7 @@ PHPC_OBJ_HANDLER_FREE(gnupg)
{ {
PHPC_OBJ_HANDLER_FREE_INIT(gnupg); PHPC_OBJ_HANDLER_FREE_INIT(gnupg);
gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); php_gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC);
PHPC_OBJ_HANDLER_FREE_DESTROY(); PHPC_OBJ_HANDLER_FREE_DESTROY();
} }
@ -171,7 +171,7 @@ PHPC_OBJ_HANDLER_CREATE_EX(gnupg)
{ {
PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg); PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg);
gnupg_res_init(PHPC_THIS TSRMLS_CC); php_gnupg_res_init(PHPC_THIS TSRMLS_CC);
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg); PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg);
} }
@ -450,7 +450,7 @@ PHP_MINIT_FUNCTION(gnupg)
/* register resource */ /* register resource */
le_gnupg = zend_register_list_destructors_ex( le_gnupg = zend_register_list_destructors_ex(
gnupg_res_dtor, NULL, "ctx", module_number); php_gnupg_res_dtor, NULL, "ctx", module_number);
if (SUCCESS != gnupg_keylistiterator_init()) { if (SUCCESS != gnupg_keylistiterator_init()) {
return FAILURE; return FAILURE;
@ -648,7 +648,7 @@ PHP_FUNCTION(gnupg_init)
{ {
PHPC_THIS_DECLARE(gnupg); PHPC_THIS_DECLARE(gnupg);
PHPC_THIS = emalloc(sizeof(PHPC_OBJ_STRUCT_NAME(gnupg))); PHPC_THIS = emalloc(sizeof(PHPC_OBJ_STRUCT_NAME(gnupg)));
gnupg_res_init(PHPC_THIS TSRMLS_CC); php_gnupg_res_init(PHPC_THIS TSRMLS_CC);
PHPC_RES_RETURN(PHPC_RES_REGISTER(PHPC_THIS, le_gnupg)); PHPC_RES_RETURN(PHPC_RES_REGISTER(PHPC_THIS, le_gnupg));
} }
/* }}} */ /* }}} */
@ -1068,7 +1068,7 @@ PHP_FUNCTION(gnupg_clearencryptkeys)
} }
GNUPG_RES_FETCH(); GNUPG_RES_FETCH();
} }
gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); php_gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC);
RETURN_TRUE; RETURN_TRUE;
} }

View file

@ -1,11 +1,11 @@
--TEST--n --TEST--
delete a key from the keyring delete a key from the keyring
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -14,3 +14,8 @@ var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--
bool(true) bool(true)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,14 +4,13 @@ encrypt and decrypt a text
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg->addencryptkey($fingerprint); $gpg->addencryptkey($fingerprint);
$enc = $gpg->encrypt($plaintext); $enc = $gpg->encrypt($plaintext);
$gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->adddecryptkey($fingerprint, $passphrase); $gpg->adddecryptkey($fingerprint, $passphrase);
@ -21,3 +20,8 @@ var_dump($ret);
?> ?>
--EXPECTF-- --EXPECTF--
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ encryptsign and decryptverify a text
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -13,9 +13,7 @@ $gpg->addencryptkey($fingerprint);
$gpg->addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$enc = $gpg->encryptsign($plaintext); $enc = $gpg->encryptsign($plaintext);
$gpg = NULL;
$plaintext = false; $plaintext = false;
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->adddecryptkey($fingerprint, $passphrase); $gpg->adddecryptkey($fingerprint, $passphrase);
$ret = $gpg->decryptverify ($enc, $plaintext); $ret = $gpg->decryptverify ($enc, $plaintext);
@ -40,3 +38,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ export a key
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -14,7 +14,6 @@ var_dump($ret);
?> ?>
--EXPECTF-- --EXPECTF--
string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3
afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z
@ -38,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI=
=twR+ =twR+
-----END PGP PUBLIC KEY BLOCK----- -----END PGP PUBLIC KEY BLOCK-----
" "
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,12 @@
--TEST--n --TEST--
import a new key into the keyring import a new key into the keyring
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_clear_files(); gnupgt::delete_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg->import($testkey); $ret = $gpg->import($testkey);
@ -32,3 +33,8 @@ array(9) {
["fingerprint"]=> ["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ get keyinfo
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -101,3 +101,8 @@ array(1) {
} }
} }
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n --TEST--
list signatures list signatures
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -37,3 +37,8 @@ array(1) {
} }
} }
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ sign a text with sigmode SIG_MODE_CLEAR
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
} }
string(8) "foo bar string(8) "foo bar
" "
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ sign a text with mode SIG_MODE_DETACH
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -39,3 +39,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n --TEST--
sign a text with mode SIG_MODE_DETACH and without armored output sign a text with mode SIG_MODE_DETACH and without armored output
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n --TEST--
sign a text with mode SIG_MODE_NORMAL sign a text with mode SIG_MODE_NORMAL
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n --TEST--
sign a text with mode SIG_MODE_NORMAL and without armored output sign a text with mode SIG_MODE_NORMAL and without armored output
--SKIPIF-- --SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
@ -14,8 +14,6 @@ $gpg->setsignmode(gnupg::SIG_MODE_NORMAL);
$gpg->addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg->sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
//$ret = $gpg->verify($plaintext, $ret); //$ret = $gpg->verify($plaintext, $ret);
$plaintext = false; $plaintext = false;
@ -41,3 +39,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--
import a new key into the keyring import a new key into the keyring
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_clear_files(); gnupgt::delete_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -31,3 +33,8 @@ array(9) {
["fingerprint"]=> ["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
delete a key from the keyring delete a key from the keyring
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -12,3 +14,8 @@ var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--
bool(true) bool(true)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST-- --TEST--
encrypt and decrypt a text encrypt and decrypt a text
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -20,3 +22,8 @@ var_dump($ret);
?> ?>
--EXPECTF-- --EXPECTF--
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST-- --TEST--
encryptsign and decryptverify a text encryptsign and decryptverify a text
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST-- --TEST--
export a key export a key
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -12,7 +14,6 @@ var_dump($ret);
?> ?>
--EXPECTF-- --EXPECTF--
string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3
afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z
@ -36,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI=
=twR+ =twR+
-----END PGP PUBLIC KEY BLOCK----- -----END PGP PUBLIC KEY BLOCK-----
" "
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
get keyinfo get keyinfo
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -99,3 +101,8 @@ array(1) {
} }
} }
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
list signatures list signatures
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -35,3 +37,8 @@ array(1) {
} }
} }
} }
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
sign a text with sigmode SIG_MODE_CLEAR sign a text with sigmode SIG_MODE_CLEAR
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -11,8 +13,6 @@ gnupg_setsignmode($gpg, GNUPG_SIG_MODE_CLEAR);
gnupg_addsignkey($gpg, $fingerprint, $passphrase); gnupg_addsignkey($gpg, $fingerprint, $passphrase);
$ret = gnupg_sign($gpg, $plaintext); $ret = gnupg_sign($gpg, $plaintext);
$gpg = NULL;
$gpg = gnupg_init(); $gpg = gnupg_init();
$tmp = false; $tmp = false;
$ret = gnupg_verify($gpg, $ret, false, $tmp); $ret = gnupg_verify($gpg, $ret, false, $tmp);
@ -38,3 +38,8 @@ array(1) {
} }
string(8) "foo bar string(8) "foo bar
" "
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
sign a text with mode SIG_MODE_DETACH sign a text with mode SIG_MODE_DETACH
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -11,8 +13,6 @@ gnupg_setsignmode($gpg, GNUPG_SIG_MODE_DETACH);
gnupg_addsignkey($gpg, $fingerprint, $passphrase); gnupg_addsignkey($gpg, $fingerprint, $passphrase);
$ret = gnupg_sign($gpg, $plaintext); $ret = gnupg_sign($gpg, $plaintext);
$gpg = NULL;
$gpg = gnupg_init(); $gpg = gnupg_init();
$tmp = false; $tmp = false;
$ret = gnupg_verify($gpg,$plaintext, $ret); $ret = gnupg_verify($gpg,$plaintext, $ret);
@ -37,3 +37,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
sign a text with mode SIG_MODE_DETACH and without armored output sign a text with mode SIG_MODE_DETACH and without armored output
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
sign a text with mode SIG_MODE_NORMAL sign a text with mode SIG_MODE_NORMAL
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n --TEST--n
sign a text with mode SIG_MODE_NORMAL and without armored output sign a text with mode SIG_MODE_NORMAL and without armored output
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once dirname(__FILE__) . "/vars.inc"; require_once "gnupgt.inc";
gnupg_test_import(); gnupgt::import_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
} }
} }
string(7) "foo bar" string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

21
tests/gnupgt.inc Normal file
View file

@ -0,0 +1,21 @@
<?php
require_once __DIR__ . "/vars.inc";
class gnupgt {
static function import_key()
{
global $testkey;
self::delete_key();
$gpg = new gnupg();
$gpg->import($testkey);
}
static function delete_key()
{
@unlink(__DIR__ . "/pubring.gpg");
@unlink(__DIR__ . "/secring.gpg");
}
}

View file

@ -3,9 +3,8 @@ putenv("GNUPGHOME=" . dirname(__FILE__));
error_reporting (E_ALL); error_reporting (E_ALL);
$fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"; $fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E";
$passphrase = "blabla"; $passphrase = "blabla";
$plaintext = "foo bar"; $plaintext = "foo bar";
$secringfile = dirname(__FILE__) . "/secring.gpg";
$pubringfile = dirname(__FILE__) . "/pubring.gpg";
$testkey =<<<EOF $testkey =<<<EOF
-----BEGIN PGP PRIVATE KEY BLOCK----- -----BEGIN PGP PRIVATE KEY BLOCK-----
@ -36,28 +35,4 @@ BjoYSlJsrQm0AJ4m57ArwLXA7WXk5iQbMWlvhWCq4g==
=awlp =awlp
-----END PGP PRIVATE KEY BLOCK----- -----END PGP PRIVATE KEY BLOCK-----
EOF; EOF;
function gnupg_test_clear_files() {
global $secringfile, $pubringfile;
if (is_file($secringfile)) {
unlink($secringfile);
}
if (is_file($pubringfile)) {
unlink($pubringfile);
}
}
function gnupg_test_import() {
global $secringfile, $testkey;
if (!file_exists($secringfile) || !filesize($secringfile)) {
$gpg = new gnupg();
return $gpg->import($testkey);
}
return true;
}
?> ?>