diff options
Diffstat (limited to 'ext/openssl/openssl.c')
| -rw-r--r-- | ext/openssl/openssl.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index e2deb4b115..c4ac6e6ffb 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -104,8 +104,8 @@ static void _php_x509_free(zend_rsrc_list_entry *rsrc); static int le_x509; static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * resourceval); -static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * passphrase, int makeresource, long * resourceval); -static X509_STORE * setup_verify(zval * calist); +static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * passphrase, int makeresource, long * resourceval TSRMLS_DC); +static X509_STORE * setup_verify(zval * calist TSRMLS_DC); static STACK_OF(X509) * load_all_certs_from_file(char *certfile); /* {{{ PHP_MINIT_FUNCTION @@ -263,7 +263,7 @@ static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * r empty string rather than NULL for the passphrase - NULL causes a passphrase prompt to be emitted in the Apache error log! */ -static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * passphrase, int makeresource, long * resourceval) +static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * passphrase, int makeresource, long * resourceval TSRMLS_DC) { EVP_PKEY * key = NULL; X509 * cert = NULL; @@ -280,7 +280,7 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * /* get passphrase */ if (zend_hash_index_find(HASH_OF(*val), 1, (void **)&zphrase) == FAILURE) { - zend_error(E_WARNING, "%s(): key array must be of the form array(0 => key, 1 => phrase)", get_active_function_name()); + zend_error(E_WARNING, "%s(): key array must be of the form array(0 => key, 1 => phrase)", get_active_function_name(TSRMLS_C)); return NULL; } convert_to_string_ex(zphrase); @@ -288,7 +288,7 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * /* now set val to be the key param and continue */ if (zend_hash_index_find(HASH_OF(*val), 0, (void **)&val) == FAILURE) { - zend_error(E_WARNING, "%s(): key array must be of the form array(0 => key, 1 => phrase)", get_active_function_name()); + zend_error(E_WARNING, "%s(): key array must be of the form array(0 => key, 1 => phrase)", get_active_function_name(TSRMLS_C)); return NULL; } } @@ -405,7 +405,7 @@ PHP_FUNCTION(openssl_private_encrypt) pkey = php_openssl_evp_from_zval(key, 0, "", 0, &keyresource); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): key param is not a valid private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): key param is not a valid private key", get_active_function_name(TSRMLS_C) TSRMLS_CC); RETURN_FALSE; } @@ -475,7 +475,7 @@ PHP_FUNCTION(openssl_private_decrypt) pkey = php_openssl_evp_from_zval(key, 0, "", 0, &keyresource); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): key param is not a valid private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): key param is not a valid private key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } @@ -550,9 +550,9 @@ PHP_FUNCTION(openssl_public_encrypt) RETVAL_FALSE; - pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource); + pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): key param is not a valid public key", get_active_function_name()); + zend_error(E_WARNING, "%s(): key param is not a valid public key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } @@ -620,9 +620,9 @@ PHP_FUNCTION(openssl_public_decrypt) convert_to_string_ex(data); RETVAL_FALSE; - pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource); + pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): key param is not a valid public key", get_active_function_name()); + zend_error(E_WARNING, "%s(): key param is not a valid public key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } @@ -685,10 +685,10 @@ PHP_FUNCTION(openssl_get_privatekey) } return_value->type = IS_RESOURCE; - pkey = php_openssl_evp_from_zval(key, 0, argc == 2 ? Z_STRVAL_PP(passphrase) : "", 1, &(return_value->value.lval)); + pkey = php_openssl_evp_from_zval(key, 0, argc == 2 ? Z_STRVAL_PP(passphrase) : "", 1, &(return_value->value.lval) TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): unable to coerce arg to a private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): unable to coerce arg to a private key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } } @@ -747,7 +747,7 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr) long gmadjust = 0; if (timestr->length < 13) { - zend_error(E_WARNING, "%s(): extension author too lazy to parse %s correctly", get_active_function_name(), timestr->data); + zend_error(E_WARNING, "%s(): extension author too lazy to parse %s correctly", get_active_function_name(TSRMLS_C), timestr->data); return (time_t)-1; } @@ -897,20 +897,21 @@ static STACK_OF(X509) * load_all_certs_from_file(char *certfile) STACK_OF(X509) *stack=NULL, *ret=NULL; BIO *in=NULL; X509_INFO *xi; + TSRMLS_FETCH(); if(!(stack = sk_X509_new_null())) { - zend_error(E_ERROR, "%s(): memory allocation failure", get_active_function_name()); + zend_error(E_ERROR, "%s(): memory allocation failure", get_active_function_name(TSRMLS_C)); goto end; } if(!(in=BIO_new_file(certfile, "r"))) { - zend_error(E_WARNING, "%s(): error opening the file, %s", get_active_function_name(), certfile); + zend_error(E_WARNING, "%s(): error opening the file, %s", get_active_function_name(TSRMLS_C), certfile); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ if(!(sk=PEM_X509_INFO_read_bio(in, NULL, NULL, NULL))) { - zend_error(E_WARNING, "%s(): error reading the file, %s", get_active_function_name(), certfile); + zend_error(E_WARNING, "%s(): error reading the file, %s", get_active_function_name(TSRMLS_C), certfile); goto end; } @@ -926,7 +927,7 @@ static STACK_OF(X509) * load_all_certs_from_file(char *certfile) X509_INFO_free(xi); } if(!sk_X509_num(stack)) { - zend_error(E_WARNING, "%s(): no certificates in file, %s", get_active_function_name(), certfile); + zend_error(E_WARNING, "%s(): no certificates in file, %s", get_active_function_name(TSRMLS_C), certfile); sk_X509_free(stack); goto end; } @@ -944,11 +945,12 @@ static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, { int ret=0; X509_STORE_CTX *csc; + TSRMLS_FETCH(); csc = X509_STORE_CTX_new(); if (csc == NULL) { - zend_error(E_ERROR, "%s(): memory allocation failure", get_active_function_name()); + zend_error(E_ERROR, "%s(): memory allocation failure", get_active_function_name(TSRMLS_C)); return 0; } X509_STORE_CTX_init(csc, ctx, x, untrustedchain); @@ -990,7 +992,7 @@ PHP_FUNCTION(openssl_x509_checkpurpose) } convert_to_long_ex(zpurpose); - cainfo = setup_verify(*zcainfo); + cainfo = setup_verify(*zcainfo TSRMLS_CC); if (cainfo == NULL) goto clean_exit; @@ -1023,7 +1025,7 @@ PHP_FUNCTION(openssl_get_publickey) } return_value->type = IS_RESOURCE; - pkey = php_openssl_evp_from_zval(cert, 1, NULL, 1, &(return_value->value.lval)); + pkey = php_openssl_evp_from_zval(cert, 1, NULL, 1, &(return_value->value.lval) TSRMLS_CC); if (pkey == NULL) { RETURN_FALSE; @@ -1064,7 +1066,7 @@ PHP_FUNCTION(openssl_x509_read) x509 = php_openssl_x509_from_zval(cert, 1, &(return_value->value.lval)); if (x509 == NULL) { - zend_error(E_WARNING, "%s() supplied parameter cannot be coerced into an X509 certificate!", get_active_function_name()); + zend_error(E_WARNING, "%s() supplied parameter cannot be coerced into an X509 certificate!", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } } @@ -1090,7 +1092,7 @@ PHP_FUNCTION(openssl_x509_free) * calist is an array containing file and directory names. create a * certificate store and add those certs to it for use in verification. */ -static X509_STORE * setup_verify(zval * calist) +static X509_STORE * setup_verify(zval * calist TSRMLS_DC) { X509_STORE *store; X509_LOOKUP * dir_lookup, * file_lookup; @@ -1114,14 +1116,14 @@ static X509_STORE * setup_verify(zval * calist) convert_to_string_ex(item); if (VCWD_STAT(Z_STRVAL_PP(item), &sb) == -1) { - zend_error(E_WARNING, "%s() unable to stat %s", get_active_function_name(), Z_STRVAL_PP(item)); + zend_error(E_WARNING, "%s() unable to stat %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(item)); continue; } if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (file_lookup == NULL || !X509_LOOKUP_load_file(file_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) - zend_error(E_WARNING, "%s() error loading file %s", get_active_function_name(), Z_STRVAL_PP(item)); + zend_error(E_WARNING, "%s() error loading file %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(item)); else nfiles++; file_lookup = NULL; @@ -1129,7 +1131,7 @@ static X509_STORE * setup_verify(zval * calist) else { dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (dir_lookup == NULL || !X509_LOOKUP_add_dir(dir_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) - zend_error(E_WARNING, "%s() error loading directory %s", get_active_function_name(), Z_STRVAL_PP(item)); + zend_error(E_WARNING, "%s() error loading directory %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(item)); else ndirs++; dir_lookup = NULL; @@ -1207,7 +1209,7 @@ PHP_FUNCTION(openssl_pkcs7_verify) if (argc >= 4) { if (Z_TYPE_PP(cainfo) != IS_ARRAY) { - zend_error(E_WARNING, "%s(): 4th parameter must be an array", get_active_function_name()); + zend_error(E_WARNING, "%s(): 4th parameter must be an array", get_active_function_name(TSRMLS_C)); goto clean_exit; } } @@ -1251,7 +1253,7 @@ PHP_FUNCTION(openssl_pkcs7_verify) } else { zend_error(E_WARNING, "%s(): signature OK, but cannot open %s for writing", - get_active_function_name(), signersfilename); + get_active_function_name(TSRMLS_C), signersfilename); RETVAL_LONG(-1); } } @@ -1299,7 +1301,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) if ((*zheaders)->type == IS_NULL) zheaders = NULL; else if ((*zheaders)->type != IS_ARRAY) { - zend_error(E_WARNING, "%s(): 4th param must be an array/null value!", get_active_function_name()); + zend_error(E_WARNING, "%s(): 4th param must be an array/null value!", get_active_function_name(TSRMLS_C)); goto clean_exit; } } @@ -1445,7 +1447,7 @@ PHP_FUNCTION(openssl_pkcs7_sign) if ((*zheaders)->type == IS_NULL) zheaders = NULL; else if ((*zheaders)->type != IS_ARRAY) { - zend_error(E_WARNING, "%s(): 5th param must be an array/null value!", get_active_function_name()); + zend_error(E_WARNING, "%s(): 5th param must be an array/null value!", get_active_function_name(TSRMLS_C)); goto clean_exit; } } @@ -1453,33 +1455,33 @@ PHP_FUNCTION(openssl_pkcs7_sign) convert_to_string_ex(zinfilename); convert_to_string_ex(zoutfilename); - privkey = php_openssl_evp_from_zval(zprivkey, 0, "", 0, &keyresource); + privkey = php_openssl_evp_from_zval(zprivkey, 0, "", 0, &keyresource TSRMLS_CC); if (privkey == NULL) { - zend_error(E_WARNING, "%s(): error getting private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): error getting private key", get_active_function_name(TSRMLS_C)); goto clean_exit; } cert = php_openssl_x509_from_zval(zcert, 0, &certresource); if (cert == NULL) { - zend_error(E_WARNING, "%s(): error getting cert", get_active_function_name()); + zend_error(E_WARNING, "%s(): error getting cert", get_active_function_name(TSRMLS_C)); goto clean_exit; } infile = BIO_new_file(Z_STRVAL_PP(zinfilename), "r"); if (infile == NULL) { - zend_error(E_WARNING, "%s(): error opening input file %s!", get_active_function_name(), Z_STRVAL_PP(zinfilename)); + zend_error(E_WARNING, "%s(): error opening input file %s!", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(zinfilename)); goto clean_exit; } outfile = BIO_new_file(Z_STRVAL_PP(zoutfilename), "w"); if (outfile == NULL) { - zend_error(E_WARNING, "%s(): error opening output file %s!", get_active_function_name(), Z_STRVAL_PP(zoutfilename)); + zend_error(E_WARNING, "%s(): error opening output file %s!", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(zoutfilename)); goto clean_exit; } p7 = PKCS7_sign(cert, privkey, others, infile, flags); if (p7 == NULL) { - zend_error(E_WARNING, "%s(): error creating PKCS7 structure!", get_active_function_name()); + zend_error(E_WARNING, "%s(): error creating PKCS7 structure!", get_active_function_name(TSRMLS_C)); goto clean_exit; } @@ -1539,13 +1541,13 @@ PHP_FUNCTION(openssl_pkcs7_decrypt) cert = php_openssl_x509_from_zval(recipcert, 0, &certresval); if (cert == NULL) { - zend_error(E_WARNING, "%s(): unable to coerce param 3 to x509 cert", get_active_function_name()); + zend_error(E_WARNING, "%s(): unable to coerce param 3 to x509 cert", get_active_function_name(TSRMLS_C)); goto clean_exit; } - key = php_openssl_evp_from_zval(argc == 3 ? recipcert : recipkey, 0, "", 0, &keyresval); + key = php_openssl_evp_from_zval(argc == 3 ? recipcert : recipkey, 0, "", 0, &keyresval TSRMLS_CC); if (key == NULL) { - zend_error(E_WARNING, "%s(): unable to coerce param %d to a private key", get_active_function_name(), argc); + zend_error(E_WARNING, "%s(): unable to coerce param %d to a private key", get_active_function_name(TSRMLS_C), argc); goto clean_exit; } @@ -1598,9 +1600,9 @@ PHP_FUNCTION(openssl_sign) } convert_to_string_ex(data); - pkey = php_openssl_evp_from_zval(key, 0, "", 0, &keyresource); + pkey = php_openssl_evp_from_zval(key, 0, "", 0, &keyresource TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): supplied key param cannot be coerced into a private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): supplied key param cannot be coerced into a private key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } @@ -1640,9 +1642,9 @@ PHP_FUNCTION(openssl_verify) convert_to_string_ex(data); convert_to_string_ex(signature); - pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource); + pkey = php_openssl_evp_from_zval(key, 1, NULL, 0, &keyresource TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): supplied key param cannot be coerced into a public key", get_active_function_name()); + zend_error(E_WARNING, "%s(): supplied key param cannot be coerced into a public key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } @@ -1699,9 +1701,9 @@ PHP_FUNCTION(openssl_seal) i = 0; while (zend_hash_get_current_data_ex(pubkeysht, (void **) &pubkey, &pos) == SUCCESS) { - pkeys[i] = php_openssl_evp_from_zval(pubkey, 1, NULL, 0, &key_resources[i]); + pkeys[i] = php_openssl_evp_from_zval(pubkey, 1, NULL, 0, &key_resources[i] TSRMLS_CC); if (pkeys[i] == NULL) { - zend_error(E_WARNING, "%s(): not a public key (%dth member of pubkeys)", get_active_function_name(), i); + zend_error(E_WARNING, "%s(): not a public key (%dth member of pubkeys)", get_active_function_name(TSRMLS_C), i); RETVAL_FALSE; goto clean_exit; } @@ -1811,9 +1813,9 @@ PHP_FUNCTION(openssl_open) convert_to_string_ex(data); convert_to_string_ex(ekey); - pkey = php_openssl_evp_from_zval(privkey, 0, "", 0, &keyresource); + pkey = php_openssl_evp_from_zval(privkey, 0, "", 0, &keyresource TSRMLS_CC); if (pkey == NULL) { - zend_error(E_WARNING, "%s(): unable to coerce param 4 into a private key", get_active_function_name()); + zend_error(E_WARNING, "%s(): unable to coerce param 4 into a private key", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } buf = emalloc(Z_STRLEN_PP(data) + 1); |
