com php-src: Merge branch 'PHP-7.0' into openssl_error_stor e: ext/openssl/openssl.c

From: Date: Sun, 12 Jun 2016 17:56:55 +0000
Subject: com php-src: Merge branch 'PHP-7.0' into openssl_error_stor e: ext/openssl/openssl.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92438@lists.php.net to get a copy of this message
Commit: b44cf1a8540d321583a0d83ebca688ebab10d3b0 Author: Jakub Zelenka <bukka@php.net> Sun, 12 Jun 2016 18:56:55 +0100 Parents: 6ac8bc4ecb1fdf112eefdd16d2c4f971e7ac232a a2f4c32eb14221de79009aadaa3da9c3349e3526 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b44cf1a8540d321583a0d83ebca688ebab10d3b0 Log: Merge branch 'PHP-7.0' into openssl_error_store Changed paths: MM ext/openssl/openssl.c Diff: diff --cc ext/openssl/openssl.c index 66dbdbf,e2f9faf..c27bbae --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@@ -1106,8 -1064,8 +1122,9 @@@ static int php_openssl_write_rand_file( if (file == NULL) { file = RAND_file_name(buffer, sizeof(buffer)); } + PHP_OPENSSL_RAND_ADD_TIME(); if (file == NULL || !RAND_write_file(file)) { + php_openssl_store_errors(); php_error_docref(NULL, E_WARNING, "unable to write random state"); return FAILURE; } @@@ -3623,9 -3442,8 +3649,10 @@@ static EVP_PKEY * php_openssl_generate_ return NULL; } rsaparam = RSA_new(); + PHP_OPENSSL_RAND_ADD_TIME(); - RSA_generate_key_ex(rsaparam, req->priv_key_bits, bne, NULL); + if (rsaparam == NULL || !RSA_generate_key_ex(rsaparam, req->priv_key_bits, bne, NULL)) { + php_openssl_store_errors(); + } BN_free(bne); } #endif @@@ -3785,6 -3591,46 +3814,48 @@@ static int php_openssl_is_private_key(E } \ } while (0); + /* {{{ php_openssl_pkey_init_dsa */ + zend_bool php_openssl_pkey_init_dsa(DSA *dsa) + { + if (!dsa->p || !dsa->q || !dsa->g) { + return 0; + } + if (dsa->priv_key || dsa->pub_key) { + return 1; + } + PHP_OPENSSL_RAND_ADD_TIME(); + if (!DSA_generate_key(dsa)) { ++ php_openssl_store_errors(); + return 0; + } + /* if BN_mod_exp return -1, then DSA_generate_key succeed for failed key + * so we need to double check that public key is created */ + if (!dsa->pub_key || BN_is_zero(dsa->pub_key)) { + return 0; + } + /* all good */ + return 1; + } + /* }}} */ + + /* {{{ php_openssl_pkey_init_dh */ + zend_bool php_openssl_pkey_init_dh(DH *dh) + { + if (!dh->p || !dh->g) { + return 0; + } + if (dh->pub_key) { + return 1; + } + PHP_OPENSSL_RAND_ADD_TIME(); + if (!DH_generate_key(dh)) { ++ php_openssl_store_errors(); + return 0; + } + /* all good */ + return 1; + } + /* }}} */ /* {{{ proto resource openssl_pkey_new([array configargs]) Generates a new private key */ @@@ -3843,14 -3683,9 +3914,11 @@@ PHP_FUNCTION(openssl_pkey_new OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dsa, g); OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dsa, priv_key); OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dsa, pub_key); - if (dsa->p && dsa->q && dsa->g) { - if (!dsa->priv_key && !dsa->pub_key && !DSA_generate_key(dsa)) { - php_openssl_store_errors(); - } + if (php_openssl_pkey_init_dsa(dsa)) { if (EVP_PKEY_assign_DSA(pkey, dsa)) { RETURN_RES(zend_register_resource(pkey, le_key)); + } else { + php_openssl_store_errors(); } } DSA_free(dsa); @@@ -3871,22 -3702,16 +3939,22 @@@ OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dh, p); OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dh, g); OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dh, priv_key); -- OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dh, pub_key); - if (dh->p && dh->g && - (dh->pub_key || DH_generate_key(dh)) && - EVP_PKEY_assign_DH(pkey, dh)) { - ZVAL_COPY_VALUE(return_value, zend_list_insert(pkey, le_key)); - return; - } else { - php_openssl_store_errors(); ++ OPENSSL_PKEY_SET_BN(Z_ARRVAL_P(data), dh, pub_key);php_openssl_store_errors(); + if (php_openssl_pkey_init_dh(dh)) { + if (EVP_PKEY_assign_DH(pkey, dh)) { + ZVAL_COPY_VALUE(return_value, zend_list_insert(pkey, le_key)); + return; ++ } else { ++ php_openssl_store_errors(); + } } DH_free(dh); + } else { + php_openssl_store_errors(); } EVP_PKEY_free(pkey); + } else { + php_openssl_store_errors(); } RETURN_FALSE; }

« previous php.cvs (#92438) next »