Skip to content

Reseed the RNG on the first call to openssl_random_pseudo_bytes #1843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mathieuk
Copy link

  • Add php_openssl_rand_seed() that calls RAND_poll() if OPENSSL_G(rng_reseeded)=0
  • Call php_openssl_rand_seed() from openssl_random_pseudo_bytes()

Introduces a simple function reinit_rng() that checks (new) module global `rng_inited_for_request` and calls RAND_poll() if it's not true. It's not
the prettiest solution but the other solution seems to be to call RAND_poll() in RINIT which may occur a performance hit for each PHP request even
if you're not using openssl functions. Other mentioned solutions depend on things like pthread_atfork() which seems out of scope for a PHP module.
@@ -624,6 +630,14 @@ static STACK_OF(X509) * load_all_certs_from_file(char *certfile);
static X509_REQ * php_openssl_csr_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC);
static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req TSRMLS_DC);

static void php_openssl_rand_seed() /* {{{ */
{
if (!OPENSSL_G(rng_reseeded)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the bug report, the PHP_GINIT_FUNCTION is missing. In this case it means that you are checking uninitialized variable...

@php-pulls
Copy link

Comment on behalf of bukka at php.net:

The PR #1857 addressing the issue in a different way has just been merged

@php-pulls php-pulls closed this Jun 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants