Merge pull request #4 from stanley-cheung/php_creds_api_change

PHP: Core credentials API refactoring
reviewable/pr3765/r1
jboeuf 9 years ago
commit f3d051a409
  1. 138
      src/php/ext/grpc/call_credentials.c
  2. 24
      src/php/ext/grpc/call_credentials.h
  3. 18
      src/php/ext/grpc/channel.c
  4. 132
      src/php/ext/grpc/channel_credentials.c
  5. 63
      src/php/ext/grpc/channel_credentials.h
  6. 4
      src/php/ext/grpc/config.m4
  7. 18
      src/php/ext/grpc/package.xml
  8. 6
      src/php/ext/grpc/php_grpc.c
  9. 7
      src/php/tests/interop/interop_client.php
  10. 4
      src/php/tests/unit_tests/SecureEndToEndTest.php

@ -0,0 +1,138 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "channel_credentials.h"
#include "call_credentials.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <php.h>
#include <php_ini.h>
#include <ext/standard/info.h>
#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
#include <zend_exceptions.h>
#include <zend_hash.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
zend_class_entry *grpc_ce_call_credentials;
/* Frees and destroys an instance of wrapped_grpc_call_credentials */
void free_wrapped_grpc_call_credentials(void *object TSRMLS_DC) {
wrapped_grpc_call_credentials *creds =
(wrapped_grpc_call_credentials *)object;
if (creds->wrapped != NULL) {
grpc_call_credentials_release(creds->wrapped);
}
efree(creds);
}
/* Initializes an instance of wrapped_grpc_call_credentials to be
* associated with an object of a class specified by class_type */
zend_object_value create_wrapped_grpc_call_credentials(
zend_class_entry *class_type TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_call_credentials *intern;
intern = (wrapped_grpc_call_credentials *)emalloc(
sizeof(wrapped_grpc_call_credentials));
memset(intern, 0, sizeof(wrapped_grpc_call_credentials));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_call_credentials, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
zval *grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped) {
zval *credentials_object;
MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_call_credentials);
wrapped_grpc_call_credentials *credentials =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
credentials_object TSRMLS_CC);
credentials->wrapped = wrapped;
return credentials_object;
}
/**
* Create composite credentials from two existing credentials.
* @param CallCredentials cred1 The first credential
* @param CallCredentials cred2 The second credential
* @return CallCredentials The new composite credentials object
*/
PHP_METHOD(CallCredentials, createComposite) {
zval *cred1_obj;
zval *cred2_obj;
/* "OO" == 3 Objects */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &cred1_obj,
grpc_ce_call_credentials, &cred2_obj,
grpc_ce_call_credentials) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createComposite expects 2 CallCredentials",
1 TSRMLS_CC);
return;
}
wrapped_grpc_call_credentials *cred1 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred1_obj TSRMLS_CC);
wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred2_obj TSRMLS_CC);
grpc_call_credentials *creds =
grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped,
NULL);
zval *creds_object = grpc_php_wrap_call_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object);
}
static zend_function_entry call_credentials_methods[] = {
PHP_ME(CallCredentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};
void grpc_init_call_credentials(TSRMLS_D) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Grpc\\CallCredentials", call_credentials_methods);
ce.create_object = create_wrapped_grpc_call_credentials;
grpc_ce_call_credentials = zend_register_internal_class(&ce TSRMLS_CC);
}

@ -31,8 +31,8 @@
* *
*/ */
#ifndef NET_GRPC_PHP_GRPC_CREDENTIALS_H_ #ifndef NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_
#define NET_GRPC_PHP_GRPC_CREDENTIALS_H_ #define NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -46,18 +46,18 @@
#include "grpc/grpc.h" #include "grpc/grpc.h"
#include "grpc/grpc_security.h" #include "grpc/grpc_security.h"
/* Class entry for the Credentials PHP class */ /* Class entry for the CallCredentials PHP class */
extern zend_class_entry *grpc_ce_credentials; extern zend_class_entry *grpc_ce_call_credentials;
/* Wrapper struct for grpc_credentials that can be associated with a PHP /* Wrapper struct for grpc_call_credentials that can be associated
* object */ * with a PHP object */
typedef struct wrapped_grpc_credentials { typedef struct wrapped_grpc_call_credentials {
zend_object std; zend_object std;
grpc_credentials *wrapped; grpc_call_credentials *wrapped;
} wrapped_grpc_credentials; } wrapped_grpc_call_credentials;
/* Initializes the Credentials PHP class */ /* Initializes the CallCredentials PHP class */
void grpc_init_credentials(TSRMLS_D); void grpc_init_call_credentials(TSRMLS_D);
#endif /* NET_GRPC_PHP_GRPC_CREDENTIALS_H_ */ #endif /* NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_ */

