2005-10-07 18:59:50 +00:00
|
|
|
/*
|
2005-11-29 20:54:36 +00:00
|
|
|
+--------------------------------------------------------------------+
|
|
|
|
| PECL :: gnupg |
|
|
|
|
+--------------------------------------------------------------------+
|
|
|
|
| Redistribution and use in source and binary forms, with or without |
|
|
|
|
| modification, are permitted provided that the conditions mentioned |
|
|
|
|
| in the accompanying LICENSE file are met. |
|
|
|
|
+--------------------------------------------------------------------+
|
2006-03-16 15:52:43 +00:00
|
|
|
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
2013-07-08 14:11:30 +00:00
|
|
|
| Copyright (c) 2013, Jim Jagielski <jimjag@php.net> |
|
2016-05-22 16:54:19 +00:00
|
|
|
| Copyright (c) 2016, Jakub Zelenka <bukka@php.net> |
|
2005-11-29 20:54:36 +00:00
|
|
|
+--------------------------------------------------------------------+
|
2005-10-07 18:59:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
2012-01-29 02:38:33 +00:00
|
|
|
#include "zend_exceptions.h"
|
2005-10-07 18:59:50 +00:00
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "php_gnupg.h"
|
2016-05-21 20:27:06 +00:00
|
|
|
#include "phpc/phpc.h"
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2005-10-10 17:37:19 +00:00
|
|
|
#include "php_gnupg_keylistiterator.h"
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
static int le_gnupg;
|
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
static zend_class_entry *gnupg_class_entry;
|
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* {{{ GNUPG_GETOBJ */
|
2005-10-18 12:40:03 +00:00
|
|
|
#define GNUPG_GETOBJ() \
|
2016-05-21 20:27:06 +00:00
|
|
|
zval *this = getThis(); \
|
|
|
|
PHPC_THIS_DECLARE(gnupg) = NULL; \
|
|
|
|
zval *res; \
|
|
|
|
do { \
|
|
|
|
if (this) { \
|
|
|
|
PHPC_THIS_FETCH_FROM_ZVAL(gnupg, this); \
|
|
|
|
if (!PHPC_THIS) { \
|
2016-09-11 19:23:32 +00:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, \
|
|
|
|
"Invalid or unitialized gnupg object"); \
|
2016-05-21 20:27:06 +00:00
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
|
|
|
} \
|
2016-05-22 11:07:13 +00:00
|
|
|
} while (0)
|
2016-05-21 20:27:06 +00:00
|
|
|
/* }}} */
|
2005-11-03 21:13:28 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
#define GNUPG_RES_FETCH() \
|
2016-09-11 19:23:32 +00:00
|
|
|
PHPC_THIS = (PHPC_OBJ_STRUCT_NAME(gnupg) *) \
|
|
|
|
PHPC_RES_FETCH(res, "ctx", le_gnupg)
|
2016-05-22 11:07:13 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* {{{ GNUPG_ERR */
|
2005-10-18 12:40:03 +00:00
|
|
|
#define GNUPG_ERR(error) \
|
2016-05-21 20:27:06 +00:00
|
|
|
if (PHPC_THIS) { \
|
|
|
|
switch (PHPC_THIS->errormode) { \
|
2005-11-03 21:13:28 +00:00
|
|
|
case 1: \
|
2016-09-11 19:23:32 +00:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, \
|
|
|
|
(char*)error); \
|
2005-11-03 21:13:28 +00:00
|
|
|
break; \
|
|
|
|
case 2: \
|
2016-09-11 19:23:32 +00:00
|
|
|
zend_throw_exception(\
|
|
|
|
zend_exception_get_default(TSRMLS_C), \
|
|
|
|
(char*) error, \
|
|
|
|
0 TSRMLS_CC \
|
|
|
|
); \
|
2005-11-03 21:13:28 +00:00
|
|
|
break; \
|
|
|
|
default: \
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->errortxt = (char*)error; \
|
2005-11-03 21:13:28 +00:00
|
|
|
} \
|
2016-05-21 20:27:06 +00:00
|
|
|
} else { \
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
|
|
|
} \
|
|
|
|
do { \
|
|
|
|
if (return_value) { \
|
|
|
|
RETVAL_FALSE; \
|
|
|
|
} \
|
2016-05-22 11:07:13 +00:00
|
|
|
} while (0)
|
2005-10-07 18:59:50 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* {{{ gnupg_free_encryptkeys */
|
|
|
|
static void gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (PHPC_THIS) {
|
2005-11-03 21:13:28 +00:00
|
|
|
int idx;
|
2005-11-12 18:35:08 +00:00
|
|
|
/* loop through all encryptkeys and unref them in the gpgme-lib */
|
2016-05-22 11:07:13 +00:00
|
|
|
for (idx=0; idx < PHPC_THIS->encrypt_size; idx++) {
|
2016-05-21 20:27:06 +00:00
|
|
|
gpgme_key_unref(PHPC_THIS->encryptkeys[idx]);
|
2005-11-03 21:13:28 +00:00
|
|
|
}
|
2016-12-12 18:56:54 +00:00
|
|
|
if (PHPC_THIS->encryptkeys != NULL) {
|
|
|
|
efree(PHPC_THIS->encryptkeys);
|
|
|
|
}
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->encryptkeys = NULL;
|
|
|
|
PHPC_THIS->encrypt_size = 0;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-09-11 19:23:32 +00:00
|
|
|
/* {{{ gnupg_free_resource_ptr */
|
2016-05-21 20:27:06 +00:00
|
|
|
static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (PHPC_THIS) {
|
|
|
|
if (PHPC_THIS->ctx) {
|
2005-11-12 18:35:08 +00:00
|
|
|
/* clear all signers from the gpgme-lib and finally release it */
|
2016-05-21 20:27:06 +00:00
|
|
|
gpgme_signers_clear(PHPC_THIS->ctx);
|
|
|
|
gpgme_release(PHPC_THIS->ctx);
|
|
|
|
PHPC_THIS->ctx = NULL;
|
|
|
|
}
|
2005-11-12 18:35:08 +00:00
|
|
|
/* basic cleanup */
|
2016-05-21 20:27:06 +00:00
|
|
|
gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC);
|
|
|
|
zend_hash_destroy(PHPC_THIS->signkeys);
|
|
|
|
FREE_HASHTABLE(PHPC_THIS->signkeys);
|
|
|
|
zend_hash_destroy(PHPC_THIS->decryptkeys);
|
|
|
|
FREE_HASHTABLE(PHPC_THIS->decryptkeys);
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
/* {{{ gnupg_res_dtor */
|
2016-05-21 20:27:06 +00:00
|
|
|
static void gnupg_res_dtor(phpc_res_entry_t *rsrc TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
PHPC_THIS_DECLARE(gnupg) = rsrc->ptr;
|
2016-05-22 18:19:26 +00:00
|
|
|
gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC);
|
2016-05-21 20:27:06 +00:00
|
|
|
efree(PHPC_THIS);
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
/* {{{ gnupg_res_init */
|
2016-05-21 20:27:06 +00:00
|
|
|
static void gnupg_res_init(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC)
|
|
|
|
{
|
2005-11-12 18:35:08 +00:00
|
|
|
/* init the gpgme-lib and set the default values */
|
2005-10-25 16:28:23 +00:00
|
|
|
gpgme_ctx_t ctx;
|
2013-07-17 12:54:49 +00:00
|
|
|
gpgme_error_t err;
|
2016-05-21 20:27:06 +00:00
|
|
|
|
|
|
|
err = gpgme_new(&ctx);
|
|
|
|
if (err == GPG_ERR_NO_ERROR) {
|
2012-01-29 02:42:28 +00:00
|
|
|
#ifdef GNUPG_PATH
|
2016-12-13 18:27:36 +00:00
|
|
|
gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, GNUPG_PATH, NULL);
|
2012-01-29 02:42:28 +00:00
|
|
|
#endif
|
2016-09-11 19:23:32 +00:00
|
|
|
gpgme_set_armor(ctx, 1);
|
2013-07-17 12:54:49 +00:00
|
|
|
}
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->ctx = ctx;
|
|
|
|
PHPC_THIS->encryptkeys = NULL;
|
|
|
|
PHPC_THIS->encrypt_size = 0;
|
|
|
|
PHPC_THIS->signmode = GPGME_SIG_MODE_CLEAR;
|
|
|
|
PHPC_THIS->errortxt = NULL;
|
|
|
|
PHPC_THIS->errormode = 3;
|
|
|
|
ALLOC_HASHTABLE(PHPC_THIS->signkeys);
|
|
|
|
zend_hash_init(PHPC_THIS->signkeys, 0, NULL, NULL, 0);
|
|
|
|
ALLOC_HASHTABLE(PHPC_THIS->decryptkeys);
|
|
|
|
zend_hash_init(PHPC_THIS->decryptkeys, 0, NULL, NULL, 0);
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* {{{ free gnupg */
|
|
|
|
PHPC_OBJ_HANDLER_FREE(gnupg)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_FREE_INIT(gnupg);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC);
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_OBJ_HANDLER_FREE_DESTROY();
|
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* {{{ create_ex gnupg */
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX(gnupg)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
gnupg_res_init(PHPC_THIS TSRMLS_CC);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg);
|
2005-10-08 19:42:50 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ create gnupg */
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_OBJ_HANDLER_CREATE(gnupg)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_RETURN(gnupg);
|
|
|
|
}
|
2016-05-03 07:20:51 +00:00
|
|
|
|
2016-09-13 18:14:00 +00:00
|
|
|
/* {{{ arginfo for gnupg method with armor parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_armor_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, armor)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-12 19:21:40 +00:00
|
|
|
/* {{{ arginfo for gnupg methods with enctext parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_enctext_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, enctext)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg methods with text parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_text_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg methods with key parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_key_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, kye)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-13 18:14:00 +00:00
|
|
|
/* {{{ arginfo for gnupg methods with key parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_keyid_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, kyeid)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-12 19:21:40 +00:00
|
|
|
/* {{{ arginfo for gnupg methods with pattern parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_pattern_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, pattern)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-13 18:14:00 +00:00
|
|
|
/* {{{ arginfo for gnupg methods with errmode parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_errmode_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, errnmode)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg methods with signmode parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_signmode_method, 0)
|
|
|
|
ZEND_ARG_INFO(0, signmode)
|
2016-09-12 19:21:40 +00:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg_verify method */
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_verify_method, 0, 0, 2)
|
2016-05-21 20:27:06 +00:00
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_ARG_INFO(0, signature)
|
|
|
|
ZEND_ARG_INFO(1, plaintext)
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-12 19:21:40 +00:00
|
|
|
/* {{{ arginfo for gnupg_decryptverify method */
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_decryptverify_method, 0, 0, 2)
|
2016-05-21 20:27:06 +00:00
|
|
|
ZEND_ARG_INFO(0, enctext)
|
|
|
|
ZEND_ARG_INFO(1, plaintext)
|
2016-05-03 06:46:51 +00:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-16 18:54:22 +00:00
|
|
|
#define PHP_GNUPG_FALIAS(_name, _arginfo) \
|
|
|
|
PHP_FALIAS(_name, gnupg_ ## _name, _arginfo)
|
|
|
|
|
2005-10-08 19:42:50 +00:00
|
|
|
/* {{{ methodlist gnupg */
|
2016-05-21 20:27:06 +00:00
|
|
|
phpc_function_entry gnupg_methods[] = {
|
2016-09-16 18:54:22 +00:00
|
|
|
PHP_GNUPG_FALIAS(keyinfo, arginfo_gnupg_pattern_method)
|
|
|
|
PHP_GNUPG_FALIAS(verify, arginfo_gnupg_verify_method)
|
|
|
|
PHP_GNUPG_FALIAS(geterror, NULL)
|
|
|
|
PHP_GNUPG_FALIAS(clearsignkeys, NULL)
|
|
|
|
PHP_GNUPG_FALIAS(clearencryptkeys, NULL)
|
|
|
|
PHP_GNUPG_FALIAS(cleardecryptkeys, NULL)
|
|
|
|
PHP_GNUPG_FALIAS(setarmor, arginfo_gnupg_armor_method)
|
|
|
|
PHP_GNUPG_FALIAS(encrypt, arginfo_gnupg_text_method)
|
|
|
|
PHP_GNUPG_FALIAS(decrypt, arginfo_gnupg_enctext_method)
|
2017-09-07 23:29:31 +00:00
|
|
|
PHP_GNUPG_FALIAS(messagekeys, arginfo_gnupg_enctext_method)
|
2016-09-16 18:54:22 +00:00
|
|
|
PHP_GNUPG_FALIAS(export, arginfo_gnupg_pattern_method)
|
|
|
|
PHP_GNUPG_FALIAS(import, arginfo_gnupg_key_method)
|
|
|
|
PHP_GNUPG_FALIAS(getprotocol, NULL)
|
|
|
|
PHP_GNUPG_FALIAS(setsignmode, arginfo_gnupg_signmode_method)
|
|
|
|
PHP_GNUPG_FALIAS(sign, arginfo_gnupg_text_method)
|
|
|
|
PHP_GNUPG_FALIAS(encryptsign, arginfo_gnupg_text_method)
|
|
|
|
PHP_GNUPG_FALIAS(decryptverify, arginfo_gnupg_decryptverify_method)
|
|
|
|
PHP_GNUPG_FALIAS(addsignkey, arginfo_gnupg_key_method)
|
|
|
|
PHP_GNUPG_FALIAS(addencryptkey, arginfo_gnupg_key_method)
|
|
|
|
PHP_GNUPG_FALIAS(adddecryptkey, arginfo_gnupg_key_method)
|
|
|
|
PHP_GNUPG_FALIAS(deletekey, arginfo_gnupg_key_method)
|
|
|
|
PHP_GNUPG_FALIAS(gettrustlist, arginfo_gnupg_pattern_method)
|
|
|
|
PHP_GNUPG_FALIAS(listsignatures, arginfo_gnupg_keyid_method)
|
|
|
|
PHP_GNUPG_FALIAS(seterrormode, arginfo_gnupg_errmode_method)
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_FE_END
|
2005-10-07 18:59:50 +00:00
|
|
|
};
|
2006-03-16 15:52:43 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2016-09-15 18:41:21 +00:00
|
|
|
/* {{{ arginfo for gnupg function with no parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_void_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg function with armor parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_armor_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, armor)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with enctext parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_enctext_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, enctext)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with text parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_text_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with key parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_key_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, kye)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with key parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_keyid_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, kyeid)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with pattern parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_pattern_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, pattern)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with errmode parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_errmode_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, errnmode)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg functions with signmode parameter */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_gnupg_signmode_function, 0)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, signmode)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ arginfo gnupg_verify_function */
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_verify_function, 0, 0, 3)
|
2016-05-21 20:27:06 +00:00
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_ARG_INFO(0, signature)
|
|
|
|
ZEND_ARG_INFO(1, plaintext)
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-09-15 18:41:21 +00:00
|
|
|
/* {{{ arginfo gnupg_decryptverify_function */
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_decryptverify_function, 0, 0, 3)
|
2016-05-21 20:27:06 +00:00
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_ARG_INFO(0, enctext)
|
|
|
|
ZEND_ARG_INFO(1, plaintext)
|
2016-05-03 07:20:51 +00:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
2006-03-16 15:52:43 +00:00
|
|
|
|
|
|
|
/* {{{ functionlist gnupg */
|
2005-10-18 12:40:03 +00:00
|
|
|
static zend_function_entry gnupg_functions[] = {
|
2016-09-15 18:41:21 +00:00
|
|
|
PHP_FE(gnupg_init, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_keyinfo, arginfo_gnupg_pattern_function)
|
|
|
|
PHP_FE(gnupg_sign, arginfo_gnupg_text_function)
|
2016-05-03 07:20:51 +00:00
|
|
|
PHP_FE(gnupg_verify, arginfo_gnupg_verify_function)
|
2016-09-15 18:41:21 +00:00
|
|
|
PHP_FE(gnupg_clearsignkeys, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_clearencryptkeys, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_cleardecryptkeys, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_setarmor, arginfo_gnupg_armor_function)
|
|
|
|
PHP_FE(gnupg_encrypt, arginfo_gnupg_text_function)
|
|
|
|
PHP_FE(gnupg_decrypt, arginfo_gnupg_enctext_function)
|
2017-09-07 23:29:31 +00:00
|
|
|
PHP_FE(gnupg_messagekeys, arginfo_gnupg_enctext_function)
|
2016-09-15 18:41:21 +00:00
|
|
|
PHP_FE(gnupg_export, arginfo_gnupg_pattern_function)
|
|
|
|
PHP_FE(gnupg_import, arginfo_gnupg_key_function)
|
|
|
|
PHP_FE(gnupg_getprotocol, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_setsignmode, arginfo_gnupg_signmode_function)
|
|
|
|
PHP_FE(gnupg_encryptsign, arginfo_gnupg_text_function)
|
2016-05-03 07:20:51 +00:00
|
|
|
PHP_FE(gnupg_decryptverify, arginfo_gnupg_decryptverify_function)
|
2016-09-15 18:41:21 +00:00
|
|
|
PHP_FE(gnupg_geterror, arginfo_gnupg_void_function)
|
|
|
|
PHP_FE(gnupg_addsignkey, arginfo_gnupg_key_function)
|
|
|
|
PHP_FE(gnupg_addencryptkey, arginfo_gnupg_key_function)
|
|
|
|
PHP_FE(gnupg_adddecryptkey, arginfo_gnupg_key_function)
|
|
|
|
PHP_FE(gnupg_deletekey, arginfo_gnupg_key_function)
|
|
|
|
PHP_FE(gnupg_gettrustlist, arginfo_gnupg_pattern_function)
|
|
|
|
PHP_FE(gnupg_listsignatures, arginfo_gnupg_keyid_function)
|
|
|
|
PHP_FE(gnupg_seterrormode, arginfo_gnupg_errmode_function)
|
|
|
|
PHPC_FE_END
|
2005-10-18 12:40:03 +00:00
|
|
|
};
|
2005-10-07 18:59:50 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ gnupg_module_entry
|
|
|
|
*/
|
|
|
|
zend_module_entry gnupg_module_entry = {
|
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
"gnupg",
|
2005-10-18 12:40:03 +00:00
|
|
|
gnupg_functions,
|
2005-10-07 18:59:50 +00:00
|
|
|
PHP_MINIT(gnupg),
|
|
|
|
PHP_MSHUTDOWN(gnupg),
|
2015-12-27 06:44:02 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2005-10-07 18:59:50 +00:00
|
|
|
PHP_MINFO(gnupg),
|
2005-11-03 21:13:28 +00:00
|
|
|
PHP_GNUPG_VERSION,
|
2005-10-07 18:59:50 +00:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#ifdef COMPILE_DL_GNUPG
|
|
|
|
ZEND_GET_MODULE(gnupg)
|
|
|
|
#endif
|
|
|
|
|
2016-10-05 19:47:27 +00:00
|
|
|
#define PHP_GNUPG_DO(_action) ((PHPC_THIS->err = _action) == GPG_ERR_NO_ERROR)
|
|
|
|
|
2016-09-21 19:58:52 +00:00
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL_EX(_g_arr, _g_name, _g_struct, _g_key) \
|
2016-09-20 19:46:10 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_BOOL(\
|
2016-09-21 19:58:52 +00:00
|
|
|
PHPC_VAL_CAST_TO_PZVAL(_g_arr), #_g_name, _g_struct->_g_key)
|
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(_g_arr, _g_name, _g_struct) \
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL_EX(_g_arr, _g_name, _g_struct, _g_name)
|
2016-09-20 19:46:10 +00:00
|
|
|
|
2016-09-21 19:58:52 +00:00
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_LONG_EX(_g_arr, _g_name, _g_struct, _g_key) \
|
2016-09-20 19:46:10 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(\
|
2016-09-21 19:58:52 +00:00
|
|
|
PHPC_VAL_CAST_TO_PZVAL(_g_arr), #_g_name, _g_struct->_g_key)
|
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(_g_arr, _g_name, _g_struct) \
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG_EX(_g_arr, _g_name, _g_struct, _g_name)
|
2016-09-20 19:46:10 +00:00
|
|
|
|
2016-09-21 19:58:52 +00:00
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR_EX(_g_arr, _g_name, _g_struct, _g_key) \
|
2016-09-20 19:46:10 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_CSTR(\
|
2016-09-21 19:58:52 +00:00
|
|
|
PHPC_VAL_CAST_TO_PZVAL(_g_arr), #_g_name, _g_struct->_g_key)
|
|
|
|
#define PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(_g_arr, _g_name, _g_struct) \
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR_EX(_g_arr, _g_name, _g_struct, _g_name)
|
2016-09-20 19:46:10 +00:00
|
|
|
|
2016-09-18 19:11:22 +00:00
|
|
|
#define PHP_GNUPG_SET_CLASS_CONST(_name, _value) \
|
|
|
|
zend_declare_class_constant_long(gnupg_class_entry, \
|
|
|
|
_name, sizeof(_name) - 1, _value TSRMLS_CC)
|
|
|
|
|
|
|
|
#define PHP_GNUPG_REG_CONST(_name, _value) \
|
|
|
|
REGISTER_LONG_CONSTANT(_name, _value, CONST_CS | CONST_PERSISTENT);
|
2016-05-21 20:27:06 +00:00
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MINIT_FUNCTION(gnupg)
|
|
|
|
{
|
2005-10-18 12:40:03 +00:00
|
|
|
zend_class_entry ce;
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* init class */
|
2016-05-21 20:27:06 +00:00
|
|
|
INIT_CLASS_ENTRY(ce, "gnupg", gnupg_methods);
|
|
|
|
PHPC_CLASS_SET_HANDLER_CREATE(ce, gnupg);
|
|
|
|
gnupg_class_entry = PHPC_CLASS_REGISTER(ce);
|
|
|
|
PHPC_OBJ_INIT_HANDLERS(gnupg);
|
|
|
|
PHPC_OBJ_SET_HANDLER_OFFSET(gnupg);
|
|
|
|
PHPC_OBJ_SET_HANDLER_FREE(gnupg);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
/* register resource */
|
2016-09-18 19:24:07 +00:00
|
|
|
le_gnupg = zend_register_list_destructors_ex(
|
|
|
|
gnupg_res_dtor, NULL, "ctx", module_number);
|
2016-05-21 20:27:06 +00:00
|
|
|
|
|
|
|
if (SUCCESS != gnupg_keylistiterator_init()) {
|
2005-10-10 17:37:19 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2016-09-18 19:11:22 +00:00
|
|
|
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIG_MODE_NORMAL", GPGME_SIG_MODE_NORMAL);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIG_MODE_DETACH", GPGME_SIG_MODE_DETACH);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIG_MODE_CLEAR", GPGME_SIG_MODE_CLEAR);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_UNKNOWN", GPGME_VALIDITY_UNKNOWN);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_UNDEFINED", GPGME_VALIDITY_UNDEFINED);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_NEVER", GPGME_VALIDITY_NEVER);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_MARGINAL", GPGME_VALIDITY_MARGINAL);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_FULL", GPGME_VALIDITY_FULL);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("VALIDITY_ULTIMATE", GPGME_VALIDITY_ULTIMATE);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("PROTOCOL_OpenPGP", GPGME_PROTOCOL_OpenPGP);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("PROTOCOL_CMS", GPGME_PROTOCOL_CMS);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_VALID", GPGME_SIGSUM_VALID);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_GREEN", GPGME_SIGSUM_GREEN);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_RED", GPGME_SIGSUM_RED);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_KEY_REVOKED", GPGME_SIGSUM_KEY_REVOKED);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_KEY_EXPIRED", GPGME_SIGSUM_KEY_EXPIRED);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_SIG_EXPIRED", GPGME_SIGSUM_SIG_EXPIRED);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_KEY_MISSING", GPGME_SIGSUM_KEY_MISSING);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_CRL_MISSING", GPGME_SIGSUM_CRL_MISSING);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_CRL_TOO_OLD", GPGME_SIGSUM_CRL_TOO_OLD);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_BAD_POLICY", GPGME_SIGSUM_BAD_POLICY);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("SIGSUM_SYS_ERROR", GPGME_SIGSUM_SYS_ERROR);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("ERROR_WARNING", 1);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("ERROR_EXCEPTION", 2);
|
|
|
|
PHP_GNUPG_SET_CLASS_CONST("ERROR_SILENT", 3);
|
|
|
|
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIG_MODE_NORMAL", GPGME_SIG_MODE_NORMAL);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIG_MODE_DETACH", GPGME_SIG_MODE_DETACH);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIG_MODE_CLEAR", GPGME_SIG_MODE_CLEAR);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_UNKNOWN", GPGME_VALIDITY_UNKNOWN);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_UNDEFINED", GPGME_VALIDITY_UNDEFINED);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_NEVER", GPGME_VALIDITY_NEVER);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_MARGINAL", GPGME_VALIDITY_MARGINAL);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_FULL", GPGME_VALIDITY_FULL);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_VALIDITY_ULTIMATE", GPGME_VALIDITY_ULTIMATE);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_PROTOCOL_OpenPGP", GPGME_PROTOCOL_OpenPGP);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_PROTOCOL_CMS", GPGME_PROTOCOL_CMS);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_VALID", GPGME_SIGSUM_VALID);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_GREEN", GPGME_SIGSUM_GREEN);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_RED", GPGME_SIGSUM_RED);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_KEY_REVOKED", GPGME_SIGSUM_KEY_REVOKED);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_KEY_EXPIRED", GPGME_SIGSUM_KEY_EXPIRED);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_SIG_EXPIRED", GPGME_SIGSUM_SIG_EXPIRED);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_KEY_MISSING", GPGME_SIGSUM_KEY_MISSING);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_CRL_MISSING", GPGME_SIGSUM_CRL_MISSING);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_CRL_TOO_OLD", GPGME_SIGSUM_CRL_TOO_OLD);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_BAD_POLICY", GPGME_SIGSUM_BAD_POLICY);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_SIGSUM_SYS_ERROR", GPGME_SIGSUM_SYS_ERROR);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_ERROR_WARNING", 1);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_ERROR_EXCEPTION", 2);
|
|
|
|
PHP_GNUPG_REG_CONST("GNUPG_ERROR_SILENT", 3);
|
2016-05-21 20:27:06 +00:00
|
|
|
|
2016-12-15 18:33:57 +00:00
|
|
|
/* init gpgme subsystems */
|
|
|
|
gpgme_check_version(NULL);
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(gnupg)
|
|
|
|
{
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MINFO_FUNCTION(gnupg)
|
|
|
|
{
|
2016-05-21 20:27:06 +00:00
|
|
|
const char *php_gpgme_version = gpgme_check_version(NULL);
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_header(2, "gnupg support", "enabled");
|
2016-05-21 20:27:06 +00:00
|
|
|
php_info_print_table_row(2, "GPGme Version", php_gpgme_version);
|
|
|
|
php_info_print_table_row(2, "Extension Version", PHP_GNUPG_VERSION);
|
2005-10-07 18:59:50 +00:00
|
|
|
php_info_print_table_end();
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
/* {{{ passphrase_cb */
|
|
|
|
gpgme_error_t passphrase_cb(
|
2016-09-23 19:51:35 +00:00
|
|
|
void *hook, const char *uid_hint, const char *passphrase_info,
|
2016-06-16 09:09:56 +00:00
|
|
|
int last_was_bad, int fd)
|
2016-05-21 20:27:06 +00:00
|
|
|
{
|
2012-01-29 02:38:33 +00:00
|
|
|
char uid[17];
|
2005-10-24 20:40:55 +00:00
|
|
|
int idx;
|
2005-10-25 16:28:23 +00:00
|
|
|
char *passphrase = NULL;
|
2006-03-16 15:52:43 +00:00
|
|
|
zval *return_value = NULL;
|
2016-06-16 09:09:56 +00:00
|
|
|
PHPC_THIS_DECLARE(gnupg) = hook;
|
|
|
|
TSRMLS_FETCH();
|
2005-10-24 20:40:55 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (last_was_bad) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("Incorrent passphrase");
|
2005-10-07 18:59:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
for (idx=0; idx < 16; idx++) {
|
2005-10-24 20:40:55 +00:00
|
|
|
uid[idx] = uid_hint[idx];
|
|
|
|
}
|
|
|
|
uid[16] = '\0';
|
2016-09-18 19:24:07 +00:00
|
|
|
if (!PHPC_HASH_CSTR_FIND_PTR_IN_COND(
|
|
|
|
PHPC_THIS->signkeys, (char *)uid, passphrase)) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("no passphrase set");
|
2005-10-07 18:59:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!passphrase) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("no passphrase set");
|
2016-05-22 11:07:13 +00:00
|
|
|
return 1;
|
2005-10-24 20:40:55 +00:00
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-18 19:24:07 +00:00
|
|
|
if (write(fd, passphrase, strlen(passphrase)) == strlen(passphrase)
|
|
|
|
&& write(fd, "\n", 1) == 1) {
|
2013-07-09 12:48:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GNUPG_ERR("write failed");
|
|
|
|
return 1;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
/* }}} */
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
/* {{{ passphrase_decrypt_cb */
|
|
|
|
gpgme_error_t passphrase_decrypt_cb (
|
2016-06-16 09:09:56 +00:00
|
|
|
void *hook,
|
2016-05-22 11:07:13 +00:00
|
|
|
const char *uid_hint, const char *passphrase_info,
|
2016-06-16 09:09:56 +00:00
|
|
|
int last_was_bad, int fd)
|
2016-05-22 11:07:13 +00:00
|
|
|
{
|
|
|
|
char uid[17];
|
|
|
|
int idx;
|
|
|
|
char *passphrase = NULL;
|
2006-03-16 15:52:43 +00:00
|
|
|
zval *return_value = NULL;
|
2016-06-16 09:09:56 +00:00
|
|
|
PHPC_THIS_DECLARE(gnupg) = hook;
|
|
|
|
TSRMLS_FETCH();
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (last_was_bad) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("Incorrent passphrase");
|
2016-05-22 11:07:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (idx=0; idx < 16; idx++) {
|
|
|
|
uid[idx] = uid_hint[idx];
|
|
|
|
}
|
|
|
|
uid[16] = '\0';
|
2016-09-18 19:24:07 +00:00
|
|
|
if (!PHPC_HASH_CSTR_FIND_PTR_IN_COND(
|
|
|
|
PHPC_THIS->decryptkeys, (char *)uid, passphrase)) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("no passphrase set");
|
2016-05-22 11:07:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!passphrase) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("no passphrase set");
|
2016-05-22 11:07:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-09-18 19:24:07 +00:00
|
|
|
if (write(fd, passphrase, strlen(passphrase)) == strlen(passphrase)
|
|
|
|
&& write(fd, "\n", 1) == 1) {
|
2013-07-09 12:48:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GNUPG_ERR("write failed");
|
|
|
|
return 1;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
/* {{{ gnupg_fetchsignatures */
|
2016-05-22 11:07:13 +00:00
|
|
|
int gnupg_fetchsignatures(gpgme_signature_t gpgme_signatures, zval *main_arr)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
phpc_val sig_arr;
|
2013-07-09 13:09:18 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_ARRAY_INIT(main_arr);
|
|
|
|
while (gpgme_signatures) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_VAL_MAKE(sig_arr);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(sig_arr));
|
2016-09-23 19:51:35 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR_EX(sig_arr, fingerprint, gpgme_signatures, fpr);
|
2016-09-21 19:58:52 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sig_arr, validity, gpgme_signatures);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sig_arr, timestamp, gpgme_signatures);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sig_arr, status, gpgme_signatures);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sig_arr, summary, gpgme_signatures);
|
|
|
|
|
2016-09-18 19:24:07 +00:00
|
|
|
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(
|
|
|
|
main_arr,
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(sig_arr)
|
|
|
|
);
|
2016-05-22 11:07:13 +00:00
|
|
|
|
|
|
|
gpgme_signatures = gpgme_signatures->next;
|
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
/* {{{ proto resource gnupg_init()
|
|
|
|
* inits gnupg and returns a resource
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_init)
|
|
|
|
{
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS_DECLARE(gnupg);
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_THIS = emalloc(sizeof(PHPC_OBJ_STRUCT_NAME(gnupg)));
|
2016-05-21 20:27:06 +00:00
|
|
|
gnupg_res_init(PHPC_THIS TSRMLS_CC);
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_RES_RETURN(PHPC_RES_REGISTER(PHPC_THIS, le_gnupg));
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/* {{{ proto bool gnupg_setarmor(int armor)
|
|
|
|
* turn on/off armor mode
|
|
|
|
* 0 = off
|
|
|
|
* >0 = on
|
|
|
|
* */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_setarmor)
|
|
|
|
{
|
|
|
|
phpc_long_t armor;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
|
|
|
|
&armor) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",
|
|
|
|
&res, &armor) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (armor > 1) {
|
2005-10-07 18:59:50 +00:00
|
|
|
armor = 1; /*just to make sure */
|
|
|
|
}
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_set_armor(PHPC_THIS->ctx, armor);
|
2005-10-07 18:59:50 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-11-12 14:07:59 +00:00
|
|
|
/* {{{ proto bool gnupg_seterrormode(int errormde) */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_seterrormode)
|
|
|
|
{
|
|
|
|
phpc_long_t errormode;
|
2005-11-12 14:07:59 +00:00
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
|
|
|
|
&errormode) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",
|
|
|
|
&res, &errormode) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
2005-11-12 14:07:59 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
switch (errormode) {
|
2005-11-12 14:07:59 +00:00
|
|
|
case 1: /* warning */
|
|
|
|
case 3: /* silent */
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->errormode = errormode;
|
2005-11-12 14:07:59 +00:00
|
|
|
break;
|
|
|
|
case 2: /* exception */
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->errormode = errormode;
|
2005-11-12 14:07:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-11-28 14:55:33 +00:00
|
|
|
GNUPG_ERR("invalid errormode");
|
2005-11-12 14:07:59 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
RETURN_TRUE;
|
2005-11-12 14:07:59 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/* {{{ proto bool gnupg_setsignmode(int signmode)
|
|
|
|
* sets the mode for signing operations
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_setsignmode)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
phpc_long_t signmode;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
|
|
|
|
&signmode) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",
|
|
|
|
&res, &signmode) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 11:07:13 +00:00
|
|
|
}
|
|
|
|
switch (signmode) {
|
2005-10-07 18:59:50 +00:00
|
|
|
case GPGME_SIG_MODE_NORMAL:
|
|
|
|
case GPGME_SIG_MODE_DETACH:
|
|
|
|
case GPGME_SIG_MODE_CLEAR:
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->signmode = signmode;
|
2005-11-12 14:07:59 +00:00
|
|
|
RETVAL_TRUE;
|
2005-10-07 18:59:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("invalid signmode");
|
2005-11-12 14:07:59 +00:00
|
|
|
RETVAL_FALSE;
|
2005-10-07 18:59:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
RETURN_TRUE;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string gnupg_geterror(void)
|
|
|
|
* returns the last errormessage
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_geterror)
|
|
|
|
{
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!this) {
|
2016-09-23 19:51:35 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->errortxt) {
|
2005-10-18 12:40:03 +00:00
|
|
|
RETURN_FALSE;
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
|
|
|
PHPC_CSTR_RETURN(PHPC_THIS->errortxt);
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int gnupg_getprotocol(void)
|
|
|
|
* returns the currently used pgp-protocol.
|
|
|
|
* atm only OpenPGP is supported
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_getprotocol) {
|
2005-10-18 12:40:03 +00:00
|
|
|
RETURN_LONG(GPGME_PROTOCOL_OpenPGP);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto array gnupg_keyinfo(string pattern)
|
2016-09-19 18:53:41 +00:00
|
|
|
* returns an array with informations about all keys, that matches
|
|
|
|
* the given pattern
|
2005-10-07 18:59:50 +00:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(gnupg_keyinfo)
|
|
|
|
{
|
2016-05-22 11:07:13 +00:00
|
|
|
char *searchkey = NULL;
|
|
|
|
phpc_str_size_t searchkey_len;
|
|
|
|
phpc_val subarr, userid, userids, subkey, subkeys;
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
2005-10-25 16:28:23 +00:00
|
|
|
gpgme_user_id_t gpgme_userid;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&searchkey, &searchkey_len) == FAILURE) {
|
2005-10-18 12:40:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-09-19 18:53:41 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &searchkey, &searchkey_len) == FAILURE) {
|
2005-10-18 12:40:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
2016-09-19 18:53:41 +00:00
|
|
|
|
|
|
|
PHPC_THIS->err = gpgme_op_keylist_start(PHPC_THIS->ctx, searchkey, 0);
|
2016-09-23 19:51:35 +00:00
|
|
|
if ((PHPC_THIS->err) != GPG_ERR_NO_ERROR) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not init keylist");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_ARRAY_INIT(return_value);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-10-05 19:47:27 +00:00
|
|
|
while (PHP_GNUPG_DO(gpgme_op_keylist_next(PHPC_THIS->ctx, &gpgme_key))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_VAL_MAKE(subarr);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subarr));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_VAL_MAKE(subkeys);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subkeys));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_VAL_MAKE(userids);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(userids));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subarr, disabled, gpgme_key);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subarr, expired, gpgme_key);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subarr, revoked, gpgme_key);
|
2016-09-23 19:51:35 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL_EX(subarr, is_secret, gpgme_key, secret);
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subarr, can_sign, gpgme_key);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subarr, can_encrypt, gpgme_key);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_userid = gpgme_key->uids;
|
|
|
|
while (gpgme_userid) {
|
|
|
|
PHPC_VAL_MAKE(userid);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(userid));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(userid, name, gpgme_userid);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(userid, comment, gpgme_userid);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(userid, email, gpgme_userid);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(userid, uid, gpgme_userid);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(userid, revoked, gpgme_userid);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(userid, invalid, gpgme_userid);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(userids),
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(userid));
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_userid = gpgme_userid->next;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_ZVAL(
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(subarr),
|
|
|
|
"uids",
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(userids));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
while (gpgme_subkey) {
|
2016-05-22 18:19:26 +00:00
|
|
|
PHPC_VAL_MAKE(subkey);
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subkey));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (gpgme_subkey->fpr) {
|
2016-09-23 19:51:35 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR_EX(subkey, fingerprint, gpgme_subkey, fpr);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(subkey, keyid, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(subkey, timestamp, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(subkey, expires, gpgme_subkey);
|
2016-09-23 19:51:35 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL_EX(subkey, is_secret, gpgme_subkey, secret);
|
2016-09-22 20:05:19 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, invalid, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, can_encrypt, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, can_sign, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, disabled, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, expired, gpgme_subkey);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, revoked, gpgme_subkey);
|
|
|
|
|
|
|
|
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(subkeys),
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(subkey));
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_ZVAL(
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(subarr),
|
|
|
|
"subkeys",
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(subkeys));
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-09-22 20:05:19 +00:00
|
|
|
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(
|
|
|
|
return_value, PHPC_VAL_CAST_TO_PZVAL(subarr));
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
/* {{{ proto bool gnupg_addsignkey(string key) */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_addsignkey)
|
|
|
|
{
|
|
|
|
char *key_id = NULL;
|
|
|
|
phpc_str_size_t key_id_len;
|
|
|
|
char *passphrase = NULL;
|
|
|
|
phpc_str_size_t passphrase_len;
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
2005-10-24 17:33:59 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-24 17:33:59 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-23 19:51:35 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s",
|
|
|
|
&key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-23 19:51:35 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s",
|
|
|
|
&res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
2016-09-23 19:51:35 +00:00
|
|
|
|
2016-10-05 19:47:27 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 1))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 11:07:13 +00:00
|
|
|
}
|
|
|
|
if (passphrase) {
|
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
while (gpgme_subkey) {
|
|
|
|
if (gpgme_subkey->can_sign == 1) {
|
2016-09-23 19:51:35 +00:00
|
|
|
PHPC_HASH_CSTR_ADD_PTR(PHPC_THIS->signkeys,
|
|
|
|
gpgme_subkey->keyid, passphrase, passphrase_len + 1);
|
2015-12-27 06:44:02 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
2005-10-24 20:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-06 19:45:40 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_signers_add(PHPC_THIS->ctx, gpgme_key))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_ERR("could not add signer");
|
|
|
|
} else {
|
2005-11-10 20:24:27 +00:00
|
|
|
RETVAL_TRUE;
|
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
/* {{{ proto bool gnupg_adddecryptkey(string key) */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_adddecryptkey)
|
|
|
|
{
|
|
|
|
char *key_id = NULL;
|
|
|
|
phpc_str_size_t key_id_len;
|
|
|
|
char *passphrase = NULL;
|
|
|
|
phpc_str_size_t passphrase_len;
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-09-23 19:51:35 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
|
|
|
|
&key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-23 19:51:35 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss",
|
|
|
|
&res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
2016-10-07 19:28:22 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 1))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 11:07:13 +00:00
|
|
|
}
|
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
while (gpgme_subkey) {
|
|
|
|
if (gpgme_subkey->secret == 1) {
|
2016-10-07 19:28:22 +00:00
|
|
|
PHPC_HASH_CSTR_ADD_PTR(
|
|
|
|
PHPC_THIS->decryptkeys, gpgme_subkey->keyid,
|
|
|
|
passphrase, passphrase_len + 1);
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
2016-05-22 11:07:13 +00:00
|
|
|
RETURN_TRUE;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
/* {{{ proto bool gnupg_addencryptkey(string key) */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_addencryptkey)
|
|
|
|
{
|
|
|
|
char *key_id = NULL;
|
|
|
|
phpc_str_size_t key_id_len;
|
|
|
|
gpgme_key_t gpgme_key = NULL;
|
2016-12-12 18:56:54 +00:00
|
|
|
size_t encrypt_keys_size;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-07 19:28:22 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&key_id, &key_id_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-07 19:28:22 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &key_id, &key_id_len) == FAILURE) {
|
2016-05-22 11:07:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-10-07 19:28:22 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 0))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_ERR("get_key failed");
|
2016-10-07 19:28:22 +00:00
|
|
|
RETURN_FALSE;
|
2016-05-22 11:07:13 +00:00
|
|
|
}
|
2016-12-12 18:56:54 +00:00
|
|
|
|
|
|
|
encrypt_keys_size = sizeof(PHPC_THIS->encryptkeys) * (PHPC_THIS->encrypt_size + 2);
|
|
|
|
if (PHPC_THIS->encryptkeys == NULL) {
|
|
|
|
PHPC_THIS->encryptkeys = emalloc(encrypt_keys_size);
|
|
|
|
} else {
|
|
|
|
PHPC_THIS->encryptkeys = erealloc(PHPC_THIS->encryptkeys, encrypt_keys_size);
|
|
|
|
}
|
2016-05-21 20:27:06 +00:00
|
|
|
PHPC_THIS->encryptkeys[PHPC_THIS->encrypt_size] = gpgme_key;
|
|
|
|
PHPC_THIS->encrypt_size++;
|
|
|
|
PHPC_THIS->encryptkeys[PHPC_THIS->encrypt_size] = NULL;
|
2005-10-24 17:33:59 +00:00
|
|
|
RETURN_TRUE;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 19:36:10 +00:00
|
|
|
/* {{{ proto bool gnupg_clearsignerkeys(void)
|
2005-10-07 18:59:50 +00:00
|
|
|
* removes all keys which are set for signing
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_clearsignkeys)
|
|
|
|
{
|
2015-12-27 06:44:02 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!this) {
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2005-10-18 12:40:03 +00:00
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_signers_clear(PHPC_THIS->ctx);
|
2016-05-21 20:27:06 +00:00
|
|
|
zend_hash_clean(PHPC_THIS->signkeys);
|
2005-10-07 18:59:50 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 19:36:10 +00:00
|
|
|
/* {{{ proto bool gnupg_clearencryptkeys(void)
|
2005-10-07 18:59:50 +00:00
|
|
|
* removes all keys which are set for encryption
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_clearencryptkeys)
|
|
|
|
{
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!this) {
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-05-21 20:27:06 +00:00
|
|
|
gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
RETURN_TRUE;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 19:36:10 +00:00
|
|
|
/* {{{ proto bool gnupg_clearsignerkeys(void)
|
2005-10-25 16:28:23 +00:00
|
|
|
* removes all keys which are set for signing
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_cleardecryptkeys)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_GETOBJ();
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!this) {
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-21 20:27:06 +00:00
|
|
|
zend_hash_clean(PHPC_THIS->decryptkeys);
|
2016-05-22 16:54:19 +00:00
|
|
|
RETURN_TRUE;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/* {{{ proto string gnupg_sign(string text)
|
|
|
|
* signs the given test with the key, which was set with setsignerkey before
|
|
|
|
* and returns the signed text
|
|
|
|
* the signmode depends on gnupg_setsignmode
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_sign)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *value = NULL;
|
|
|
|
phpc_str_size_t value_len;
|
|
|
|
char *userret;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_t in, out;
|
2005-10-15 14:42:56 +00:00
|
|
|
gpgme_sign_result_t result;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-09 18:54:03 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-09 18:54:03 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-06-16 09:09:56 +00:00
|
|
|
gpgme_set_passphrase_cb(PHPC_THIS->ctx, passphrase_cb, PHPC_THIS);
|
2016-10-09 18:54:03 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, value, value_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-09 18:54:03 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new(&out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-09 18:54:03 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_sign(PHPC_THIS->ctx, in, out, PHPC_THIS->signmode))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->errortxt) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("data signing failed");
|
|
|
|
}
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
2006-03-16 15:52:43 +00:00
|
|
|
RETVAL_FALSE;
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
|
|
|
result = gpgme_op_sign_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (result->invalid_signers) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("invalid signers found");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!result->signatures) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("no signature in result");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (ret_size < 1) {
|
2005-11-03 21:13:28 +00:00
|
|
|
RETVAL_FALSE;
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_CSTRL_RETVAL(userret, ret_size);
|
2005-11-03 21:13:28 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
free(userret);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string gnupg_encrypt(string text)
|
|
|
|
* encrypts the given text with the key, which was set with setencryptkey before
|
|
|
|
* and returns the encrypted text
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_encrypt)
|
|
|
|
{
|
2005-10-07 18:59:50 +00:00
|
|
|
char *value = NULL;
|
2016-05-22 11:07:13 +00:00
|
|
|
phpc_str_size_t value_len;
|
2005-10-07 18:59:50 +00:00
|
|
|
char *userret = NULL;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2005-10-07 18:59:50 +00:00
|
|
|
gpgme_data_t in, out;
|
2005-10-15 14:42:56 +00:00
|
|
|
gpgme_encrypt_result_t result;
|
|
|
|
|
2015-12-27 06:44:02 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-23 19:41:39 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-23 19:41:39 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->encryptkeys) {
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_ERR("no key for encryption set");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-10-23 19:41:39 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, value, value_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could no create in-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-10-23 19:41:39 +00:00
|
|
|
if (!PHP_GNUPG_DO(PHPC_THIS->err = gpgme_data_new(&out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-10-23 19:41:39 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_encrypt(PHPC_THIS->ctx, PHPC_THIS->encryptkeys,
|
|
|
|
GPGME_ENCRYPT_ALWAYS_TRUST, in, out))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("encrypt failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
|
|
|
result = gpgme_op_encrypt_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (result->invalid_recipients) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("Invalid recipient encountered");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
|
|
|
gpgme_data_release(in);
|
|
|
|
PHPC_CSTRL_RETVAL(userret, ret_size);
|
|
|
|
free(userret);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (ret_size < 1) {
|
2005-10-07 18:59:50 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
/* {{{ proto string gnupg_encrypt_sign(string text)
|
2016-10-24 19:52:26 +00:00
|
|
|
* encrypts and signs the given text with the keys, which weres set
|
|
|
|
* with setencryptkey and setsignkey before, and returns the encrypted text
|
2005-10-09 15:55:02 +00:00
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_encryptsign)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *value = NULL;
|
2016-05-22 11:07:13 +00:00
|
|
|
phpc_str_size_t value_len;
|
2016-05-22 16:54:19 +00:00
|
|
|
char *userret = NULL;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_t in, out;
|
2005-10-15 14:42:56 +00:00
|
|
|
gpgme_encrypt_result_t result;
|
2005-10-09 15:55:02 +00:00
|
|
|
gpgme_sign_result_t sign_result;
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-24 19:52:26 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-24 19:52:26 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &value, &value_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-09 15:55:02 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->encryptkeys) {
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_ERR("no key for encryption set");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-06-16 09:09:56 +00:00
|
|
|
gpgme_set_passphrase_cb(PHPC_THIS->ctx, passphrase_cb, PHPC_THIS);
|
2016-10-24 19:52:26 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem (&in, value, value_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-24 19:52:26 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new(&out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-24 19:52:26 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_encrypt_sign(PHPC_THIS->ctx, PHPC_THIS->encryptkeys,
|
|
|
|
GPGME_ENCRYPT_ALWAYS_TRUST, in, out))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->errortxt) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("encrypt-sign failed");
|
|
|
|
}
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
2006-03-16 15:52:43 +00:00
|
|
|
RETVAL_FALSE;
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-09 15:55:02 +00:00
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
result = gpgme_op_encrypt_result (PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (result->invalid_recipients) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("Invalid recipient encountered");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
sign_result = gpgme_op_sign_result (PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (sign_result->invalid_signers) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("invalid signers found");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!sign_result->signatures) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("could not find a signature");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(out);
|
|
|
|
return;
|
|
|
|
}
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 18:19:26 +00:00
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
PHPC_CSTRL_RETVAL(userret, ret_size);
|
2005-11-03 21:13:28 +00:00
|
|
|
free (userret);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (ret_size < 1) {
|
2016-05-22 16:54:19 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2005-10-09 15:55:02 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
/* {{{ proto array gnupg_verify(string text, string signature [, string &plaintext])
|
2005-10-07 18:59:50 +00:00
|
|
|
* verifies the given clearsigned text and returns information about the result in an array
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_verify)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_t gpgme_text, gpgme_sig;
|
|
|
|
gpgme_verify_result_t gpgme_result;
|
|
|
|
/* text without the signature, if its a detached one, or the text incl the sig */
|
|
|
|
zval *signed_text = NULL;
|
|
|
|
/* signature, if its a detached one */
|
|
|
|
zval *signature = NULL;
|
|
|
|
/* signed_text without the signature if its not a detached sig */
|
|
|
|
zval *plain_text = NULL;
|
|
|
|
char *gpg_plain;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t gpg_plain_len;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-25 19:35:34 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z",
|
|
|
|
&signed_text, &signature, &plain_text) == FAILURE) {
|
2006-05-18 19:27:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-25 19:35:34 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzz|z",
|
|
|
|
&res, &signed_text, &signature, &plain_text) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
|
|
|
if (Z_TYPE_P(signature) == IS_STRING) { /* detached signature */
|
2006-05-18 19:27:52 +00:00
|
|
|
/* setup signature-databuffer for gpgme */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(
|
|
|
|
&gpgme_sig, Z_STRVAL_P(signature), Z_STRLEN_P(signature), 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("could not create signature-databuffer");
|
|
|
|
return;
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
/* and the text */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(
|
|
|
|
&gpgme_text, Z_STRVAL_P(signed_text), Z_STRLEN_P(signed_text), 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("could not create text-databuffer");
|
|
|
|
gpgme_data_release(gpgme_sig);
|
|
|
|
gpgme_data_release(gpgme_text);
|
|
|
|
return;
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
/* now verify sig + text */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_verify(PHPC_THIS->ctx, gpgme_sig, gpgme_text, NULL))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("verify failed");
|
|
|
|
gpgme_data_release(gpgme_sig);
|
|
|
|
gpgme_data_release(gpgme_text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { /* clearsign or normal signature */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(
|
|
|
|
&gpgme_sig, Z_STRVAL_P(signed_text), Z_STRLEN_P(signed_text), 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("could not create signature-databuffer");
|
|
|
|
return;
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
/* set a NULL databuffer for gpgme */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&gpgme_text, NULL, 0, 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("could not create text-databuffer");
|
|
|
|
gpgme_data_release(gpgme_sig);
|
|
|
|
gpgme_data_release(gpgme_text);
|
|
|
|
return;
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
/* and verify the 'signature' */
|
2016-10-25 19:35:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_verify(PHPC_THIS->ctx, gpgme_sig, NULL, gpgme_text))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("verify failed");
|
|
|
|
gpgme_data_release(gpgme_sig);
|
|
|
|
gpgme_data_release(gpgme_text);
|
|
|
|
return;
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
/* now get the result */
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_result = gpgme_op_verify_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!gpgme_result->signatures) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("no signature found");
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2006-05-18 19:27:52 +00:00
|
|
|
/* fetch all signatures in an array */
|
2016-05-22 16:54:19 +00:00
|
|
|
gnupg_fetchsignatures(gpgme_result->signatures, return_value);
|
2006-05-18 19:27:52 +00:00
|
|
|
/* get a 'plain' version of the text without a signature */
|
2016-05-22 16:54:19 +00:00
|
|
|
gpg_plain = gpgme_data_release_and_get_mem(gpgme_text, &gpg_plain_len);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (gpg_plain && gpg_plain_len > 0 && plain_text) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_PZVAL_DEREF(plain_text);
|
|
|
|
PHPC_PZVAL_CSTRL(plain_text, gpg_plain, gpg_plain_len);
|
|
|
|
}
|
|
|
|
free(gpg_plain);
|
|
|
|
}
|
|
|
|
gpgme_data_release(gpgme_sig);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string gnupg_decrypt(string enctext)
|
|
|
|
* decrypts the given enctext
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_decrypt)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *enctxt;
|
2016-05-22 11:07:13 +00:00
|
|
|
phpc_str_size_t enctxt_len;
|
2016-05-22 16:54:19 +00:00
|
|
|
char *userret;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_t in, out;
|
|
|
|
gpgme_decrypt_result_t result;
|
2015-12-27 06:44:02 +00:00
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-27 19:28:57 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&enctxt, &enctxt_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-27 19:28:57 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &enctxt, &enctxt_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2016-06-16 09:09:56 +00:00
|
|
|
gpgme_set_passphrase_cb(PHPC_THIS->ctx, passphrase_decrypt_cb, PHPC_THIS);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-10-27 19:28:57 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, enctxt, enctxt_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
if ((PHPC_THIS->err = gpgme_data_new(&out)) != GPG_ERR_NO_ERROR) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-10-27 19:28:57 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_decrypt(PHPC_THIS->ctx, in, out))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->errortxt) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("decrypt failed");
|
|
|
|
}
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
2006-03-16 15:52:43 +00:00
|
|
|
RETVAL_FALSE;
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
result = gpgme_op_decrypt_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (result->unsupported_algorithm) {
|
2005-11-03 21:13:28 +00:00
|
|
|
GNUPG_ERR("unsupported algorithm");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
|
|
|
return;
|
2015-12-27 06:44:02 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
|
|
|
gpgme_data_release(in);
|
|
|
|
PHPC_CSTRL_RETVAL(userret, ret_size);
|
|
|
|
free(userret);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (ret_size < 1) {
|
2005-11-03 21:13:28 +00:00
|
|
|
RETVAL_FALSE;
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2017-09-07 23:29:31 +00:00
|
|
|
/* {{{ proto string gnupg_messagekeys(string enctext)
|
|
|
|
* returns the recipient keyids and their status for the given enctext
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(gnupg_messagekeys)
|
|
|
|
{
|
|
|
|
char *enctxt;
|
|
|
|
phpc_str_size_t enctxt_len;
|
|
|
|
gpgme_data_t in, out;
|
|
|
|
gpgme_decrypt_result_t result;
|
|
|
|
gpgme_recipient_t recipient;
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
if (this) {
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&enctxt, &enctxt_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &enctxt, &enctxt_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GNUPG_RES_FETCH();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, enctxt, enctxt_len, 0))) {
|
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2017-09-11 16:46:01 +00:00
|
|
|
RETURN_FALSE;
|
2017-09-07 23:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((PHPC_THIS->err = gpgme_data_new(&out)) != GPG_ERR_NO_ERROR) {
|
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
|
|
|
gpgme_data_release(in);
|
2017-09-11 16:46:01 +00:00
|
|
|
RETURN_FALSE;
|
2017-09-07 23:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PHP_GNUPG_DO(gpgme_op_decrypt(PHPC_THIS->ctx, in, out));
|
|
|
|
|
|
|
|
result = gpgme_op_decrypt_result(PHPC_THIS->ctx);
|
|
|
|
|
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
2017-09-11 16:46:01 +00:00
|
|
|
if (!result->recipients) {
|
|
|
|
GNUPG_ERR("invalid enctext");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHPC_ARRAY_INIT(return_value);
|
2017-09-07 23:29:31 +00:00
|
|
|
|
2017-09-11 16:46:01 +00:00
|
|
|
recipient = result->recipients;
|
2017-09-07 23:29:31 +00:00
|
|
|
|
2017-09-11 16:46:01 +00:00
|
|
|
while (recipient) {
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_BOOL(return_value, recipient->keyid, !recipient->status);
|
2017-09-07 23:29:31 +00:00
|
|
|
|
2017-09-11 16:46:01 +00:00
|
|
|
recipient = recipient->next;
|
2017-09-07 23:29:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
/* {{{ proto string gnupg_decryptverify(string enctext, string &plaintext)
|
|
|
|
* decrypts the given enctext
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_decryptverify)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *enctxt;
|
|
|
|
phpc_str_size_t enctxt_len;
|
|
|
|
zval *plaintext;
|
|
|
|
char *userret;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_data_t in, out;
|
|
|
|
gpgme_decrypt_result_t decrypt_result;
|
|
|
|
gpgme_verify_result_t verify_result;
|
2005-10-09 15:55:02 +00:00
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-10-30 20:11:17 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
|
|
|
|
&enctxt, &enctxt_len, &plaintext) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-10-30 20:11:17 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz",
|
|
|
|
&res, &enctxt, &enctxt_len, &plaintext) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
|
|
|
PHPC_PZVAL_DEREF(plaintext);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
2016-06-16 09:09:56 +00:00
|
|
|
gpgme_set_passphrase_cb(PHPC_THIS->ctx, passphrase_decrypt_cb, PHPC_THIS);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
2016-10-30 20:11:17 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, enctxt, enctxt_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-30 20:11:17 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new(&out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create out-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-10-30 20:11:17 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_decrypt_verify(PHPC_THIS->ctx, in, out))) {
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!PHPC_THIS->errortxt) {
|
2006-03-16 15:52:43 +00:00
|
|
|
GNUPG_ERR("decrypt-verify failed");
|
|
|
|
}
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
gpgme_data_release(out);
|
2006-03-16 15:52:43 +00:00
|
|
|
RETVAL_FALSE;
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
|
|
|
PHPC_PZVAL_CSTRL(plaintext, userret, ret_size);
|
|
|
|
free(userret);
|
|
|
|
decrypt_result = gpgme_op_decrypt_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (decrypt_result->unsupported_algorithm) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("unsupported algorithm");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
verify_result = gpgme_op_verify_result(PHPC_THIS->ctx);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!verify_result->signatures) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("no signature found");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gnupg_fetchsignatures(verify_result->signatures, return_value);
|
|
|
|
gpgme_data_release(in);
|
2005-10-09 15:55:02 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/* {{{ proto string gnupg_export(string pattern)
|
|
|
|
* exports the first public key which matches against the given pattern
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_export)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *searchkey = NULL;
|
|
|
|
phpc_str_size_t searchkey_len;
|
|
|
|
char *userret;
|
2016-05-22 18:19:26 +00:00
|
|
|
size_t ret_size;
|
2005-10-18 12:40:03 +00:00
|
|
|
gpgme_data_t out;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-11-02 20:27:52 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&searchkey, &searchkey_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-11-02 20:27:52 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &searchkey, &searchkey_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-11-02 20:27:52 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new(&out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-11-02 20:27:52 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_export(PHPC_THIS->ctx, searchkey, 0, out))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("export failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(out);
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (ret_size < 1) {
|
2005-11-03 21:13:28 +00:00
|
|
|
RETVAL_FALSE;
|
2016-05-22 16:54:19 +00:00
|
|
|
} else {
|
|
|
|
PHPC_CSTRL_RETVAL(userret, ret_size);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
free(userret);
|
2005-10-07 18:59:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2005-10-08 19:42:50 +00:00
|
|
|
|
2005-10-15 14:42:56 +00:00
|
|
|
/* {{{ proto array gnupg_import(string key)
|
|
|
|
* imports the given key and returns a status-array
|
2016-05-22 16:54:19 +00:00
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_import)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *importkey = NULL;
|
|
|
|
phpc_str_size_t importkey_len;
|
|
|
|
gpgme_data_t in;
|
2005-10-15 14:42:56 +00:00
|
|
|
gpgme_import_result_t result;
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-11-04 19:37:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&importkey, &importkey_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-11-04 19:37:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &importkey, &importkey_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-11-04 19:37:28 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_data_new_from_mem(&in, importkey, importkey_len, 0))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
2016-11-04 19:37:28 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_import(PHPC_THIS->ctx,in))) {
|
2005-10-15 14:42:56 +00:00
|
|
|
GNUPG_ERR("import failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_data_release(in);
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
|
|
|
gpgme_data_release(in);
|
2016-05-22 16:54:19 +00:00
|
|
|
result = gpgme_op_import_result(PHPC_THIS->ctx);
|
2015-09-09 11:28:12 +00:00
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!result || !result->imports || result->imports->result != GPG_ERR_NO_ERROR) {
|
2015-02-11 18:10:16 +00:00
|
|
|
RETURN_FALSE;
|
2015-02-11 17:51:41 +00:00
|
|
|
}
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_ARRAY_INIT(return_value);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "imported", result->imported);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "unchanged", result->unchanged);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "newuserids", result->new_user_ids);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "newsubkeys", result->new_sub_keys);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "secretimported", result->secret_imported);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "secretunchanged", result->secret_unchanged);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "newsignatures", result->new_signatures);
|
|
|
|
PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "skippedkeys", result->skipped_new_keys);
|
2016-05-22 11:07:13 +00:00
|
|
|
if (result->imports && result->imports->fpr) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_CSTR(return_value, "fingerprint", result->imports->fpr);
|
2005-11-25 14:31:36 +00:00
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
/* {{{ proto book gnupg_deletekey(string key)
|
2016-05-22 16:54:19 +00:00
|
|
|
* deletes a key from the keyring
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_deletekey)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *key;
|
|
|
|
phpc_str_size_t key_len;
|
|
|
|
phpc_long_t allow_secret = 0;
|
2005-10-25 16:28:23 +00:00
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-11-06 21:28:32 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
|
|
|
|
&key, &key_len, &allow_secret) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-11-06 21:28:32 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l",
|
|
|
|
&res, &key, &key_len, &allow_secret) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-11-06 21:28:32 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_get_key(PHPC_THIS->ctx, key, &gpgme_key, 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-11-06 21:28:32 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_delete(PHPC_THIS->ctx,gpgme_key,allow_secret))) {
|
2005-10-25 16:28:23 +00:00
|
|
|
GNUPG_ERR("delete failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
RETVAL_FALSE;
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2005-11-10 20:24:27 +00:00
|
|
|
RETVAL_TRUE;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto array gnupg_gettrustlist(string pattern)
|
|
|
|
* searching for trust items which match PATTERN
|
|
|
|
*/
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_gettrustlist)
|
|
|
|
{
|
2016-05-22 16:54:19 +00:00
|
|
|
char *pattern;
|
2016-05-22 11:07:13 +00:00
|
|
|
phpc_str_size_t pattern_len;
|
2016-05-22 16:54:19 +00:00
|
|
|
phpc_val sub_arr;
|
2005-10-25 16:28:23 +00:00
|
|
|
gpgme_trust_item_t item;
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-11-09 20:44:22 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&pattern, &pattern_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-11-09 20:44:22 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &pattern, &pattern_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-11-09 20:44:22 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_op_trustlist_start(PHPC_THIS->ctx, pattern, 0))) {
|
2005-10-25 16:28:23 +00:00
|
|
|
GNUPG_ERR("could not start trustlist");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_ARRAY_INIT(return_value);
|
2016-11-09 20:44:22 +00:00
|
|
|
while (PHP_GNUPG_DO(gpgme_op_trustlist_next(PHPC_THIS->ctx, &item))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_VAL_MAKE(sub_arr);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(sub_arr));
|
|
|
|
|
2016-11-09 20:44:22 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sub_arr, level, item);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sub_arr, type, item);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sub_arr, keyid, item);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR_EX(sub_arr, ownertrust, item, owner_trust);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sub_arr, validity, item);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sub_arr, name, item);
|
|
|
|
gpgme_trust_item_unref(item);
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(return_value, PHPC_VAL_CAST_TO_PZVAL(sub_arr));
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto array gnupg_listsignatures(string keyid) */
|
2016-05-22 11:07:13 +00:00
|
|
|
PHP_FUNCTION(gnupg_listsignatures)
|
|
|
|
{
|
2005-10-25 16:28:23 +00:00
|
|
|
char *keyid;
|
2016-05-22 11:07:13 +00:00
|
|
|
phpc_str_size_t keyid_len;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
2016-05-22 16:54:19 +00:00
|
|
|
phpc_val sub_arr;
|
|
|
|
phpc_val sig_arr;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
gpgme_user_id_t gpgme_userid;
|
|
|
|
gpgme_key_sig_t gpgme_signature;
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
2016-05-22 11:07:13 +00:00
|
|
|
if (this) {
|
2016-11-13 20:46:34 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
|
|
|
&keyid, &keyid_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
} else {
|
2016-11-13 20:46:34 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
|
|
|
|
&res, &keyid, &keyid_len) == FAILURE) {
|
2016-05-22 16:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
GNUPG_RES_FETCH();
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-11-13 20:46:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_set_keylist_mode(PHPC_THIS->ctx, GPGME_KEYLIST_MODE_SIGS))) {
|
2005-10-25 16:28:23 +00:00
|
|
|
GNUPG_ERR("could not switch to sigmode");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2016-11-13 20:46:34 +00:00
|
|
|
if (!PHP_GNUPG_DO(gpgme_get_key(PHPC_THIS->ctx, keyid, &gpgme_key, 0))) {
|
2016-05-22 16:54:19 +00:00
|
|
|
GNUPG_ERR("get_key failed. given key not unique?");
|
2005-11-10 20:24:27 +00:00
|
|
|
return;
|
2016-05-22 16:54:19 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
if (!gpgme_key->uids) {
|
2005-10-25 16:28:23 +00:00
|
|
|
GNUPG_ERR("no uids found");
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2016-05-22 11:07:13 +00:00
|
|
|
PHPC_ARRAY_INIT(return_value);
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_userid = gpgme_key->uids;
|
2016-05-22 11:07:13 +00:00
|
|
|
while (gpgme_userid) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_VAL_MAKE(sub_arr);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(sub_arr));
|
2005-10-25 16:28:23 +00:00
|
|
|
gpgme_signature = gpgme_userid->signatures;
|
2016-05-22 11:07:13 +00:00
|
|
|
while (gpgme_signature) {
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_VAL_MAKE(sig_arr);
|
|
|
|
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(sig_arr));
|
|
|
|
|
2016-11-13 20:46:34 +00:00
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sig_arr, uid, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sig_arr, name, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sig_arr, email, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(sig_arr, comment, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_LONG(sig_arr, expires, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(sig_arr, revoked, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(sig_arr, expired, gpgme_signature);
|
|
|
|
PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(sig_arr, invalid, gpgme_signature);
|
2016-05-22 16:54:19 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_ZVAL(
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(sub_arr),
|
|
|
|
gpgme_signature->keyid,
|
|
|
|
PHPC_VAL_CAST_TO_PZVAL(sig_arr)
|
|
|
|
);
|
|
|
|
gpgme_signature = gpgme_signature->next;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2016-11-13 20:46:34 +00:00
|
|
|
PHPC_ARRAY_ADD_ASSOC_ZVAL(
|
|
|
|
return_value, gpgme_userid->uid, PHPC_VAL_CAST_TO_PZVAL(sub_arr));
|
2016-05-22 16:54:19 +00:00
|
|
|
gpgme_userid = gpgme_userid->next;
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
gpgme_key_unref(gpgme_key);
|
2005-10-25 16:28:23 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|