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> |
|
2005-11-29 20:54:36 +00:00
|
|
|
|
+--------------------------------------------------------------------+
|
2005-10-07 18:59:50 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#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"
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ZEND_ENGINE_2
|
2005-10-10 17:37:19 +00:00
|
|
|
|
#include "php_gnupg_keylistiterator.h"
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#endif
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
static int le_gnupg;
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#ifdef ZEND_ENGINE_2
|
2005-10-07 18:59:50 +00:00
|
|
|
|
static zend_object_handlers gnupg_object_handlers;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#endif
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-10 17:37:19 +00:00
|
|
|
|
/* {{{ defs */
|
2006-03-16 15:52:43 +00:00
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#define GNUPG_GETOBJ() \
|
2006-03-16 15:52:43 +00:00
|
|
|
|
zval *this = getThis(); \
|
|
|
|
|
gnupg_object *intern; \
|
|
|
|
|
zval *res; \
|
|
|
|
|
if(this){ \
|
|
|
|
|
intern = (gnupg_object*) zend_object_store_get_object(getThis() TSRMLS_CC); \
|
|
|
|
|
if(!intern){ \
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg object"); \
|
|
|
|
|
RETURN_FALSE; \
|
|
|
|
|
} \
|
|
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#define GNUPG_ERR(error) \
|
|
|
|
|
if(intern){ \
|
2005-11-12 14:07:59 +00:00
|
|
|
|
switch (intern->errormode) { \
|
2005-11-03 21:13:28 +00:00
|
|
|
|
case 1: \
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
|
|
|
|
break; \
|
|
|
|
|
case 2: \
|
2012-01-29 02:38:33 +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: \
|
|
|
|
|
intern->errortxt = (char*)error; \
|
|
|
|
|
} \
|
2005-10-18 12:40:03 +00:00
|
|
|
|
}else{ \
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
|
|
|
|
} \
|
2006-03-16 15:52:43 +00:00
|
|
|
|
if(return_value){ \
|
|
|
|
|
RETVAL_FALSE; \
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#define GNUPG_ERR(error) \
|
|
|
|
|
if(intern && intern->errormode!=1) { \
|
|
|
|
|
intern->errortxt = (char*)error; \
|
|
|
|
|
}else{ \
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
|
|
|
|
} \
|
|
|
|
|
if(return_value){ \
|
|
|
|
|
RETVAL_FALSE; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define GNUPG_GETOBJ() \
|
|
|
|
|
zval *this = NULL; \
|
|
|
|
|
zval *res; \
|
|
|
|
|
gnupg_object *intern;
|
|
|
|
|
|
|
|
|
|
#endif
|
2005-10-07 18:59:50 +00:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
/* {{{ free encryptkeys */
|
|
|
|
|
static void gnupg_free_encryptkeys(gnupg_object *intern TSRMLS_DC){
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if(intern){
|
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 */
|
2005-11-03 21:13:28 +00:00
|
|
|
|
for(idx=0;idx<intern->encrypt_size;idx++){
|
|
|
|
|
gpgme_key_unref (intern->encryptkeys[idx]);
|
|
|
|
|
}
|
2005-11-12 18:35:08 +00:00
|
|
|
|
/* it´s an odd-thing, but other solutions makes problems :
|
|
|
|
|
* erealloc(x,0) gives a segfault with PHP 4 and debug enabled
|
|
|
|
|
* efree(x) alone ends in a segfault
|
|
|
|
|
*/
|
2005-11-12 14:07:59 +00:00
|
|
|
|
efree(erealloc(intern->encryptkeys,0));
|
2005-10-24 17:33:59 +00:00
|
|
|
|
intern->encryptkeys = NULL;
|
|
|
|
|
intern->encrypt_size = 0;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
/* {{{ free_resource */
|
|
|
|
|
static void gnupg_free_resource_ptr(gnupg_object *intern TSRMLS_DC){
|
|
|
|
|
if(intern){
|
|
|
|
|
if(intern->ctx){
|
2005-11-12 18:35:08 +00:00
|
|
|
|
/* clear all signers from the gpgme-lib and finally release it */
|
2005-10-24 17:33:59 +00:00
|
|
|
|
gpgme_signers_clear (intern->ctx);
|
|
|
|
|
gpgme_release (intern->ctx);
|
|
|
|
|
intern->ctx = NULL;
|
|
|
|
|
}
|
2005-11-12 18:35:08 +00:00
|
|
|
|
/* basic cleanup */
|
|
|
|
|
gnupg_free_encryptkeys(intern TSRMLS_CC);
|
2005-10-24 20:40:55 +00:00
|
|
|
|
zend_hash_destroy(intern->signkeys);
|
|
|
|
|
FREE_HASHTABLE(intern->signkeys);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
zend_hash_destroy(intern->decryptkeys);
|
|
|
|
|
FREE_HASHTABLE(intern->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 */
|
|
|
|
|
static void gnupg_res_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
|
|
|
|
|
gnupg_object *intern;
|
|
|
|
|
intern = (gnupg_object *) rsrc->ptr;
|
|
|
|
|
gnupg_free_resource_ptr(intern TSRMLS_CC);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
efree(intern);
|
2005-10-18 12:40:03 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
/* {{{ gnupg_res_init */
|
2005-11-03 21:13:28 +00:00
|
|
|
|
static void gnupg_res_init(gnupg_object *intern 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;
|
2010-07-20 18:48:19 +00:00
|
|
|
|
gpgme_check_version (NULL);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_new (&ctx);
|
2012-01-29 02:42:28 +00:00
|
|
|
|
#ifdef GNUPG_PATH
|
|
|
|
|
gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, GNUPG_PATH, NULL);
|
|
|
|
|
#endif
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_set_armor (ctx,1);
|
|
|
|
|
intern->ctx = ctx;
|
|
|
|
|
intern->encryptkeys = NULL;
|
|
|
|
|
intern->encrypt_size = 0;
|
|
|
|
|
intern->signmode = GPGME_SIG_MODE_CLEAR;
|
|
|
|
|
intern->errortxt = NULL;
|
2005-11-12 14:07:59 +00:00
|
|
|
|
intern->errormode = 3;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
ALLOC_HASHTABLE (intern->signkeys);
|
|
|
|
|
zend_hash_init (intern->signkeys, 0, NULL, NULL, 0);
|
|
|
|
|
ALLOC_HASHTABLE (intern->decryptkeys);
|
|
|
|
|
zend_hash_init (intern->decryptkeys, 0, NULL, NULL, 0);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#ifdef ZEND_ENGINE_2
|
2005-10-07 18:59:50 +00:00
|
|
|
|
/* {{{ free_storage */
|
2005-11-03 21:13:28 +00:00
|
|
|
|
static void gnupg_obj_dtor(gnupg_object *intern TSRMLS_DC){
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if(!intern){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
|
gnupg_free_resource_ptr(intern TSRMLS_CC);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if(intern->zo.properties){
|
|
|
|
|
zend_hash_destroy(intern->zo.properties);
|
|
|
|
|
FREE_HASHTABLE(intern->zo.properties);
|
|
|
|
|
}
|
|
|
|
|
efree(intern);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
|
/* {{{ objects_new */
|
2005-11-03 21:13:28 +00:00
|
|
|
|
zend_object_value gnupg_obj_new(zend_class_entry *class_type TSRMLS_DC){
|
|
|
|
|
gnupg_object *intern;
|
2012-01-29 02:38:33 +00:00
|
|
|
|
#if PHP_VERSION_ID < 50399
|
2005-10-07 18:59:50 +00:00
|
|
|
|
zval *tmp;
|
2012-01-29 02:38:33 +00:00
|
|
|
|
#endif
|
2005-10-07 18:59:50 +00:00
|
|
|
|
zend_object_value retval;
|
2005-10-09 15:55:02 +00:00
|
|
|
|
|
2012-01-29 02:29:40 +00:00
|
|
|
|
intern = ecalloc(1, sizeof(gnupg_object));
|
2005-10-25 16:28:23 +00:00
|
|
|
|
intern->zo.ce = class_type;
|
2012-01-29 02:29:40 +00:00
|
|
|
|
|
|
|
|
|
#if PHP_VERSION_ID < 50399
|
2005-10-25 16:28:23 +00:00
|
|
|
|
intern->zo.properties = NULL;
|
|
|
|
|
ALLOC_HASHTABLE (intern->zo.properties);
|
|
|
|
|
zend_hash_init (intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
|
|
|
|
zend_hash_copy (intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
2012-01-29 02:29:40 +00:00
|
|
|
|
#else
|
|
|
|
|
object_properties_init(&intern->zo, class_type);
|
|
|
|
|
#endif
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-11-03 21:13:28 +00:00
|
|
|
|
retval.handle = zend_objects_store_put(intern,NULL,(zend_objects_free_object_storage_t) gnupg_obj_dtor,NULL TSRMLS_CC);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
retval.handlers = (zend_object_handlers *) & gnupg_object_handlers;
|
2005-11-03 21:13:28 +00:00
|
|
|
|
gnupg_res_init (intern TSRMLS_CC);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-08 19:42:50 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ methodlist gnupg */
|
2005-10-07 18:59:50 +00:00
|
|
|
|
static zend_function_entry gnupg_methods[] = {
|
2006-11-03 12:38:35 +00:00
|
|
|
|
PHP_FALIAS(keyinfo, gnupg_keyinfo, NULL)
|
|
|
|
|
PHP_FALIAS(verify, gnupg_verify, NULL)
|
|
|
|
|
PHP_FALIAS(geterror, gnupg_geterror, NULL)
|
|
|
|
|
PHP_FALIAS(clearsignkeys, gnupg_clearsignkeys, NULL)
|
|
|
|
|
PHP_FALIAS(clearencryptkeys, gnupg_clearencryptkeys, NULL)
|
|
|
|
|
PHP_FALIAS(cleardecryptkeys, gnupg_cleardecryptkeys, NULL)
|
|
|
|
|
PHP_FALIAS(setarmor, gnupg_setarmor, NULL)
|
|
|
|
|
PHP_FALIAS(encrypt, gnupg_encrypt, NULL)
|
|
|
|
|
PHP_FALIAS(decrypt, gnupg_decrypt, NULL)
|
|
|
|
|
PHP_FALIAS(export, gnupg_export, NULL)
|
|
|
|
|
PHP_FALIAS(import, gnupg_import, NULL)
|
|
|
|
|
PHP_FALIAS(getprotocol, gnupg_getprotocol, NULL)
|
|
|
|
|
PHP_FALIAS(setsignmode, gnupg_setsignmode, NULL)
|
|
|
|
|
PHP_FALIAS(sign, gnupg_sign, NULL)
|
|
|
|
|
PHP_FALIAS(encryptsign, gnupg_encryptsign, NULL)
|
|
|
|
|
PHP_FALIAS(decryptverify, gnupg_decryptverify, NULL)
|
|
|
|
|
PHP_FALIAS(addsignkey, gnupg_addsignkey, NULL)
|
|
|
|
|
PHP_FALIAS(addencryptkey, gnupg_addencryptkey, NULL)
|
|
|
|
|
PHP_FALIAS(adddecryptkey, gnupg_adddecryptkey, NULL)
|
|
|
|
|
PHP_FALIAS(deletekey, gnupg_deletekey, NULL)
|
|
|
|
|
PHP_FALIAS(gettrustlist, gnupg_gettrustlist, NULL)
|
|
|
|
|
PHP_FALIAS(listsignatures, gnupg_listsignatures, NULL)
|
|
|
|
|
PHP_FALIAS(seterrormode, gnupg_seterrormode, NULL)
|
2005-10-07 18:59:50 +00:00
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
2006-03-16 15:52:43 +00:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ class constants */
|
|
|
|
|
static void gnupg_declare_long_constant(const char *const_name, long value TSRMLS_DC){
|
|
|
|
|
#if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1
|
|
|
|
|
zend_declare_class_constant_long(gnupg_class_entry, (char*)const_name, strlen(const_name), value TSRMLS_CC);
|
|
|
|
|
#else
|
|
|
|
|
zval *constant = malloc(sizeof(*constant));
|
|
|
|
|
ZVAL_LONG(constant,value);
|
|
|
|
|
INIT_PZVAL(constant);
|
|
|
|
|
zend_hash_update(&gnupg_class_entry->constants_table, (char*)const_name, strlen(const_name)+1, &constant, sizeof(zval*), NULL);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#endif /* ZEND_ENGINE_2 */
|
2006-03-16 15:52:43 +00:00
|
|
|
|
|
|
|
|
|
/* {{{ functionlist gnupg */
|
2005-10-18 12:40:03 +00:00
|
|
|
|
static zend_function_entry gnupg_functions[] = {
|
|
|
|
|
PHP_FE(gnupg_init, NULL)
|
|
|
|
|
PHP_FE(gnupg_keyinfo, NULL)
|
|
|
|
|
PHP_FE(gnupg_sign, NULL)
|
|
|
|
|
PHP_FE(gnupg_verify, NULL)
|
2005-10-24 17:33:59 +00:00
|
|
|
|
PHP_FE(gnupg_clearsignkeys, NULL)
|
|
|
|
|
PHP_FE(gnupg_clearencryptkeys, NULL)
|
2005-10-25 16:28:23 +00:00
|
|
|
|
PHP_FE(gnupg_cleardecryptkeys, NULL)
|
2005-10-18 12:40:03 +00:00
|
|
|
|
PHP_FE(gnupg_setarmor, NULL)
|
|
|
|
|
PHP_FE(gnupg_encrypt, NULL)
|
|
|
|
|
PHP_FE(gnupg_decrypt, NULL)
|
|
|
|
|
PHP_FE(gnupg_export, NULL)
|
|
|
|
|
PHP_FE(gnupg_import, NULL)
|
|
|
|
|
PHP_FE(gnupg_getprotocol, NULL)
|
|
|
|
|
PHP_FE(gnupg_setsignmode, NULL)
|
|
|
|
|
PHP_FE(gnupg_encryptsign, NULL)
|
|
|
|
|
PHP_FE(gnupg_decryptverify, NULL)
|
|
|
|
|
PHP_FE(gnupg_geterror, NULL)
|
2005-10-24 17:33:59 +00:00
|
|
|
|
PHP_FE(gnupg_addsignkey, NULL)
|
|
|
|
|
PHP_FE(gnupg_addencryptkey, NULL)
|
2005-10-25 16:28:23 +00:00
|
|
|
|
PHP_FE(gnupg_adddecryptkey, NULL)
|
|
|
|
|
PHP_FE(gnupg_deletekey, NULL)
|
|
|
|
|
PHP_FE(gnupg_gettrustlist, NULL)
|
|
|
|
|
PHP_FE(gnupg_listsignatures, NULL)
|
2005-11-12 14:07:59 +00:00
|
|
|
|
PHP_FE(gnupg_seterrormode, NULL)
|
2005-10-18 12:40:03 +00:00
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
2005-10-07 18:59:50 +00:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ gnupg_module_entry
|
|
|
|
|
*/
|
|
|
|
|
zend_module_entry gnupg_module_entry = {
|
|
|
|
|
#if ZEND_MODULE_API_NO >= 20010901
|
|
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
|
#endif
|
|
|
|
|
"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),
|
2005-10-10 17:37:19 +00:00
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2005-10-07 18:59:50 +00:00
|
|
|
|
PHP_MINFO(gnupg),
|
|
|
|
|
#if ZEND_MODULE_API_NO >= 20010901
|
2005-11-03 21:13:28 +00:00
|
|
|
|
PHP_GNUPG_VERSION,
|
2005-10-07 18:59:50 +00:00
|
|
|
|
#endif
|
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#ifdef COMPILE_DL_GNUPG
|
|
|
|
|
ZEND_GET_MODULE(gnupg)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
|
*/
|
|
|
|
|
PHP_MINIT_FUNCTION(gnupg)
|
|
|
|
|
{
|
2005-10-18 12:40:03 +00:00
|
|
|
|
le_gnupg = zend_register_list_destructors_ex(gnupg_res_dtor, NULL, "ctx", module_number);
|
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
|
zend_class_entry ce;
|
|
|
|
|
INIT_CLASS_ENTRY(ce, "gnupg", gnupg_methods);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
ce.create_object = gnupg_obj_new;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
gnupg_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
|
|
|
|
|
memcpy(&gnupg_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
2005-10-10 17:37:19 +00:00
|
|
|
|
if (SUCCESS != gnupg_keylistiterator_init()){
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
2005-11-12 18:35:08 +00:00
|
|
|
|
gnupg_declare_long_constant("SIG_MODE_NORMAL", GPGME_SIG_MODE_NORMAL TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIG_MODE_DETACH", GPGME_SIG_MODE_DETACH TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIG_MODE_CLEAR", GPGME_SIG_MODE_CLEAR TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_UNKNOWN", GPGME_VALIDITY_UNKNOWN TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_UNDEFINED", GPGME_VALIDITY_UNDEFINED TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_NEVER", GPGME_VALIDITY_NEVER TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_MARGINAL", GPGME_VALIDITY_MARGINAL TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_FULL", GPGME_VALIDITY_FULL TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("VALIDITY_ULTIMATE", GPGME_VALIDITY_ULTIMATE TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("PROTOCOL_OpenPGP", GPGME_PROTOCOL_OpenPGP TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("PROTOCOL_CMS", GPGME_PROTOCOL_CMS TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_VALID", GPGME_SIGSUM_VALID TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_GREEN", GPGME_SIGSUM_GREEN TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_RED", GPGME_SIGSUM_RED TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_KEY_REVOKED", GPGME_SIGSUM_KEY_REVOKED TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_KEY_EXPIRED", GPGME_SIGSUM_KEY_EXPIRED TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_SIG_EXPIRED", GPGME_SIGSUM_SIG_EXPIRED TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_KEY_MISSING", GPGME_SIGSUM_KEY_MISSING TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_CRL_MISSING", GPGME_SIGSUM_CRL_MISSING TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_CRL_TOO_OLD", GPGME_SIGSUM_CRL_TOO_OLD TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_BAD_POLICY", GPGME_SIGSUM_BAD_POLICY TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("SIGSUM_SYS_ERROR", GPGME_SIGSUM_SYS_ERROR TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("ERROR_WARNING", 1 TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("ERROR_EXCEPTION", 2 TSRMLS_CC);
|
|
|
|
|
gnupg_declare_long_constant("ERROR_SILENT", 3 TSRMLS_CC);
|
2005-10-18 12:40:03 +00:00
|
|
|
|
#endif
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIG_MODE_NORMAL", GPGME_SIG_MODE_NORMAL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIG_MODE_DETACH", GPGME_SIG_MODE_DETACH, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIG_MODE_CLEAR", GPGME_SIG_MODE_CLEAR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_UNKNOWN", GPGME_VALIDITY_UNKNOWN, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_UNDEFINED", GPGME_VALIDITY_UNDEFINED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_NEVER", GPGME_VALIDITY_NEVER, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_MARGINAL", GPGME_VALIDITY_MARGINAL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_FULL", GPGME_VALIDITY_FULL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_VALIDITY_ULTIMATE", GPGME_VALIDITY_ULTIMATE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_PROTOCOL_OpenPGP", GPGME_PROTOCOL_OpenPGP, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_PROTOCOL_CMS", GPGME_PROTOCOL_CMS, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_VALID", GPGME_SIGSUM_VALID, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_GREEN", GPGME_SIGSUM_GREEN, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_RED", GPGME_SIGSUM_RED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_KEY_REVOKED", GPGME_SIGSUM_KEY_REVOKED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_KEY_EXPIRED", GPGME_SIGSUM_KEY_EXPIRED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_SIG_EXPIRED", GPGME_SIGSUM_SIG_EXPIRED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_KEY_MISSING", GPGME_SIGSUM_KEY_MISSING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_CRL_MISSING", GPGME_SIGSUM_CRL_MISSING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_CRL_TOO_OLD", GPGME_SIGSUM_CRL_TOO_OLD, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_BAD_POLICY", GPGME_SIGSUM_BAD_POLICY, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_SIGSUM_SYS_ERROR", GPGME_SIGSUM_SYS_ERROR, CONST_CS | CONST_PERSISTENT);
|
2005-11-12 14:07:59 +00:00
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_ERROR_WARNING", 1, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_ERROR_EXCEPTION", 2, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("GNUPG_ERROR_SILENT", 3, CONST_CS | CONST_PERSISTENT);
|
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)
|
|
|
|
|
{
|
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_header(2, "gnupg support", "enabled");
|
|
|
|
|
php_info_print_table_row(2,"GPGme Version",gpgme_check_version(NULL));
|
2005-11-03 21:13:28 +00:00
|
|
|
|
php_info_print_table_row(2,"Extension Version",PHP_GNUPG_VERSION);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
php_info_print_table_end();
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
/* {{{ callback func for setting the passphrase */
|
|
|
|
|
|
2005-11-12 18:35:08 +00:00
|
|
|
|
gpgme_error_t passphrase_cb (gnupg_object *intern, const char *uid_hint, const char *passphrase_info,int last_was_bad, int fd TSRMLS_DC){
|
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;
|
2005-10-24 20:40:55 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +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;
|
|
|
|
|
}
|
2005-10-24 20:40:55 +00:00
|
|
|
|
for(idx=0;idx<16;idx++){
|
|
|
|
|
uid[idx] = uid_hint[idx];
|
|
|
|
|
}
|
|
|
|
|
uid[16] = '\0';
|
|
|
|
|
if(zend_hash_find(intern->signkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
GNUPG_ERR("no passphrase set");
|
2005-10-07 18:59:50 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2005-10-24 20:40:55 +00:00
|
|
|
|
if(!passphrase){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
GNUPG_ERR("no passphrase set");
|
2005-10-24 20:40:55 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
2013-07-09 12:48:04 +00:00
|
|
|
|
if (write (fd, passphrase, strlen(passphrase))==strlen(passphrase)
|
|
|
|
|
&& write (fd, "\n", 1)==1) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
GNUPG_ERR("write failed");
|
|
|
|
|
return 1;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
2005-11-12 18:35:08 +00:00
|
|
|
|
gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint, const char *passphrase_info,int last_was_bad, int fd TSRMLS_DC){
|
2012-01-29 02:38:33 +00:00
|
|
|
|
char uid[17];
|
2005-10-25 16:28:23 +00:00
|
|
|
|
int idx;
|
|
|
|
|
char *passphrase = NULL;
|
2006-03-16 15:52:43 +00:00
|
|
|
|
zval *return_value = NULL;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
|
|
if(last_was_bad){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
GNUPG_ERR("Incorrent passphrase");
|
2005-10-25 16:28:23 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
for(idx=0;idx<16;idx++){
|
|
|
|
|
uid[idx] = uid_hint[idx];
|
|
|
|
|
}
|
|
|
|
|
uid[16] = '\0';
|
|
|
|
|
if(zend_hash_find(intern->decryptkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
GNUPG_ERR("no passphrase set");
|
2005-10-25 16:28:23 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if(!passphrase){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
GNUPG_ERR("no passphrase set");
|
2005-10-25 16:28:23 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2013-07-09 12:48:04 +00:00
|
|
|
|
if (write (fd, passphrase, strlen(passphrase))==strlen(passphrase)
|
|
|
|
|
&& write (fd, "\n", 1)==1) {
|
|
|
|
|
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 */
|
|
|
|
|
int gnupg_fetchsignatures(gpgme_signature_t gpgme_signatures, zval *sig_arr, zval *main_arr){
|
|
|
|
|
array_init (main_arr);
|
|
|
|
|
while(gpgme_signatures){
|
|
|
|
|
ALLOC_INIT_ZVAL (sig_arr);
|
|
|
|
|
array_init (sig_arr);
|
|
|
|
|
add_assoc_string (sig_arr, "fingerprint", gpgme_signatures->fpr, 1);
|
|
|
|
|
add_assoc_long (sig_arr, "validity", gpgme_signatures->validity );
|
|
|
|
|
add_assoc_long (sig_arr, "timestamp", gpgme_signatures->timestamp );
|
|
|
|
|
add_assoc_long (sig_arr, "status", gpgme_signatures->status );
|
2006-05-18 19:27:52 +00:00
|
|
|
|
add_assoc_long (sig_arr, "summary", gpgme_signatures->summary );
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_next_index_zval (main_arr, sig_arr);
|
|
|
|
|
|
|
|
|
|
gpgme_signatures = gpgme_signatures->next;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
|
|
/* {{{ proto resource gnupg_init()
|
|
|
|
|
* inits gnupg and returns a resource
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_init){
|
|
|
|
|
gnupg_object *intern;
|
2005-11-03 21:13:28 +00:00
|
|
|
|
intern = emalloc(sizeof(gnupg_object));
|
2005-11-12 18:35:08 +00:00
|
|
|
|
gnupg_res_init(intern TSRMLS_CC);
|
2005-10-18 12:40:03 +00:00
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value,intern,le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
|
/* {{{ proto bool gnupg_setarmor(int armor)
|
|
|
|
|
* turn on/off armor mode
|
|
|
|
|
* 0 = off
|
|
|
|
|
* >0 = on
|
|
|
|
|
* */
|
|
|
|
|
PHP_FUNCTION(gnupg_setarmor){
|
2010-07-20 19:05:22 +00:00
|
|
|
|
long armor;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &armor) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &armor) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
if(armor > 1){
|
|
|
|
|
armor = 1; /*just to make sure */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpgme_set_armor (intern->ctx,armor);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-11-12 14:07:59 +00:00
|
|
|
|
/* {{{ proto bool gnupg_seterrormode(int errormde) */
|
|
|
|
|
PHP_FUNCTION(gnupg_seterrormode){
|
2010-07-20 19:05:22 +00:00
|
|
|
|
long errormode;
|
2005-11-12 14:07:59 +00:00
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errormode) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &errormode) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(errormode){
|
|
|
|
|
case 1: /* warning */
|
|
|
|
|
case 3: /* silent */
|
|
|
|
|
intern->errormode = errormode;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
|
case 2: /* exception */
|
|
|
|
|
intern->errormode = errormode;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
2005-11-28 14:55:33 +00:00
|
|
|
|
GNUPG_ERR("invalid errormode");
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_setsignmode){
|
2010-07-20 19:05:22 +00:00
|
|
|
|
long signmode;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &signmode) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &signmode) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
switch(signmode){
|
|
|
|
|
case GPGME_SIG_MODE_NORMAL:
|
|
|
|
|
case GPGME_SIG_MODE_DETACH:
|
|
|
|
|
case GPGME_SIG_MODE_CLEAR:
|
|
|
|
|
intern->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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string gnupg_geterror(void)
|
|
|
|
|
* returns the last errormessage
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_geterror){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
if(!this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
if(!intern->errortxt){
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}else{
|
|
|
|
|
RETURN_STRINGL(intern->errortxt, strlen(intern->errortxt), 1);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gnupg_getprotocol(void)
|
|
|
|
|
* returns the currently used pgp-protocol.
|
|
|
|
|
* atm only OpenPGP is supported
|
|
|
|
|
*/
|
|
|
|
|
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)
|
|
|
|
|
* returns an array with informations about all keys, that matches the given pattern
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_keyinfo)
|
|
|
|
|
{
|
|
|
|
|
char *searchkey = NULL;
|
|
|
|
|
int *searchkey_len;
|
|
|
|
|
zval *subarr;
|
|
|
|
|
zval *userid;
|
|
|
|
|
zval *userids;
|
|
|
|
|
zval *subkey;
|
|
|
|
|
zval *subkeys;
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
|
|
|
|
gpgme_user_id_t gpgme_userid;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &searchkey, &searchkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &searchkey, &searchkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if((intern->err = gpgme_op_keylist_start(intern->ctx, searchkey, 0)) != 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
while(!(intern->err = gpgme_op_keylist_next(intern->ctx, &gpgme_key))){
|
2005-10-07 18:59:50 +00:00
|
|
|
|
ALLOC_INIT_ZVAL (subarr);
|
|
|
|
|
array_init (subarr);
|
|
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL (subkeys);
|
|
|
|
|
array_init (subkeys);
|
|
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL (userids);
|
|
|
|
|
array_init (userids);
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_assoc_bool (subarr, "disabled", gpgme_key->disabled );
|
|
|
|
|
add_assoc_bool (subarr, "expired", gpgme_key->expired );
|
|
|
|
|
add_assoc_bool (subarr, "revoked", gpgme_key->revoked );
|
|
|
|
|
add_assoc_bool (subarr, "is_secret", gpgme_key->secret );
|
|
|
|
|
add_assoc_bool (subarr, "can_sign", gpgme_key->can_sign );
|
|
|
|
|
add_assoc_bool (subarr, "can_encrypt", gpgme_key->can_encrypt );
|
|
|
|
|
|
|
|
|
|
gpgme_userid = gpgme_key->uids;
|
|
|
|
|
while(gpgme_userid){
|
2005-10-07 18:59:50 +00:00
|
|
|
|
ALLOC_INIT_ZVAL (userid);
|
|
|
|
|
array_init (userid);
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_assoc_string (userid, "name", gpgme_userid->name, 1);
|
|
|
|
|
add_assoc_string (userid, "comment", gpgme_userid->comment, 1);
|
|
|
|
|
add_assoc_string (userid, "email", gpgme_userid->email, 1);
|
|
|
|
|
add_assoc_string (userid, "uid", gpgme_userid->uid, 1);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_assoc_bool (userid, "revoked", gpgme_userid->revoked );
|
|
|
|
|
add_assoc_bool (userid, "invalid", gpgme_userid->invalid );
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
add_next_index_zval (userids, userid);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_userid = gpgme_userid->next;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_assoc_zval (subarr, "uids", userids);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
|
while(gpgme_subkey){
|
2005-10-07 18:59:50 +00:00
|
|
|
|
ALLOC_INIT_ZVAL (subkey);
|
|
|
|
|
array_init (subkey);
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
if(gpgme_subkey->fpr){
|
|
|
|
|
add_assoc_string (subkey, "fingerprint", gpgme_subkey->fpr, 1);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_assoc_string (subkey, "keyid", gpgme_subkey->keyid, 1);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
add_assoc_long (subkey, "timestamp", gpgme_subkey->timestamp );
|
|
|
|
|
add_assoc_long (subkey, "expires", gpgme_subkey->expires );
|
|
|
|
|
add_assoc_bool (subkey, "is_secret", gpgme_subkey->secret );
|
|
|
|
|
add_assoc_bool (subkey, "invalid", gpgme_subkey->invalid );
|
|
|
|
|
add_assoc_bool (subkey, "can_encrypt", gpgme_subkey->can_encrypt );
|
|
|
|
|
add_assoc_bool (subkey, "can_sign", gpgme_subkey->can_sign );
|
|
|
|
|
add_assoc_bool (subkey, "disabled", gpgme_subkey->disabled );
|
|
|
|
|
add_assoc_bool (subkey, "expired", gpgme_subkey->expired );
|
|
|
|
|
add_assoc_bool (subkey, "revoked", gpgme_subkey->revoked );
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
add_next_index_zval (subkeys, subkey);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_assoc_zval (subarr, "subkeys", subkeys);
|
|
|
|
|
|
|
|
|
|
add_next_index_zval (return_value, subarr);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
gpgme_key_unref (gpgme_key);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
/* {{{ proto bool gnupg_addsignkey(string key) */
|
|
|
|
|
PHP_FUNCTION(gnupg_addsignkey){
|
|
|
|
|
char *key_id = NULL;
|
|
|
|
|
int key_id_len;
|
2005-10-24 20:40:55 +00:00
|
|
|
|
char *passphrase = NULL;
|
|
|
|
|
int passphrase_len;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
gpgme_key_t gpgme_key;
|
2005-10-24 20:40:55 +00:00
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
2005-10-24 17:33:59 +00:00
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
2005-10-24 20:40:55 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2005-10-24 20:40:55 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if((intern->err = gpgme_get_key(intern->ctx, key_id, &gpgme_key, 1)) != GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2005-10-24 20:40:55 +00:00
|
|
|
|
if(passphrase){
|
|
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
|
while(gpgme_subkey){
|
|
|
|
|
if(gpgme_subkey->can_sign == 1){
|
|
|
|
|
zend_hash_add(intern->signkeys, (char *) gpgme_subkey->keyid, (uint) strlen(gpgme_subkey->keyid)+1, passphrase, (uint) passphrase_len+1, NULL);
|
|
|
|
|
}
|
|
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if((intern->err = gpgme_signers_add(intern->ctx, gpgme_key))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("could not add signer");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
}else{
|
|
|
|
|
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) */
|
|
|
|
|
PHP_FUNCTION(gnupg_adddecryptkey){
|
|
|
|
|
char *key_id = NULL;
|
|
|
|
|
int key_id_len;
|
|
|
|
|
char *passphrase = NULL;
|
|
|
|
|
int passphrase_len;
|
|
|
|
|
|
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
|
gpgme_subkey_t gpgme_subkey;
|
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_get_key(intern->ctx, key_id, &gpgme_key, 1)) != GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
gpgme_subkey = gpgme_key->subkeys;
|
|
|
|
|
while(gpgme_subkey){
|
|
|
|
|
if(gpgme_subkey->secret == 1){
|
|
|
|
|
zend_hash_add(intern->decryptkeys, (char *) gpgme_subkey->keyid, (uint) strlen(gpgme_subkey->keyid)+1, passphrase, (uint) passphrase_len+1, NULL);
|
|
|
|
|
}
|
|
|
|
|
gpgme_subkey = gpgme_subkey->next;
|
|
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
|
gpgme_key_unref(gpgme_key);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
/* {{{ proto bool gnupg_addencryptkey(string key) */
|
|
|
|
|
PHP_FUNCTION(gnupg_addencryptkey){
|
|
|
|
|
char *key_id = NULL;
|
|
|
|
|
int key_id_len;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
gpgme_key_t gpgme_key = NULL;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if(this){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key_id, &key_id_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &key_id, &key_id_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if((intern->err = gpgme_get_key(intern->ctx, key_id, &gpgme_key, 0)) != GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2006-11-03 12:38:35 +00:00
|
|
|
|
intern->encryptkeys = erealloc(intern->encryptkeys, sizeof(intern->encryptkeys) * (intern->encrypt_size + 2));
|
2005-10-24 17:33:59 +00:00
|
|
|
|
intern->encryptkeys[intern->encrypt_size] = gpgme_key;
|
|
|
|
|
intern->encrypt_size++;
|
|
|
|
|
intern->encryptkeys[intern->encrypt_size] = NULL;
|
|
|
|
|
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
|
|
|
|
|
*/
|
2005-10-24 17:33:59 +00:00
|
|
|
|
PHP_FUNCTION(gnupg_clearsignkeys){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(!this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
|
gpgme_signers_clear (intern->ctx);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
zend_hash_clean(intern->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
|
|
|
|
|
*/
|
2005-10-24 17:33:59 +00:00
|
|
|
|
PHP_FUNCTION(gnupg_clearencryptkeys){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
if(!this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-11-12 18:35:08 +00:00
|
|
|
|
gnupg_free_encryptkeys(intern TSRMLS_CC);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_cleardecryptkeys){
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(!this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zend_hash_clean(intern->decryptkeys);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_sign){
|
|
|
|
|
char *value = NULL;
|
|
|
|
|
int value_len;
|
|
|
|
|
|
|
|
|
|
char *userret;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
size_t ret_size;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +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();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
|
gpgme_set_passphrase_cb (intern->ctx, (void*) passphrase_cb, intern);
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, value, value_len, 0))!=GPG_ERR_NO_ERROR){
|
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-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->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
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_sign(intern->ctx, in, out, intern->signmode))!=GPG_ERR_NO_ERROR){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
if(!intern->errortxt){
|
|
|
|
|
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;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
result = gpgme_op_sign_result (intern->ctx);
|
|
|
|
|
if(result->invalid_signers){
|
|
|
|
|
GNUPG_ERR("invalid signers found");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
if(!result->signatures){
|
|
|
|
|
GNUPG_ERR("no signature in result");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
|
|
|
|
if(ret_size < 1){
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_FALSE;
|
|
|
|
|
}else{
|
|
|
|
|
RETVAL_STRINGL (userret,ret_size,1);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
gpgme_data_release (in);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_encrypt){
|
|
|
|
|
char *value = NULL;
|
|
|
|
|
int value_len;
|
|
|
|
|
char *userret = NULL;
|
2005-10-25 16:28:23 +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;
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if(!intern->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
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, value, value_len, 0))!=GPG_ERR_NO_ERROR){
|
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
|
|
|
|
}
|
|
|
|
|
if((intern->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
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if((intern->err = gpgme_op_encrypt(intern->ctx, intern->encryptkeys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("encrypt failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-24 17:33:59 +00:00
|
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
result = gpgme_op_encrypt_result (intern->ctx);
|
|
|
|
|
if (result->invalid_recipients){
|
|
|
|
|
GNUPG_ERR("Invalid recipient encountered");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
2005-10-24 17:33:59 +00:00
|
|
|
|
gpgme_data_release (in);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_STRINGL (userret,ret_size,1);
|
|
|
|
|
free (userret);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if(ret_size < 1){
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
|
/* {{{ proto string gnupg_encrypt_sign(string text)
|
|
|
|
|
* encrypts and signs the given text with the keys, which weres set with setencryptkey and setsignkey before
|
|
|
|
|
* and returns the encrypted text
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_encryptsign){
|
|
|
|
|
char *value = NULL;
|
|
|
|
|
int value_len;
|
|
|
|
|
char *userret = NULL;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
size_t ret_size;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-09 15:55:02 +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();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if(!intern->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-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
gpgme_set_passphrase_cb (intern->ctx, (void*) passphrase_cb, intern);
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, value, value_len, 0))!=GPG_ERR_NO_ERROR){
|
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-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->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-09 15:55:02 +00:00
|
|
|
|
}
|
2005-10-24 17:33:59 +00:00
|
|
|
|
if((intern->err = gpgme_op_encrypt_sign(intern->ctx, intern->encryptkeys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out))!=GPG_ERR_NO_ERROR){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
if(!intern->errortxt){
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
result = gpgme_op_encrypt_result (intern->ctx);
|
|
|
|
|
if (result->invalid_recipients){
|
|
|
|
|
GNUPG_ERR("Invalid recipient encountered");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
|
sign_result = gpgme_op_sign_result (intern->ctx);
|
2005-10-15 14:42:56 +00:00
|
|
|
|
if(sign_result->invalid_signers){
|
|
|
|
|
GNUPG_ERR("invalid signers found");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
2005-11-03 21:13:28 +00:00
|
|
|
|
if(!sign_result->signatures){
|
|
|
|
|
GNUPG_ERR("could not find a signature");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
gpgme_data_release(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
|
|
|
|
gpgme_data_release (in);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_STRINGL (userret,ret_size,1);
|
|
|
|
|
free (userret);
|
2005-10-10 17:37:19 +00:00
|
|
|
|
if(ret_size < 1){
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_verify){
|
2006-05-18 19:27:52 +00:00
|
|
|
|
gpgme_data_t gpgme_text, gpgme_sig;
|
|
|
|
|
gpgme_verify_result_t gpgme_result;
|
|
|
|
|
zval *signature_array;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2006-05-18 19:27:52 +00:00
|
|
|
|
zval *signed_text = NULL; /* text without the signature, if its a detached one, or the text incl the sig */
|
|
|
|
|
zval *signature = NULL; /* signature, if its a detached one */
|
|
|
|
|
zval *plain_text = NULL; /* signed_text without the signature if its not a detached sig */
|
2005-10-15 14:42:56 +00:00
|
|
|
|
|
2006-05-18 19:27:52 +00:00
|
|
|
|
char *gpg_plain;
|
2010-07-20 19:27:25 +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
|
|
|
|
|
|
|
|
|
if(this){
|
2006-05-18 19:27:52 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &signed_text, &signature, &plain_text) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-10-18 12:40:03 +00:00
|
|
|
|
}else{
|
2006-05-18 19:27:52 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzz|z", &res, &signed_text, &signature, &plain_text) == FAILURE){
|
2005-10-18 12:40:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
|
if(Z_STRVAL_P(signature)){ /* detached signature */
|
|
|
|
|
/* setup signature-databuffer for gpgme */
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&gpgme_sig, Z_STRVAL_P(signature), Z_STRLEN_P(signature), 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("could not create signature-databuffer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* and the text */
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&gpgme_text, Z_STRVAL_P(signed_text), Z_STRLEN_P(signed_text), 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("could not create text-databuffer");
|
|
|
|
|
gpgme_data_release (gpgme_sig);
|
|
|
|
|
gpgme_data_release (gpgme_text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* now verify sig + text */
|
|
|
|
|
if((intern->err = gpgme_op_verify (intern->ctx, gpgme_sig, gpgme_text, NULL))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("verify failed");
|
|
|
|
|
gpgme_data_release (gpgme_sig);
|
|
|
|
|
gpgme_data_release (gpgme_text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{ /* clearsign or normal signature */
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&gpgme_sig, Z_STRVAL_P(signed_text), Z_STRLEN_P(signed_text), 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("could not create signature-databuffer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* set a NULL databuffer for gpgme */
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&gpgme_text, NULL, 0, 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("could not create text-databuffer");
|
|
|
|
|
gpgme_data_release (gpgme_sig);
|
|
|
|
|
gpgme_data_release (gpgme_text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* and verify the 'signature' */
|
|
|
|
|
if((intern->err = gpgme_op_verify (intern->ctx, gpgme_sig, NULL, gpgme_text))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR ("verify failed");
|
|
|
|
|
gpgme_data_release (gpgme_sig);
|
|
|
|
|
gpgme_data_release (gpgme_text);
|
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
2006-05-18 19:27:52 +00:00
|
|
|
|
/* now get the result */
|
|
|
|
|
gpgme_result = gpgme_op_verify_result (intern->ctx);
|
2005-10-25 16:28:23 +00:00
|
|
|
|
if(!gpgme_result->signatures){
|
2006-05-18 19:27:52 +00:00
|
|
|
|
GNUPG_ERR ("no signature found");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
}else{
|
2006-05-18 19:27:52 +00:00
|
|
|
|
/* fetch all signatures in an array */
|
|
|
|
|
gnupg_fetchsignatures (gpgme_result->signatures,signature_array,return_value);
|
|
|
|
|
/* get a 'plain' version of the text without a signature */
|
|
|
|
|
gpg_plain = gpgme_data_release_and_get_mem(gpgme_text,&gpg_plain_len);
|
2006-10-24 14:04:02 +00:00
|
|
|
|
if(gpg_plain && gpg_plain_len > 0 && plain_text){
|
2006-05-18 19:27:52 +00:00
|
|
|
|
ZVAL_STRINGL (plain_text, gpg_plain,gpg_plain_len,1);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_decrypt){
|
2005-10-25 16:28:23 +00:00
|
|
|
|
char *enctxt;
|
|
|
|
|
int enctxt_len;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
char *userret;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
size_t ret_size;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-07 18:59:50 +00:00
|
|
|
|
gpgme_data_t in, out;
|
|
|
|
|
gpgme_decrypt_result_t result;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_set_passphrase_cb (intern->ctx, (void*) passphrase_decrypt_cb, intern);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, enctxt, enctxt_len, 0))!=GPG_ERR_NO_ERROR){
|
2005-10-15 14:42:56 +00:00
|
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-10-07 18:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->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
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_decrypt (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
if(!intern->errortxt){
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
result = gpgme_op_decrypt_result (intern->ctx);
|
2005-10-15 14:42:56 +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;
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
|
|
|
|
gpgme_data_release (in);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_STRINGL (userret,ret_size,1);
|
|
|
|
|
free (userret);
|
2005-10-10 17:37:19 +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
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
|
/* {{{ proto string gnupg_decryptverify(string enctext, string &plaintext)
|
|
|
|
|
* decrypts the given enctext
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_decryptverify){
|
2005-10-25 16:28:23 +00:00
|
|
|
|
char *enctxt;
|
|
|
|
|
int enctxt_len;
|
|
|
|
|
zval *plaintext;
|
|
|
|
|
zval *sig_arr;
|
2005-10-09 15:55:02 +00:00
|
|
|
|
|
|
|
|
|
char *userret;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
size_t ret_size;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-09 15:55:02 +00:00
|
|
|
|
gpgme_data_t in, out;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &enctxt, &enctxt_len, &plaintext) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz", &res, &enctxt, &enctxt_len, &plaintext) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gpgme_set_passphrase_cb (intern->ctx, (void*) passphrase_decrypt_cb, intern);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
|
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, enctxt, enctxt_len, 0))!=GPG_ERR_NO_ERROR){
|
2005-10-15 14:42:56 +00:00
|
|
|
|
GNUPG_ERR("could not create in-data buffer");
|
2005-10-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->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-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_decrypt_verify (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
|
2006-03-16 15:52:43 +00:00
|
|
|
|
if(!intern->errortxt){
|
|
|
|
|
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;
|
2005-10-09 15:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
|
|
|
|
ZVAL_STRINGL (plaintext,userret,ret_size,1);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
free (userret);
|
2005-10-15 14:42:56 +00:00
|
|
|
|
decrypt_result = gpgme_op_decrypt_result (intern->ctx);
|
|
|
|
|
if (decrypt_result->unsupported_algorithm){
|
|
|
|
|
GNUPG_ERR ("unsupported algorithm");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
verify_result = gpgme_op_verify_result (intern->ctx);
|
|
|
|
|
if(!verify_result->signatures){
|
|
|
|
|
GNUPG_ERR ("no signature found");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
gpgme_data_release(in);
|
|
|
|
|
free(out);
|
|
|
|
|
return;
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
2005-10-25 16:28:23 +00:00
|
|
|
|
gnupg_fetchsignatures (verify_result->signatures,sig_arr,return_value);
|
2005-10-09 15:55:02 +00:00
|
|
|
|
gpgme_data_release (in);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_export){
|
|
|
|
|
char *searchkey = NULL;
|
|
|
|
|
int *searchkey_len;
|
|
|
|
|
char *userret;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
size_t ret_size;
|
2005-10-07 18:59:50 +00:00
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &searchkey, &searchkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &searchkey, &searchkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if((intern->err = gpgme_data_new (&out))!=GPG_ERR_NO_ERROR){
|
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
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_export (intern->ctx, searchkey, 0, out))!=GPG_ERR_NO_ERROR){
|
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
|
|
|
|
}
|
|
|
|
|
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_STRINGL (userret,ret_size,1);
|
2005-10-07 18:59:50 +00:00
|
|
|
|
if(ret_size < 1){
|
2005-11-03 21:13:28 +00:00
|
|
|
|
RETVAL_FALSE;
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_import){
|
|
|
|
|
char *importkey = NULL;
|
|
|
|
|
int importkey_len;
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
2005-10-15 14:42:56 +00:00
|
|
|
|
gpgme_data_t in;
|
|
|
|
|
gpgme_import_result_t result;
|
|
|
|
|
|
2005-10-18 12:40:03 +00:00
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &importkey, &importkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &importkey, &importkey_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
if((intern->err = gpgme_data_new_from_mem (&in, importkey, importkey_len, 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_import(intern->ctx,in))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
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);
|
|
|
|
|
result = gpgme_op_import_result (intern->ctx);
|
|
|
|
|
|
|
|
|
|
array_init (return_value);
|
|
|
|
|
add_assoc_long (return_value, "imported", result->imported);
|
|
|
|
|
add_assoc_long (return_value, "unchanged", result->unchanged);
|
|
|
|
|
add_assoc_long (return_value, "newuserids", result->new_user_ids);
|
|
|
|
|
add_assoc_long (return_value, "newsubkeys", result->new_sub_keys);
|
|
|
|
|
add_assoc_long (return_value, "secretimported", result->secret_imported);
|
|
|
|
|
add_assoc_long (return_value, "secretunchanged", result->secret_unchanged);
|
|
|
|
|
add_assoc_long (return_value, "newsignatures", result->new_signatures);
|
|
|
|
|
add_assoc_long (return_value, "skippedkeys", result->skipped_new_keys);
|
2005-11-25 14:31:36 +00:00
|
|
|
|
if(result->imports && result->imports->fpr){
|
|
|
|
|
add_assoc_string (return_value, "fingerprint", result->imports->fpr, 1);
|
|
|
|
|
}
|
2005-10-15 14:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
|
|
/* {{{ proto book gnupg_deletekey(string key)
|
|
|
|
|
* deletes a key from the keyring
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_deletekey){
|
|
|
|
|
char *key;
|
|
|
|
|
int key_len;
|
2010-07-20 19:05:22 +00:00
|
|
|
|
long allow_secret = 0;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &key_len, &allow_secret) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2006-11-03 12:38:35 +00:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &key, &key_len, &allow_secret) == FAILURE){
|
2005-10-25 16:28:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((intern->err = gpgme_get_key(intern->ctx, key, &gpgme_key, 0)) != GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("get_key failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_delete(intern->ctx,gpgme_key,allow_secret))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("delete failed");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
RETVAL_FALSE;
|
|
|
|
|
}else{
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(gnupg_gettrustlist){
|
|
|
|
|
char *pattern;
|
|
|
|
|
int pattern_len;
|
|
|
|
|
zval *sub_arr;
|
|
|
|
|
|
|
|
|
|
gpgme_trust_item_t item;
|
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pattern, &pattern_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &pattern, &pattern_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_op_trustlist_start (intern->ctx, pattern, 0))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("could not start trustlist");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
while (!(intern->err = gpgme_op_trustlist_next (intern->ctx, &item))){
|
|
|
|
|
ALLOC_INIT_ZVAL (sub_arr);
|
|
|
|
|
array_init (sub_arr);
|
|
|
|
|
|
|
|
|
|
add_assoc_long (sub_arr, "level", item->level );
|
|
|
|
|
add_assoc_long (sub_arr, "type", item->type );
|
|
|
|
|
add_assoc_string (sub_arr, "keyid", item->keyid, 1);
|
|
|
|
|
add_assoc_string (sub_arr, "ownertrust", item->owner_trust, 1);
|
|
|
|
|
add_assoc_string (sub_arr, "validity", item->validity, 1);
|
|
|
|
|
add_assoc_string (sub_arr, "name", item->name, 1);
|
|
|
|
|
gpgme_trust_item_unref (item);
|
|
|
|
|
add_next_index_zval (return_value, sub_arr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto array gnupg_listsignatures(string keyid) */
|
|
|
|
|
PHP_FUNCTION(gnupg_listsignatures){
|
|
|
|
|
char *keyid;
|
2012-05-06 07:43:30 +00:00
|
|
|
|
int keyid_len;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
|
|
|
|
|
zval *sub_arr;
|
|
|
|
|
zval *sig_arr;
|
|
|
|
|
|
|
|
|
|
gpgme_key_t gpgme_key;
|
|
|
|
|
gpgme_user_id_t gpgme_userid;
|
|
|
|
|
gpgme_key_sig_t gpgme_signature;
|
|
|
|
|
|
|
|
|
|
GNUPG_GETOBJ();
|
|
|
|
|
|
|
|
|
|
if(this){
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &keyid, &keyid_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &keyid, &keyid_len) == FAILURE){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ZEND_FETCH_RESOURCE(intern,gnupg_object *, &res, -1, "ctx", le_gnupg);
|
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_set_keylist_mode(intern->ctx,GPGME_KEYLIST_MODE_SIGS))!=GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("could not switch to sigmode");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
if((intern->err = gpgme_get_key(intern->ctx, keyid, &gpgme_key, 0)) != GPG_ERR_NO_ERROR){
|
|
|
|
|
GNUPG_ERR("get_key failed. given key not unique?");
|
2005-11-10 20:24:27 +00:00
|
|
|
|
return;
|
2005-10-25 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
if(!gpgme_key->uids){
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
gpgme_userid = gpgme_key->uids;
|
|
|
|
|
while(gpgme_userid){
|
|
|
|
|
ALLOC_INIT_ZVAL (sub_arr);
|
|
|
|
|
array_init (sub_arr);
|
|
|
|
|
gpgme_signature = gpgme_userid->signatures;
|
|
|
|
|
while(gpgme_signature){
|
|
|
|
|
ALLOC_INIT_ZVAL (sig_arr);
|
|
|
|
|
array_init (sig_arr);
|
|
|
|
|
|
|
|
|
|
add_assoc_string (sig_arr, "uid", gpgme_signature->uid, 1);
|
|
|
|
|
add_assoc_string (sig_arr, "name", gpgme_signature->name, 1);
|
|
|
|
|
add_assoc_string (sig_arr, "email", gpgme_signature->email, 1);
|
|
|
|
|
add_assoc_string (sig_arr, "comment", gpgme_signature->comment, 1);
|
|
|
|
|
add_assoc_long (sig_arr, "expires", gpgme_signature->expires );
|
|
|
|
|
add_assoc_bool (sig_arr, "revoked", gpgme_signature->revoked );
|
|
|
|
|
add_assoc_bool (sig_arr, "expired", gpgme_signature->expired );
|
|
|
|
|
add_assoc_bool (sig_arr, "invalid", gpgme_signature->invalid );
|
|
|
|
|
add_assoc_zval (sub_arr,gpgme_signature->keyid,sig_arr);
|
|
|
|
|
gpgme_signature = gpgme_signature->next;
|
|
|
|
|
}
|
|
|
|
|
add_assoc_zval (return_value,gpgme_userid->uid,sub_arr);
|
|
|
|
|
gpgme_userid = gpgme_userid->next;
|
|
|
|
|
}
|
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
|
|
|
|
|
*/
|