@ -52,7 +52,7 @@
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
#include "completion_queue.h" #include "completion_queue.h"
#include "credentials.h" #include "channel_credentials.h"
#include "server.h" #include "server.h"
#include "timeval.h" #include "timeval.h"
@ -125,21 +125,22 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
/** /**
* Construct an instance of the Channel class. If the $args array contains a * Construct an instance of the Channel class. If the $args array contains a
* "credentials" key mapping to a Credentials object, a secure channel will be * "credentials" key mapping to a ChannelCredentials object, a secure channel
* created with those credentials. * will be created with those credentials.
* @param string $target The hostname to associate with this channel * @param string $target The hostname to associate with this channel
* @param array $args The arguments to pass to the Channel (optional) * @param array $args The arguments to pass to the Channel (optional)
*/ */
PHP_METHOD(Channel, __construct) { PHP_METHOD(Channel, __construct) {
wrapped_grpc_channel *channel = wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC); (wrapped_grpc_channel *)zend_object_store_get_object(
getThis() TSRMLS_CC);
char *target; char *target;
int target_length; int target_length;
zval *args_array = NULL; zval *args_array = NULL;
grpc_channel_args args; grpc_channel_args args;
HashTable *array_hash; HashTable *array_hash;
zval **creds_obj = NULL; zval **creds_obj = NULL;
wrapped_grpc_credentials *creds = NULL; wrapped_grpc_channel_credentials *creds = NULL;
/* "s|a" == 1 string, 1 optional array */ /* "s|a" == 1 string, 1 optional array */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &target, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &target,
&target_length, &args_array) == FAILURE) { &target_length, &args_array) == FAILURE) {
@ -153,13 +154,14 @@ PHP_METHOD(Channel, __construct) {
array_hash = Z_ARRVAL_P(args_array); array_hash = Z_ARRVAL_P(args_array);
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"), if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
(void **)&creds_obj) == SUCCESS) { (void **)&creds_obj) == SUCCESS) {
if (zend_get_class_entry(*creds_obj TSRMLS_CC) != grpc_ce_credentials) { if (zend_get_class_entry(*creds_obj TSRMLS_CC) !=
grpc_ce_channel_credentials) {
zend_throw_exception(spl_ce_InvalidArgumentException, zend_throw_exception(spl_ce_InvalidArgumentException,
"credentials must be a Credentials object", "credentials must be a ChannelCredentials object",
1 TSRMLS_CC); 1 TSRMLS_CC);
return; return;
} }
creds = (wrapped_grpc_credentials *)zend_object_store_get_object( creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object(
*creds_obj TSRMLS_CC); *creds_obj TSRMLS_CC);
zend_hash_del(array_hash, "credentials", 12); zend_hash_del(array_hash, "credentials", 12);
} }

