aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar thinkerou <thinkerou@gmail.com>2016-06-09 11:57:15 +0800
committerGravatar thinkerou <thinkerou@gmail.com>2016-06-17 09:41:04 +0800
commitf3bc3b62a776c34b916c7771177629b4620dbfec (patch)
tree5361402c84a202dafb831d65ccd8aef1eeea4789
parentfa9b7c1bc6488be17d18007f45c57dac39ea5b79 (diff)
Load default roots.pem in PHP via grpc_set_ssl_roots_override_callback
-rw-r--r--src/php/ext/grpc/channel_credentials.c33
-rwxr-xr-xsrc/php/lib/Grpc/BaseStub.php4
-rwxr-xr-xtools/dockerfile/interoptest/grpc_interop_php/build_interop.sh2
3 files changed, 37 insertions, 2 deletions
diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c
index 5c537378a6..b76fb105f3 100644
--- a/src/php/ext/grpc/channel_credentials.c
+++ b/src/php/ext/grpc/channel_credentials.c
@@ -47,11 +47,23 @@
#include <zend_exceptions.h>
#include <zend_hash.h>
+#include <grpc/support/alloc.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
zend_class_entry *grpc_ce_channel_credentials;
+static char *default_pem_root_certs = NULL;
+
+static grpc_ssl_roots_override_result get_ssl_roots_override(
+ char **pem_root_certs) {
+ *pem_root_certs = default_pem_root_certs;
+ if (default_pem_root_certs == NULL) {
+ return GRPC_SSL_ROOTS_OVERRIDE_FAIL;
+ }
+ return GRPC_SSL_ROOTS_OVERRIDE_OK;
+}
+
/* Frees and destroys an instance of wrapped_grpc_channel_credentials */
void free_wrapped_grpc_channel_credentials(void *object TSRMLS_DC) {
wrapped_grpc_channel_credentials *creds =
@@ -94,6 +106,24 @@ zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped TSRMLS
}
/**
+ * Set default roots pem.
+ * @param string pem_roots PEM encoding of the server root certificates
+ * @return void
+ */
+PHP_METHOD(ChannelCredentials, setDefaultRootsPem) {
+ char *pem_roots;
+ int pem_roots_length;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pem_roots,
+ &pem_roots_length) == FAILURE) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "setDefaultRootsPem expects 1 string", 1 TSRMLS_CC);
+ return;
+ }
+ default_pem_root_certs = gpr_malloc((pem_roots_length + 1) * sizeof(char));
+ memcpy(default_pem_root_certs, pem_roots, pem_roots_length + 1);
+}
+
+/**
* Create a default channel credentials object.
* @return ChannelCredentials The new default channel credentials object
*/
@@ -178,6 +208,8 @@ PHP_METHOD(ChannelCredentials, createInsecure) {
}
static zend_function_entry channel_credentials_methods[] = {
+ PHP_ME(ChannelCredentials, setDefaultRootsPem, NULL,
+ ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ChannelCredentials, createDefault, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ChannelCredentials, createSsl, NULL,
@@ -192,6 +224,7 @@ void grpc_init_channel_credentials(TSRMLS_D) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Grpc\\ChannelCredentials",
channel_credentials_methods);
+ grpc_set_ssl_roots_override_callback(get_ssl_roots_override);
ce.create_object = create_wrapped_grpc_channel_credentials;
grpc_ce_channel_credentials = zend_register_internal_class(&ce TSRMLS_CC);
}
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index 70644fac87..df3fe85d44 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -56,6 +56,10 @@ class BaseStub
*/
public function __construct($hostname, $opts, $channel = null)
{
+ $ssl_roots = file_get_contents(
+ dirname(__FILE__).'/../../../../etc/roots.pem');
+ ChannelCredentials::setDefaultRootsPem($ssl_roots);
+
$this->hostname = $hostname;
$this->update_metadata = null;
if (isset($opts['update_metadata'])) {
diff --git a/tools/dockerfile/interoptest/grpc_interop_php/build_interop.sh b/tools/dockerfile/interoptest/grpc_interop_php/build_interop.sh
index 87262f1d62..a84a450221 100755
--- a/tools/dockerfile/interoptest/grpc_interop_php/build_interop.sh
+++ b/tools/dockerfile/interoptest/grpc_interop_php/build_interop.sh
@@ -40,8 +40,6 @@ cp -r /var/local/jenkins/service_account $HOME || true
cd /var/local/git/grpc
rvm --default use ruby-2.1
-make install-certs
-
# gRPC core and protobuf need to be installed
make install