26 #include <ext/standard/sha1.h>
27 #include <ext/spl/spl_exceptions.h>
28 #include <zend_exceptions.h>
56 if (
p->wrapped != NULL) {
65 zend_class_entry *class_type TSRMLS_DC) {
67 zend_object_std_init(&
intern->std, class_type TSRMLS_CC);
68 object_properties_init(&
intern->std, class_type);
70 channel_credentials_ce_handlers);
76 zval *credentials_object;
79 wrapped_grpc_channel_credentials *credentials =
85 return credentials_object;
98 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &pem_roots,
99 &pem_roots_length) == FAILURE) {
100 zend_throw_exception(spl_ce_InvalidArgumentException,
101 "setDefaultRootsPem expects 1 string", 1 TSRMLS_CC);
162 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"|s!s!s!",
167 &cert_chain_length) == FAILURE) {
168 zend_throw_exception(spl_ce_InvalidArgumentException,
169 "createSsl expects 3 optional strings", 1 TSRMLS_CC);
173 php_grpc_int hashkey_len = root_certs_length + cert_chain_length;
174 char *hashkey = emalloc(hashkey_len + 1);
175 if (root_certs_length > 0) {
178 if (cert_chain_length > 0) {
179 strcpy(hashkey, pem_key_cert_pair.
cert_chain);
187 pem_key_cert_pair.
private_key == NULL ? NULL : &pem_key_cert_pair, NULL, NULL);
207 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OO", &cred1_obj,
210 zend_throw_exception(spl_ce_InvalidArgumentException,
211 "createComposite expects 2 Credentials", 1 TSRMLS_CC);
214 wrapped_grpc_channel_credentials *cred1 =
216 wrapped_grpc_call_credentials *cred2 =
224 char *cred1_hashstr = malloc(cred1_len+1);
225 strcpy(cred1_hashstr, cred1->hashstr);
249 zval* fallback_creds = NULL;
250 if (zend_parse_parameters_ex(0,
251 ZEND_NUM_ARGS() TSRMLS_CC,
"O", &fallback_creds,
253 zend_throw_exception(spl_ce_InvalidArgumentException,
254 "createXds expects a fallback credentials",
259 wrapped_grpc_channel_credentials* wrapped_fallback_creds =
263 const char* fallback_creds_hash_str =
264 wrapped_fallback_creds->hashstr ? wrapped_fallback_creds->hashstr :
"";
267 char* hash_str = malloc(strlen(fallback_creds_hash_str) + strlen(
"XDS:") + 1);
268 strcpy(hash_str,
"XDS:");
269 strcat(hash_str, fallback_creds_hash_str);
271 xds_creds, hash_str,
false TSRMLS_CC);
275 ZEND_BEGIN_ARG_INFO_EX(arginfo_setDefaultRootsPem, 0, 0, 1)
276 ZEND_ARG_INFO(0, pem_roots)
279 ZEND_BEGIN_ARG_INFO_EX(arginfo_isDefaultRootsPemSet, 0, 0, 0)
282 ZEND_BEGIN_ARG_INFO_EX(arginfo_invalidateDefaultRootsPem, 0, 0, 0)
285 ZEND_BEGIN_ARG_INFO_EX(arginfo_createDefault, 0, 0, 0)
288 ZEND_BEGIN_ARG_INFO_EX(arginfo_createSsl, 0, 0, 0)
290 ZEND_ARG_INFO(0, pem_private_key)
291 ZEND_ARG_INFO(0, pem_cert_chain)
294 ZEND_BEGIN_ARG_INFO_EX(arginfo_createComposite, 0, 0, 2)
295 ZEND_ARG_INFO(0, channel_creds)
299 ZEND_BEGIN_ARG_INFO_EX(arginfo_createInsecure, 0, 0, 0)
302 ZEND_BEGIN_ARG_INFO_EX(arginfo_createXds, 0, 0, 1)
308 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
310 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
311 PHP_ME(
ChannelCredentials, invalidateDefaultRootsPem, arginfo_invalidateDefaultRootsPem,
312 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
314 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
316 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
318 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
320 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
322 ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
328 INIT_CLASS_ENTRY(ce,
"Grpc\\ChannelCredentials",
333 channel_credentials_ce_handlers);