@ -31,7 +31,8 @@
* *
*/ */
#include "credentials.h" #include "channel_credentials.h"
#include "call_credentials.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -49,55 +50,56 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
zend_class_entry *grpc_ce_credentials; zend_class_entry *grpc_ce_channel_credentials;
/* Frees and destroys an instance of wrapped_grpc_credentials */ /* Frees and destroys an instance of wrapped_grpc_channel_credentials */
void free_wrapped_grpc_credentials(void *object TSRMLS_DC) { void free_wrapped_grpc_channel_credentials(void *object TSRMLS_DC) {
wrapped_grpc_credentials *creds = (wrapped_grpc_credentials *)object; wrapped_grpc_channel_credentials *creds =
(wrapped_grpc_channel_credentials *)object;
if (creds->wrapped != NULL) { if (creds->wrapped != NULL) {
grpc_credentials_release(creds->wrapped); grpc_channel_credentials_release(creds->wrapped);
} }
efree(creds); efree(creds);
} }
/* Initializes an instance of wrapped_grpc_credentials to be associated with an /* Initializes an instance of wrapped_grpc_channel_credentials to be
* object of a class specified by class_type */ * associated with an object of a class specified by class_type */
zend_object_value create_wrapped_grpc_credentials(zend_class_entry *class_type zend_object_value create_wrapped_grpc_channel_credentials(
TSRMLS_DC) { zend_class_entry *class_type TSRMLS_DC) {
zend_object_value retval; zend_object_value retval;
wrapped_grpc_credentials *intern; wrapped_grpc_channel_credentials *intern;
intern = intern = (wrapped_grpc_channel_credentials *)emalloc(
(wrapped_grpc_credentials *)emalloc(sizeof(wrapped_grpc_credentials)); sizeof(wrapped_grpc_channel_credentials));
memset(intern, 0, sizeof(wrapped_grpc_credentials)); memset(intern, 0, sizeof(wrapped_grpc_channel_credentials));
zend_object_std_init(&intern->std, class_type TSRMLS_CC); zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type); object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put( retval.handle = zend_objects_store_put(
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_credentials, NULL TSRMLS_CC); free_wrapped_grpc_channel_credentials, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers(); retval.handlers = zend_get_std_object_handlers();
return retval; return retval;
} }
zval *grpc_php_wrap_credentials(grpc_credentials *wrapped) { zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped) {
zval *credentials_object; zval *credentials_object;
MAKE_STD_ZVAL(credentials_object); MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_credentials); object_init_ex(credentials_object, grpc_ce_channel_credentials);
wrapped_grpc_credentials *credentials = wrapped_grpc_channel_credentials *credentials =
(wrapped_grpc_credentials *)zend_object_store_get_object( (wrapped_grpc_channel_credentials *)zend_object_store_get_object(
credentials_object TSRMLS_CC); credentials_object TSRMLS_CC);
credentials->wrapped = wrapped; credentials->wrapped = wrapped;
return credentials_object; return credentials_object;
} }
/** /**
* Create a default credentials object. * Create a default channel credentials object.
* @return Credentials The new default credentials object * @return ChannelCredentials The new default channel credentials object
*/ */
PHP_METHOD(Credentials, createDefault) { PHP_METHOD(ChannelCredentials, createDefault) {
grpc_credentials *creds = grpc_google_default_credentials_create(); grpc_channel_credentials *creds = grpc_google_default_credentials_create();
zval *creds_object = grpc_php_wrap_credentials(creds); zval *creds_object = grpc_php_wrap_channel_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object); RETURN_DESTROY_ZVAL(creds_object);
} }
@ -108,84 +110,78 @@ PHP_METHOD(Credentials, createDefault) {
* (optional) * (optional)
* @param string pem_cert_chain PEM encoding of the client's certificate chain * @param string pem_cert_chain PEM encoding of the client's certificate chain
* (optional) * (optional)
* @return Credentials The new SSL credentials object * @return ChannelCredentials The new SSL credentials object
*/ */
PHP_METHOD(Credentials, createSsl) { PHP_METHOD(ChannelCredentials, createSsl) {
char *pem_root_certs; char *pem_root_certs = NULL;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair; grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
int root_certs_length, private_key_length = 0, cert_chain_length = 0; int root_certs_length = 0, private_key_length = 0, cert_chain_length = 0;
pem_key_cert_pair.private_key = pem_key_cert_pair.cert_chain = NULL; pem_key_cert_pair.private_key = pem_key_cert_pair.cert_chain = NULL;
/* "s|s!s! == 1 string, 2 optional nullable strings */ /* "|s!s!s! == 3 optional nullable strings */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!", if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!",
&pem_root_certs, &root_certs_length, &pem_root_certs, &root_certs_length,
&pem_key_cert_pair.private_key, &private_key_length, &pem_key_cert_pair.private_key,
&private_key_length,
&pem_key_cert_pair.cert_chain, &pem_key_cert_pair.cert_chain,
&cert_chain_length) == FAILURE) { &cert_chain_length) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException, zend_throw_exception(spl_ce_InvalidArgumentException,
"createSsl expects 1 to 3 strings", 1 TSRMLS_CC); "createSsl expects 3 optional strings", 1 TSRMLS_CC);
return; return;
} }
grpc_credentials *creds = grpc_ssl_credentials_create( grpc_channel_credentials *creds = grpc_ssl_credentials_create(
pem_root_certs, pem_root_certs,
pem_key_cert_pair.private_key == NULL ? NULL : &pem_key_cert_pair, NULL); pem_key_cert_pair.private_key == NULL ? NULL : &pem_key_cert_pair, NULL);
zval *creds_object = grpc_php_wrap_credentials(creds); zval *creds_object = grpc_php_wrap_channel_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object); RETURN_DESTROY_ZVAL(creds_object);
} }
/** /**
* Create composite credentials from two existing credentials. * Create composite credentials from two existing credentials.
* @param Credentials cred1 The first credential * @param ChannelCredentials cred1 The first credential
* @param Credentials cred2 The second credential * @param CallCredentials cred2 The second credential
* @return Credentials The new composite credentials object * @return ChannelCredentials The new composite credentials object
*/ */
PHP_METHOD(Credentials, createComposite) { PHP_METHOD(ChannelCredentials, createComposite) {
zval *cred1_obj; zval *cred1_obj;
zval *cred2_obj; zval *cred2_obj;
/* "OO" == 3 Objects */ /* "OO" == 3 Objects */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &cred1_obj, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &cred1_obj,
grpc_ce_credentials, &cred2_obj, grpc_ce_channel_credentials, &cred2_obj,
grpc_ce_credentials) == FAILURE) { grpc_ce_call_credentials) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException, zend_throw_exception(spl_ce_InvalidArgumentException,
"createComposite expects 2 Credentials", 1 TSRMLS_CC); "createComposite expects 2 Credentials", 1 TSRMLS_CC);
return; return;
} }
wrapped_grpc_credentials *cred1 = wrapped_grpc_channel_credentials *cred1 =
(wrapped_grpc_credentials *)zend_object_store_get_object( (wrapped_grpc_channel_credentials *)zend_object_store_get_object(
cred1_obj TSRMLS_CC); cred1_obj TSRMLS_CC);
wrapped_grpc_credentials *cred2 = wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_credentials *)zend_object_store_get_object( (wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred2_obj TSRMLS_CC); cred2_obj TSRMLS_CC);
grpc_credentials *creds = grpc_channel_credentials *creds =
grpc_composite_credentials_create(cred1->wrapped, cred2->wrapped, NULL); grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped,
zval *creds_object = grpc_php_wrap_credentials(creds); NULL);
zval *creds_object = grpc_php_wrap_channel_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object); RETURN_DESTROY_ZVAL(creds_object);
} }
/** static zend_function_entry channel_credentials_methods[] = {
* Create Google Compute Engine credentials PHP_ME(ChannelCredentials, createDefault, NULL,
* @return Credentials The new GCE credentials object ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
*/ PHP_ME(ChannelCredentials, createSsl, NULL,
PHP_METHOD(Credentials, createGce) { ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
grpc_credentials *creds = grpc_google_compute_engine_credentials_create(NULL); PHP_ME(ChannelCredentials, createComposite, NULL,
zval *creds_object = grpc_php_wrap_credentials(creds); ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
RETURN_DESTROY_ZVAL(creds_object); PHP_FE_END};
}
static zend_function_entry credentials_methods[] = {
PHP_ME(Credentials, createDefault, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createSsl, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createGce, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};
void grpc_init_credentials(TSRMLS_D) { void grpc_init_channel_credentials(TSRMLS_D) {
zend_class_entry ce; zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Grpc\\Credentials", credentials_methods); INIT_CLASS_ENTRY(ce, "Grpc\\ChannelCredentials",
ce.create_object = create_wrapped_grpc_credentials; channel_credentials_methods);
grpc_ce_credentials = zend_register_internal_class(&ce TSRMLS_CC); ce.create_object = create_wrapped_grpc_channel_credentials;
grpc_ce_channel_credentials = zend_register_internal_class(&ce TSRMLS_CC);
} }

@ -0,0 +1,63 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef NET_GRPC_PHP_GRPC_CHANNEL_CREDENTIALS_H_
#define NET_GRPC_PHP_GRPC_CHANNEL_CREDENTIALS_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_grpc.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
/* Class entry for the ChannelCredentials PHP class */
extern zend_class_entry *grpc_ce_channel_credentials;
/* Wrapper struct for grpc_channel_credentials that can be associated
* with a PHP object */
typedef struct wrapped_grpc_channel_credentials {
zend_object std;
grpc_channel_credentials *wrapped;
} wrapped_grpc_channel_credentials;
/* Initializes the ChannelCredentials PHP class */
void grpc_init_channel_credentials(TSRMLS_D);
#endif /* NET_GRPC_PHP_GRPC_CHANNEL_CREDENTIALS_H_ */

@ -71,5 +71,7 @@ if test "$PHP_GRPC" != "no"; then
PHP_SUBST(GRPC_SHARED_LIBADD) PHP_SUBST(GRPC_SHARED_LIBADD)
PHP_NEW_EXTENSION(grpc, byte_buffer.c call.c channel.c completion_queue.c credentials.c timeval.c server.c server_credentials.c php_grpc.c, $ext_shared, , -Wall -Werror -std=c11) PHP_NEW_EXTENSION(grpc, byte_buffer.c call.c call_credentials.c channel.c \
channel_credentials.c completion_queue.c timeval.c server.c \
server_credentials.c php_grpc.c, $ext_shared, , -Wall -Werror -std=c11)
fi fi

@ -10,8 +10,8 @@
<email>grpc-packages@google.com</email> <email>grpc-packages@google.com</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2015-10-07</date> <date>2015-10-21</date>
<time>13:40:54</time> <time>17:04:32</time>
<version> <version>
<release>0.6.1</release> <release>0.6.1</release>
<api>0.6.0</api> <api>0.6.0</api>
@ -30,16 +30,18 @@
<file baseinstalldir="/" md5sum="c8de0f819499c48adfc8d7f472c0196b" name="byte_buffer.h" role="src" /> <file baseinstalldir="/" md5sum="c8de0f819499c48adfc8d7f472c0196b" name="byte_buffer.h" role="src" />
<file baseinstalldir="/" md5sum="d64c9005993de02abac55664b0b9e0b2" name="call.c" role="src" /> <file baseinstalldir="/" md5sum="d64c9005993de02abac55664b0b9e0b2" name="call.c" role="src" />
<file baseinstalldir="/" md5sum="26acbf04c30162c2d2aca4688bb2aec8" name="call.h" role="src" /> <file baseinstalldir="/" md5sum="26acbf04c30162c2d2aca4688bb2aec8" name="call.h" role="src" />
<file baseinstalldir="/" md5sum="15e56239b32c803f073e8a2b9f96e8c3" name="channel.c" role="src" /> <file baseinstalldir="/" md5sum="6fa13d260dfde216f795225644f04e7a" name="call_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="e45269975f9a30fd349a90daf6b31aa2" name="call_credentials.h" role="src" />
<file baseinstalldir="/" md5sum="0779db3b196c98081b2260ceec22cd4d" name="channel.c" role="src" />
<file baseinstalldir="/" md5sum="ed4b00c0cf3702b115d0cfa87450dc09" name="channel.h" role="src" /> <file baseinstalldir="/" md5sum="ed4b00c0cf3702b115d0cfa87450dc09" name="channel.h" role="src" />
<file baseinstalldir="/" md5sum="1b40f50fa6184ad7d24a961ac76151ff" name="channel_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="a86250e03f610ce6c2c7595a84e08821" name="channel_credentials.h" role="src" />
<file baseinstalldir="/" md5sum="55ab7a42f9dd9bfc7e28a61cfc5fca63" name="completion_queue.c" role="src" /> <file baseinstalldir="/" md5sum="55ab7a42f9dd9bfc7e28a61cfc5fca63" name="completion_queue.c" role="src" />
<file baseinstalldir="/" md5sum="f10b5bb232d74a6878e829e2e76cdaa2" name="completion_queue.h" role="src" /> <file baseinstalldir="/" md5sum="f10b5bb232d74a6878e829e2e76cdaa2" name="completion_queue.h" role="src" />
<file baseinstalldir="/" md5sum="a22f8eac0164761058cc4d9eb2ceb069" name="config.m4" role="src" /> <file baseinstalldir="/" md5sum="c7bba7f0f00d1b1483de457d55311382" name="config.m4" role="src" />
<file baseinstalldir="/" md5sum="588752c908f7bc1663f7b8fc922ae661" name="credentials.c" role="src" />
<file baseinstalldir="/" md5sum="6988d6e97c19c8f8e3eb92371cf8246b" name="credentials.h" role="src" />
<file baseinstalldir="/" md5sum="38a1bc979d810c36ebc2a52d4b7b5319" name="CREDITS" role="doc" /> <file baseinstalldir="/" md5sum="38a1bc979d810c36ebc2a52d4b7b5319" name="CREDITS" role="doc" />
<file baseinstalldir="/" md5sum="3f35b472bbdef5a788cd90617d7d0847" name="LICENSE" role="doc" /> <file baseinstalldir="/" md5sum="3f35b472bbdef5a788cd90617d7d0847" name="LICENSE" role="doc" />
<file baseinstalldir="/" md5sum="b77f1f3941aaf7a21090b493e9f26037" name="php_grpc.c" role="src" /> <file baseinstalldir="/" md5sum="3131a8af38fe5918e5409016b89d6cdb" name="php_grpc.c" role="src" />
<file baseinstalldir="/" md5sum="673b07859d9f69232f8a754c56780686" name="php_grpc.h" role="src" /> <file baseinstalldir="/" md5sum="673b07859d9f69232f8a754c56780686" name="php_grpc.h" role="src" />
<file baseinstalldir="/" md5sum="7533a6d3ea02c78cad23a9651de0825d" name="README.md" role="doc" /> <file baseinstalldir="/" md5sum="7533a6d3ea02c78cad23a9651de0825d" name="README.md" role="doc" />
<file baseinstalldir="/" md5sum="3e4e960454ebb2fc7b78a840493f5315" name="server.c" role="src" /> <file baseinstalldir="/" md5sum="3e4e960454ebb2fc7b78a840493f5315" name="server.c" role="src" />
@ -122,7 +124,7 @@ Update to wrap gRPC C Core version 0.10.0
<release>beta</release> <release>beta</release>
<api>beta</api> <api>beta</api>
</stability> </stability>
<date>2015-10-07</date> <date>2015-10-21</date>
<license>BSD</license> <license>BSD</license>
<notes> <notes>
- fixed undefined constant fatal error when run with apache/nginx #2275 - fixed undefined constant fatal error when run with apache/nginx #2275

@ -35,7 +35,8 @@
#include "channel.h" #include "channel.h"
#include "server.h" #include "server.h"
#include "timeval.h" #include "timeval.h"
#include "credentials.h" #include "channel_credentials.h"
#include "call_credentials.h"
#include "server_credentials.h" #include "server_credentials.h"
#include "completion_queue.h" #include "completion_queue.h"
@ -233,7 +234,8 @@ PHP_MINIT_FUNCTION(grpc) {
grpc_init_channel(TSRMLS_C); grpc_init_channel(TSRMLS_C);
grpc_init_server(TSRMLS_C); grpc_init_server(TSRMLS_C);
grpc_init_timeval(TSRMLS_C); grpc_init_timeval(TSRMLS_C);
grpc_init_credentials(TSRMLS_C); grpc_init_channel_credentials(TSRMLS_C);
grpc_init_call_credentials(TSRMLS_C);
grpc_init_server_credentials(TSRMLS_C); grpc_init_server_credentials(TSRMLS_C);
grpc_php_init_completion_queue(TSRMLS_C); grpc_php_init_completion_queue(TSRMLS_C);
return SUCCESS; return SUCCESS;

@ -392,12 +392,11 @@ $opts = [];
if ($use_tls) { if ($use_tls) {
if ($use_test_ca) { if ($use_test_ca) {
$ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem'; $ssl_credentials = Grpc\Credentials::createSsl(
file_get_contents(dirname(__FILE__) . '/../data/ca.pem'));
} else { } else {
$ssl_cert_file = getenv('SSL_CERT_FILE'); $ssl_credentials = Grpc\Credentials::createSsl();
} }
$ssl_credentials = Grpc\Credentials::createSsl(
file_get_contents($ssl_cert_file));
$opts['credentials'] = $ssl_credentials; $opts['credentials'] = $ssl_credentials;
$opts['grpc.ssl_target_name_override'] = $host_override; $opts['grpc.ssl_target_name_override'] = $host_override;
} }

@ -33,7 +33,7 @@
*/ */
class SecureEndToEndTest extends PHPUnit_Framework_TestCase{ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() { public function setUp() {
$credentials = Grpc\Credentials::createSsl( $channel_credentials = Grpc\ChannelCredentials::createSsl(
file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); file_get_contents(dirname(__FILE__) . '/../data/ca.pem'));
$server_credentials = Grpc\ServerCredentials::createSsl( $server_credentials = Grpc\ServerCredentials::createSsl(
null, null,
@ -49,7 +49,7 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
[ [
'grpc.ssl_target_name_override' => $this->host_override, 'grpc.ssl_target_name_override' => $this->host_override,
'grpc.default_authority' => $this->host_override, 'grpc.default_authority' => $this->host_override,
'credentials' => $credentials 'credentials' => $channel_credentials
]); ]);
} }

Loading…
Cancel
Save