From f569ae5981e354abab4f9412a0b6e12d2451d3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20F=C3=B6rster?= Date: Tue, 27 Nov 2018 04:03:46 +0100 Subject: [PATCH] [dev-lang/php] update openssl patch from debian --- dev-lang/php/files/php-5.6.31-openssl11.patch | 742 +++++++++++------- ...php-5.6.38.ebuild => php-5.6.38-r1.ebuild} | 2 +- 2 files changed, 438 insertions(+), 306 deletions(-) rename dev-lang/php/{php-5.6.38.ebuild => php-5.6.38-r1.ebuild} (99%) diff --git a/dev-lang/php/files/php-5.6.31-openssl11.patch b/dev-lang/php/files/php-5.6.31-openssl11.patch index 1cce7e3..79066cb 100644 --- a/dev-lang/php/files/php-5.6.31-openssl11.patch +++ b/dev-lang/php/files/php-5.6.31-openssl11.patch @@ -1,44 +1,187 @@ -From 4ca75ff1f3c341b83932f85310595f5c0a10f57e Mon Sep 17 00:00:00 2001 -From: Remi Collet -Date: Mon, 20 Mar 2017 11:45:54 +0100 -Subject: [PATCH] backport needed changes for OpenSSL 1.1 +From: Debian PHP Maintainers +Date: Thu, 3 Aug 2017 20:45:55 +0200 +Subject: Use-OpenSSL-1.1-compatibility-patch-when-built-with- --- - ext/openssl/openssl.c | 528 ++++++++++++++-------- - ext/openssl/tests/001.phpt | 7 +- + ext/openssl/openssl.c | 683 ++++++++++++++++------ ext/openssl/tests/bug41033.phpt | 4 +- ext/openssl/tests/bug66501.phpt | 2 +- - ext/openssl/tests/openssl_error_string_basic.phpt | 6 +- - ext/openssl/tests/sni_server.phpt | 2 + - ext/openssl/xp_ssl.c | 15 - + ext/openssl/tests/openssl_error_string_basic.phpt | 2 +- + ext/openssl/tests/sni_server.phpt | 3 + + ext/openssl/xp_ssl.c | 18 +- ext/phar/util.c | 13 +- - 8 files changed, 371 insertions(+), 206 deletions(-) + 7 files changed, 534 insertions(+), 191 deletions(-) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c -index a78a8fb..eda68f2 100644 +index a78a8fb..b53114c 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c -@@ -68,7 +68,9 @@ - #ifdef HAVE_OPENSSL_MD2_H - #define OPENSSL_ALGO_MD2 4 - #endif -+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER) - #define OPENSSL_ALGO_DSS1 5 +@@ -42,6 +42,12 @@ + + /* OpenSSL includes */ + #include ++#if OPENSSL_VERSION_NUMBER >= 0x10002000L ++#include ++#include ++#include ++#include +#endif - #if OPENSSL_VERSION_NUMBER >= 0x0090708fL - #define OPENSSL_ALGO_SHA224 6 - #define OPENSSL_ALGO_SHA256 7 -@@ -825,7 +827,8 @@ static int add_oid_section(struct php_x509_request * req TSRMLS_DC) /* {{{ */ + #include + #include + #include +@@ -531,6 +537,133 @@ zend_module_entry openssl_module_entry = { + ZEND_GET_MODULE(openssl) + #endif + ++/* {{{ OpenSSL compatibility functions and macros */ ++#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER) ++#define EVP_PKEY_get0_RSA(_pkey) _pkey->pkey.rsa ++#define EVP_PKEY_get0_DH(_pkey) _pkey->pkey.dh ++#define EVP_PKEY_get0_DSA(_pkey) _pkey->pkey.dsa ++#define EVP_PKEY_get0_EC_KEY(_pkey) _pkey->pkey.ec ++ ++static int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) ++{ ++ r->n = n; ++ r->e = e; ++ r->d = d; ++ ++ return 1; ++} ++ ++static int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) ++{ ++ r->p = p; ++ r->q = q; ++ ++ return 1; ++} ++ ++static int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) ++{ ++ r->dmp1 = dmp1; ++ r->dmq1 = dmq1; ++ r->iqmp = iqmp; ++ ++ return 1; ++} ++ ++static void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) ++{ ++ *n = r->n; ++ *e = r->e; ++ *d = r->d; ++} ++ ++static void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) ++{ ++ *p = r->p; ++ *q = r->q; ++} ++ ++static void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp) ++{ ++ *dmp1 = r->dmp1; ++ *dmq1 = r->dmq1; ++ *iqmp = r->iqmp; ++} ++ ++static void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) ++{ ++ *p = dh->p; ++ *q = dh->q; ++ *g = dh->g; ++} ++ ++static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) ++{ ++ dh->p = p; ++ dh->q = q; ++ dh->g = g; ++ ++ return 1; ++} ++ ++static void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) ++{ ++ *pub_key = dh->pub_key; ++ *priv_key = dh->priv_key; ++} ++ ++static int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) ++{ ++ dh->pub_key = pub_key; ++ dh->priv_key = priv_key; ++ ++ return 1; ++} ++ ++static void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) ++{ ++ *p = d->p; ++ *q = d->q; ++ *g = d->g; ++} ++ ++int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) ++{ ++ d->p = p; ++ d->q = q; ++ d->g = g; ++ ++ return 1; ++} ++ ++static void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) ++{ ++ *pub_key = d->pub_key; ++ *priv_key = d->priv_key; ++} ++ ++int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) ++{ ++ d->pub_key = pub_key; ++ d->priv_key = priv_key; ++ ++ return 1; ++} ++ ++#if OPENSSL_VERSION_NUMBER < 0x10002000L || defined (LIBRESSL_VERSION_NUMBER) ++#define EVP_PKEY_id(_pkey) _pkey->type ++#define EVP_PKEY_base_id(_key) EVP_PKEY_type(_key->type) ++ ++static int X509_get_signature_nid(const X509 *x) ++{ ++ return OBJ_obj2nid(x->sig_alg->algorithm); ++} ++ ++#endif ++ ++#endif ++/* }}} */ ++ + static int le_key; + static int le_x509; + static int le_csr; +@@ -825,7 +958,7 @@ static int add_oid_section(struct php_x509_request * req TSRMLS_DC) /* {{{ */ } for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { cnf = sk_CONF_VALUE_value(sktmp, i); - if (OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) { -+ if (OBJ_sn2nid(cnf->name) == NID_undef && OBJ_ln2nid(cnf->name) == NID_undef && -+ OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) { ++ if (OBJ_sn2nid(cnf->name) == NID_undef && OBJ_ln2nid(cnf->name) == NID_undef && OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "problem creating object %s=%s", cnf->name, cnf->value); return FAILURE; } -@@ -1053,9 +1056,11 @@ static EVP_MD * php_openssl_get_evp_md_from_algo(long algo) { /* {{{ */ +@@ -967,7 +1100,7 @@ static void php_openssl_dispose_config(struct php_x509_request * req TSRMLS_DC) + } + /* }}} */ + +-#ifdef PHP_WIN32 ++#if defined(PHP_WIN32) || (OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)) + #define PHP_OPENSSL_RAND_ADD_TIME() ((void) 0) + #else + #define PHP_OPENSSL_RAND_ADD_TIME() php_openssl_rand_add_timeval() +@@ -1053,9 +1186,11 @@ static EVP_MD * php_openssl_get_evp_md_from_algo(long algo) { /* {{{ */ mdtype = (EVP_MD *) EVP_md2(); break; #endif @@ -50,7 +193,20 @@ index a78a8fb..eda68f2 100644 #if OPENSSL_VERSION_NUMBER >= 0x0090708fL case OPENSSL_ALGO_SHA224: mdtype = (EVP_MD *) EVP_sha224(); -@@ -1173,7 +1178,9 @@ PHP_MINIT_FUNCTION(openssl) +@@ -1146,6 +1281,12 @@ PHP_MINIT_FUNCTION(openssl) + OpenSSL_add_all_digests(); + OpenSSL_add_all_algorithms(); + ++#if !defined(OPENSSL_NO_AES) && defined(EVP_CIPH_CCM_MODE) && OPENSSL_VERSION_NUMBER < 0x100020000 ++ EVP_add_cipher(EVP_aes_128_ccm()); ++ EVP_add_cipher(EVP_aes_192_ccm()); ++ EVP_add_cipher(EVP_aes_256_ccm()); ++#endif ++ + SSL_load_error_strings(); + + /* register a resource id number with OpenSSL so that we can map SSL -> stream structures in +@@ -1173,7 +1314,9 @@ PHP_MINIT_FUNCTION(openssl) #ifdef HAVE_OPENSSL_MD2_H REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD2", OPENSSL_ALGO_MD2, CONST_CS|CONST_PERSISTENT); #endif @@ -60,7 +216,27 @@ index a78a8fb..eda68f2 100644 #if OPENSSL_VERSION_NUMBER >= 0x0090708fL REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA224", OPENSSL_ALGO_SHA224, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA256", OPENSSL_ALGO_SHA256, CONST_CS|CONST_PERSISTENT); -@@ -1893,6 +1900,7 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +@@ -1251,7 +1394,9 @@ PHP_MINIT_FUNCTION(openssl) + } + + php_stream_xport_register("ssl", php_openssl_ssl_socket_factory TSRMLS_CC); ++#ifndef OPENSSL_NO_SSL3 + php_stream_xport_register("sslv3", php_openssl_ssl_socket_factory TSRMLS_CC); ++#endif + #ifndef OPENSSL_NO_SSL2 + php_stream_xport_register("sslv2", php_openssl_ssl_socket_factory TSRMLS_CC); + #endif +@@ -1308,7 +1453,9 @@ PHP_MSHUTDOWN_FUNCTION(openssl) + #ifndef OPENSSL_NO_SSL2 + php_stream_xport_unregister("sslv2" TSRMLS_CC); + #endif ++#ifndef OPENSSL_NO_SSL3 + php_stream_xport_unregister("sslv3" TSRMLS_CC); ++#endif + php_stream_xport_unregister("tls" TSRMLS_CC); + php_stream_xport_unregister("tlsv1.0" TSRMLS_CC); + #if OPENSSL_VERSION_NUMBER >= 0x10001001L +@@ -1893,6 +2040,7 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) { GENERAL_NAMES *names; const X509V3_EXT_METHOD *method = NULL; @@ -68,7 +244,7 @@ index a78a8fb..eda68f2 100644 long i, length, num; const unsigned char *p; -@@ -1901,8 +1909,9 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) +@@ -1901,8 +2049,9 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension) return -1; } @@ -80,7 +256,7 @@ index a78a8fb..eda68f2 100644 if (method->it) { names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length, ASN1_ITEM_ptr(method->it))); -@@ -1965,6 +1974,8 @@ PHP_FUNCTION(openssl_x509_parse) +@@ -1965,6 +2114,8 @@ PHP_FUNCTION(openssl_x509_parse) char * tmpstr; zval * subitem; X509_EXTENSION *extension; @@ -89,26 +265,22 @@ index a78a8fb..eda68f2 100644 char *extname; BIO *bio_out; BUF_MEM *bio_buf; -@@ -1979,12 +1990,14 @@ PHP_FUNCTION(openssl_x509_parse) +@@ -1979,10 +2130,10 @@ PHP_FUNCTION(openssl_x509_parse) } array_init(return_value); - if (cert->name) { - add_assoc_string(return_value, "name", cert->name, 1); - } +-/* add_assoc_bool(return_value, "valid", cert->valid); */ + subject_name = X509_get_subject_name(cert); + cert_name = X509_NAME_oneline(subject_name, NULL, 0); + add_assoc_string(return_value, "name", cert_name, 1); + OPENSSL_free(cert_name); -+ - /* add_assoc_bool(return_value, "valid", cert->valid); */ -- add_assoc_name_entry(return_value, "subject", X509_get_subject_name(cert), useshortnames TSRMLS_CC); -+ add_assoc_name_entry(return_value, "subject", subject_name, useshortnames TSRMLS_CC); + add_assoc_name_entry(return_value, "subject", X509_get_subject_name(cert), useshortnames TSRMLS_CC); /* hash as used in CA directories to lookup cert by subject name */ - { - char buf[32]; -@@ -2008,7 +2021,7 @@ PHP_FUNCTION(openssl_x509_parse) +@@ -2008,7 +2159,7 @@ PHP_FUNCTION(openssl_x509_parse) add_assoc_string(return_value, "alias", tmpstr, 1); } @@ -117,7 +289,30 @@ index a78a8fb..eda68f2 100644 add_assoc_string(return_value, "signatureTypeSN", (char*)OBJ_nid2sn(sig_nid), 1); add_assoc_string(return_value, "signatureTypeLN", (char*)OBJ_nid2ln(sig_nid), 1); add_assoc_long(return_value, "signatureTypeNID", sig_nid); -@@ -3482,14 +3495,21 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) +@@ -3217,7 +3368,21 @@ PHP_FUNCTION(openssl_csr_get_public_key) + RETURN_FALSE; + } + +- tpubkey=X509_REQ_get_pubkey(csr); ++#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) ++ /* Due to changes in OpenSSL 1.1 related to locking when decoding CSR, ++ * the pub key is not changed after assigning. It means if we pass ++ * a private key, it will be returned including the private part. ++ * If we duplicate it, then we get just the public part which is ++ * the same behavior as for OpenSSL 1.0 */ ++ csr = X509_REQ_dup(csr); ++#endif ++ /* Retrieve the public key from the CSR */ ++ tpubkey = X509_REQ_get_pubkey(csr); ++ ++#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) ++ /* We need to free the CSR as it was duplicated */ ++ X509_REQ_free(csr); ++#endif + RETVAL_RESOURCE(zend_list_insert(tpubkey, le_key TSRMLS_CC)); + return; + } +@@ -3482,13 +3647,20 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) { assert(pkey != NULL); @@ -129,7 +324,6 @@ index a78a8fb..eda68f2 100644 - assert(pkey->pkey.rsa != NULL); - if (pkey->pkey.rsa != NULL && (NULL == pkey->pkey.rsa->p || NULL == pkey->pkey.rsa->q)) { - return 0; -- } + { + RSA *rsa = EVP_PKEY_get0_RSA(pkey); + if (rsa != NULL) { @@ -140,11 +334,10 @@ index a78a8fb..eda68f2 100644 + return 0; + } + } -+ } + } break; #endif - #ifndef NO_DSA -@@ -3498,29 +3518,50 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) +@@ -3498,28 +3670,51 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: @@ -152,7 +345,6 @@ index a78a8fb..eda68f2 100644 - - if (NULL == pkey->pkey.dsa->p || NULL == pkey->pkey.dsa->q || NULL == pkey->pkey.dsa->priv_key){ - return 0; -- } + { + DSA *dsa = EVP_PKEY_get0_DSA(pkey); + if (dsa != NULL) { @@ -162,12 +354,13 @@ index a78a8fb..eda68f2 100644 + if (p == NULL || q == NULL) { + return 0; + } ++ + DSA_get0_key(dsa, &pub_key, &priv_key); + if (priv_key == NULL) { + return 0; + } + } -+ } + } break; #endif #ifndef NO_DH @@ -176,7 +369,6 @@ index a78a8fb..eda68f2 100644 - - if (NULL == pkey->pkey.dh->p || NULL == pkey->pkey.dh->priv_key) { - return 0; -- } + { + DH *dh = EVP_PKEY_get0_DH(pkey); + if (dh != NULL) { @@ -186,12 +378,13 @@ index a78a8fb..eda68f2 100644 + if (p == NULL) { + return 0; + } ++ + DH_get0_key(dh, &pub_key, &priv_key); + if (priv_key == NULL) { + return 0; + } + } -+ } + } break; #endif #ifdef HAVE_EVP_PKEY_EC @@ -200,68 +393,71 @@ index a78a8fb..eda68f2 100644 - - if ( NULL == EC_KEY_get0_private_key(pkey->pkey.ec)) { - return 0; -- } + { + EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey); + if (ec != NULL && NULL == EC_KEY_get0_private_key(ec)) { + return 0; + } -+ } + } break; #endif - default: -@@ -3531,42 +3572,91 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) +@@ -3531,34 +3726,80 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC) } /* }}} */ -#define OPENSSL_PKEY_GET_BN(_type, _name) do { \ - if (pkey->pkey._type->_name != NULL) { \ - int len = BN_num_bytes(pkey->pkey._type->_name); \ -+#define OPENSSL_GET_BN(_array, _bn, _name) do { \ -+ if (_bn != NULL) { \ -+ int len = BN_num_bytes(_bn); \ - char *str = emalloc(len + 1); \ +- char *str = emalloc(len + 1); \ - BN_bn2bin(pkey->pkey._type->_name, (unsigned char*)str); \ -+ BN_bn2bin(_bn, (unsigned char*)str); \ - str[len] = 0; \ +- str[len] = 0; \ - add_assoc_stringl(_type, #_name, str, len, 0); \ -+ add_assoc_stringl(_array, #_name, str, len, 0); \ - } \ - } while (0) - +- } \ +- } while (0) +- -#define OPENSSL_PKEY_SET_BN(_ht, _type, _name) do { \ -+#define OPENSSL_PKEY_GET_BN(_type, _name) OPENSSL_GET_BN(_type, _name, _name) -+ -+#define OPENSSL_PKEY_SET_BN(_data, _name) do { \ - zval **bn; \ +- zval **bn; \ - if (zend_hash_find(_ht, #_name, sizeof(#_name), (void**)&bn) == SUCCESS && \ -+ if (zend_hash_find(Z_ARRVAL_P(_data), #_name, sizeof(#_name), (void**)&bn) == SUCCESS && \ - Z_TYPE_PP(bn) == IS_STRING) { \ +- Z_TYPE_PP(bn) == IS_STRING) { \ - _type->_name = BN_bin2bn( \ -+ _name = BN_bin2bn( \ - (unsigned char*)Z_STRVAL_PP(bn), \ - Z_STRLEN_PP(bn), NULL); \ -+ } else { \ -+ _name = NULL; \ - } \ +- (unsigned char*)Z_STRVAL_PP(bn), \ +- Z_STRLEN_PP(bn), NULL); \ +- } \ ++#define OPENSSL_GET_BN(_array, _bn, _name) do { \ ++ if (_bn != NULL) { \ ++ int len = BN_num_bytes(_bn); \ ++ char *str = emalloc(len + 1); \ ++ BN_bn2bin(_bn, (unsigned char*)str); \ ++ str[len] = 0; \ ++ add_assoc_stringl(_array, #_name, str, len, 0); \ ++ } \ } while (0); --/* {{{ php_openssl_pkey_init_dsa */ --zend_bool php_openssl_pkey_init_dsa(DSA *dsa) ++#define OPENSSL_PKEY_GET_BN(_type, _name) OPENSSL_GET_BN(_type, _name, _name) ++ ++#define OPENSSL_PKEY_SET_BN(_data, _name) do { \ ++ zval **bn; \ ++ if (zend_hash_find(Z_ARRVAL_P(_data), #_name, sizeof(#_name),(void**)&bn) == SUCCESS && \ ++ Z_TYPE_PP(bn) == IS_STRING) { \ ++ _name = BN_bin2bn( \ ++ (unsigned char*)Z_STRVAL_PP(bn), \ ++ Z_STRLEN_PP(bn), NULL); \ ++ } else { \ ++ _name = NULL; \ ++ } \ ++ } while (0); ++ +/* {{{ php_openssl_pkey_init_rsa */ +zend_bool php_openssl_pkey_init_and_assign_rsa(EVP_PKEY *pkey, RSA *rsa, zval *data) - { -- if (!dsa->p || !dsa->q || !dsa->g) { ++{ + BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; + + OPENSSL_PKEY_SET_BN(data, n); + OPENSSL_PKEY_SET_BN(data, e); + OPENSSL_PKEY_SET_BN(data, d); + if (!n || !d || !RSA_set0_key(rsa, n, e, d)) { - return 0; - } -- if (dsa->priv_key || dsa->pub_key) { -- return 1; ++ return 0; ++ } + + OPENSSL_PKEY_SET_BN(data, p); + OPENSSL_PKEY_SET_BN(data, q); @@ -282,10 +478,13 @@ index a78a8fb..eda68f2 100644 + + return 1; +} ++/* }}} */ + -+/* {{{ php_openssl_pkey_init_dsa */ + /* {{{ php_openssl_pkey_init_dsa */ +-zend_bool php_openssl_pkey_init_dsa(DSA *dsa) +zend_bool php_openssl_pkey_init_dsa(DSA *dsa, zval *data) -+{ + { +- if (!dsa->p || !dsa->q || !dsa->g) { + BIGNUM *p, *q, *g, *priv_key, *pub_key; + const BIGNUM *priv_key_const, *pub_key_const; + @@ -293,21 +492,20 @@ index a78a8fb..eda68f2 100644 + OPENSSL_PKEY_SET_BN(data, q); + OPENSSL_PKEY_SET_BN(data, g); + if (!p || !q || !g || !DSA_set0_pqg(dsa, p, q, g)) { -+ return 0; + return 0; } +- if (dsa->priv_key || dsa->pub_key) { +- return 1; + + OPENSSL_PKEY_SET_BN(data, pub_key); + OPENSSL_PKEY_SET_BN(data, priv_key); + if (pub_key) { + return DSA_set0_key(dsa, pub_key, priv_key); -+ } -+ -+ /* generate key */ + } PHP_OPENSSL_RAND_ADD_TIME(); if (!DSA_generate_key(dsa)) { - return 0; +@@ -3566,7 +3807,8 @@ zend_bool php_openssl_pkey_init_dsa(DSA *dsa) } -+ /* 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)) { @@ -316,7 +514,7 @@ index a78a8fb..eda68f2 100644 return 0; } /* all good */ -@@ -3574,15 +3664,69 @@ zend_bool php_openssl_pkey_init_dsa(DSA *dsa) +@@ -3574,14 +3816,66 @@ zend_bool php_openssl_pkey_init_dsa(DSA *dsa) } /* }}} */ @@ -377,20 +575,17 @@ index a78a8fb..eda68f2 100644 + OPENSSL_PKEY_SET_BN(data, pub_key); + if (pub_key) { + return DH_set0_key(dh, pub_key, priv_key); - } ++ } + if (priv_key) { + pub_key = php_openssl_dh_pub_from_priv(priv_key, g, p); + if (pub_key == NULL) { + return 0; + } + return DH_set0_key(dh, pub_key, priv_key); -+ } -+ -+ /* generate key */ + } PHP_OPENSSL_RAND_ADD_TIME(); if (!DH_generate_key(dh)) { - return 0; -@@ -3614,18 +3758,8 @@ PHP_FUNCTION(openssl_pkey_new) +@@ -3614,18 +3908,8 @@ PHP_FUNCTION(openssl_pkey_new) if (pkey) { RSA *rsa = RSA_new(); if (rsa) { @@ -411,7 +606,7 @@ index a78a8fb..eda68f2 100644 } RSA_free(rsa); } -@@ -3638,12 +3772,7 @@ PHP_FUNCTION(openssl_pkey_new) +@@ -3638,12 +3922,7 @@ PHP_FUNCTION(openssl_pkey_new) if (pkey) { DSA *dsa = DSA_new(); if (dsa) { @@ -425,7 +620,7 @@ index a78a8fb..eda68f2 100644 if (EVP_PKEY_assign_DSA(pkey, dsa)) { RETURN_RESOURCE(zend_list_insert(pkey, le_key TSRMLS_CC)); } -@@ -3659,11 +3788,7 @@ PHP_FUNCTION(openssl_pkey_new) +@@ -3659,11 +3938,7 @@ PHP_FUNCTION(openssl_pkey_new) if (pkey) { DH *dh = DH_new(); if (dh) { @@ -438,7 +633,20 @@ index a78a8fb..eda68f2 100644 if (EVP_PKEY_assign_DH(pkey, dh)) { RETURN_RESOURCE(zend_list_insert(pkey, le_key TSRMLS_CC)); } -@@ -3738,7 +3863,7 @@ PHP_FUNCTION(openssl_pkey_export_to_file) +@@ -3738,10 +4013,10 @@ PHP_FUNCTION(openssl_pkey_export_to_file) + cipher = NULL; + } + +- switch (EVP_PKEY_type(key->type)) { ++ switch (EVP_PKEY_base_id(key)) { + #ifdef HAVE_EVP_PKEY_EC + case EVP_PKEY_EC: +- pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get1_EC_KEY(key), cipher, (unsigned char *)passphrase, passphrase_len, NULL, NULL); ++ pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(key), cipher, (unsigned char *)passphrase, passphrase_len, NULL, NULL); + break; + #endif + default: +@@ -3807,7 +4082,7 @@ PHP_FUNCTION(openssl_pkey_export) cipher = NULL; } @@ -447,16 +655,7 @@ index a78a8fb..eda68f2 100644 #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get1_EC_KEY(key), cipher, (unsigned char *)passphrase, passphrase_len, NULL, NULL); -@@ -3807,7 +3932,7 @@ PHP_FUNCTION(openssl_pkey_export) - cipher = NULL; - } - -- switch (EVP_PKEY_type(key->type)) { -+ switch (EVP_PKEY_base_id(key)) { - #ifdef HAVE_EVP_PKEY_EC - case EVP_PKEY_EC: - pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get1_EC_KEY(key), cipher, (unsigned char *)passphrase, passphrase_len, NULL, NULL); -@@ -3928,68 +4053,88 @@ PHP_FUNCTION(openssl_pkey_get_details) +@@ -3928,25 +4203,33 @@ PHP_FUNCTION(openssl_pkey_get_details) /*TODO: Use the real values once the openssl constants are used * See the enum at the top of this file */ @@ -480,7 +679,6 @@ index a78a8fb..eda68f2 100644 - OPENSSL_PKEY_GET_BN(rsa, dmq1); - OPENSSL_PKEY_GET_BN(rsa, iqmp); - add_assoc_zval(return_value, "rsa", rsa); -- } + { + RSA *rsa = EVP_PKEY_get0_RSA(pkey); + ktype = OPENSSL_KEYTYPE_RSA; @@ -505,10 +703,10 @@ index a78a8fb..eda68f2 100644 + OPENSSL_PKEY_GET_BN(z_rsa, iqmp); + add_assoc_zval(return_value, "rsa", z_rsa); + } -+ } + } break; - case EVP_PKEY_DSA: +@@ -3954,42 +4237,55 @@ PHP_FUNCTION(openssl_pkey_get_details) case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: @@ -525,7 +723,6 @@ index a78a8fb..eda68f2 100644 - OPENSSL_PKEY_GET_BN(dsa, priv_key); - OPENSSL_PKEY_GET_BN(dsa, pub_key); - add_assoc_zval(return_value, "dsa", dsa); -- } + { + DSA *dsa = EVP_PKEY_get0_DSA(pkey); + ktype = OPENSSL_KEYTYPE_DSA; @@ -546,7 +743,7 @@ index a78a8fb..eda68f2 100644 + OPENSSL_PKEY_GET_BN(z_dsa, pub_key); + add_assoc_zval(return_value, "dsa", z_dsa); + } -+ } + } break; case EVP_PKEY_DH: - @@ -562,8 +759,6 @@ index a78a8fb..eda68f2 100644 - OPENSSL_PKEY_GET_BN(dh, priv_key); - OPENSSL_PKEY_GET_BN(dh, pub_key); - add_assoc_zval(return_value, "dh", dh); -- } -- + { + DH *dh = EVP_PKEY_get0_DH(pkey); + ktype = OPENSSL_KEYTYPE_DH; @@ -583,7 +778,8 @@ index a78a8fb..eda68f2 100644 + OPENSSL_PKEY_GET_BN(z_dh, pub_key); + add_assoc_zval(return_value, "dh", z_dh); + } -+ } + } + break; #ifdef HAVE_EVP_PKEY_EC case EVP_PKEY_EC: @@ -593,7 +789,7 @@ index a78a8fb..eda68f2 100644 zval *ec; const EC_GROUP *ec_group; int nid; -@@ -4546,13 +4691,13 @@ PHP_FUNCTION(openssl_private_encrypt) +@@ -4546,13 +4842,13 @@ PHP_FUNCTION(openssl_private_encrypt) cryptedlen = EVP_PKEY_size(pkey); cryptedbuf = emalloc(cryptedlen + 1); @@ -605,11 +801,11 @@ index a78a8fb..eda68f2 100644 (unsigned char *)data, cryptedbuf, - pkey->pkey.rsa, -+ EVP_PKEY_get0_RSA(pkey), ++ EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: -@@ -4604,13 +4749,13 @@ PHP_FUNCTION(openssl_private_decrypt) +@@ -4604,13 +4900,13 @@ PHP_FUNCTION(openssl_private_decrypt) cryptedlen = EVP_PKEY_size(pkey); crypttemp = emalloc(cryptedlen + 1); @@ -621,11 +817,11 @@ index a78a8fb..eda68f2 100644 (unsigned char *)data, crypttemp, - pkey->pkey.rsa, -+ EVP_PKEY_get0_RSA(pkey), ++ EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { cryptedbuf = emalloc(cryptedlen + 1); -@@ -4669,13 +4814,13 @@ PHP_FUNCTION(openssl_public_encrypt) +@@ -4669,13 +4965,13 @@ PHP_FUNCTION(openssl_public_encrypt) cryptedlen = EVP_PKEY_size(pkey); cryptedbuf = emalloc(cryptedlen + 1); @@ -637,11 +833,11 @@ index a78a8fb..eda68f2 100644 (unsigned char *)data, cryptedbuf, - pkey->pkey.rsa, -+ EVP_PKEY_get0_RSA(pkey), ++ EVP_PKEY_get0_RSA(pkey), padding) == cryptedlen); break; default: -@@ -4728,13 +4873,13 @@ PHP_FUNCTION(openssl_public_decrypt) +@@ -4728,13 +5024,13 @@ PHP_FUNCTION(openssl_public_decrypt) cryptedlen = EVP_PKEY_size(pkey); crypttemp = emalloc(cryptedlen + 1); @@ -653,11 +849,11 @@ index a78a8fb..eda68f2 100644 (unsigned char *)data, crypttemp, - pkey->pkey.rsa, -+ EVP_PKEY_get0_RSA(pkey), ++ EVP_PKEY_get0_RSA(pkey), padding); if (cryptedlen != -1) { cryptedbuf = emalloc(cryptedlen + 1); -@@ -4798,7 +4943,7 @@ PHP_FUNCTION(openssl_sign) +@@ -4798,7 +5094,7 @@ PHP_FUNCTION(openssl_sign) long keyresource = -1; char * data; int data_len; @@ -666,7 +862,7 @@ index a78a8fb..eda68f2 100644 zval *method = NULL; long signature_algo = OPENSSL_ALGO_SHA1; const EVP_MD *mdtype; -@@ -4831,9 +4976,11 @@ PHP_FUNCTION(openssl_sign) +@@ -4831,9 +5127,10 @@ PHP_FUNCTION(openssl_sign) siglen = EVP_PKEY_size(pkey); sigbuf = emalloc(siglen + 1); @@ -674,14 +870,13 @@ index a78a8fb..eda68f2 100644 - EVP_SignUpdate(&md_ctx, data, data_len); - if (EVP_SignFinal (&md_ctx, sigbuf,(unsigned int *)&siglen, pkey)) { + md_ctx = EVP_MD_CTX_create(); -+ if (md_ctx != NULL && -+ EVP_SignInit(md_ctx, mdtype) && -+ EVP_SignUpdate(md_ctx, data, data_len) && -+ EVP_SignFinal(md_ctx, sigbuf,(unsigned int *)&siglen, pkey)) { ++ EVP_SignInit(md_ctx, mdtype); ++ EVP_SignUpdate(md_ctx, data, data_len); ++ if (EVP_SignFinal (md_ctx, sigbuf,(unsigned int *)&siglen, pkey)) { zval_dtor(signature); sigbuf[siglen] = '\0'; ZVAL_STRINGL(signature, (char *)sigbuf, siglen, 0); -@@ -4842,7 +4989,7 @@ PHP_FUNCTION(openssl_sign) +@@ -4842,7 +5139,7 @@ PHP_FUNCTION(openssl_sign) efree(sigbuf); RETVAL_FALSE; } @@ -690,18 +885,16 @@ index a78a8fb..eda68f2 100644 if (keyresource == -1) { EVP_PKEY_free(pkey); } -@@ -4855,8 +5002,8 @@ PHP_FUNCTION(openssl_verify) - { +@@ -4856,7 +5153,7 @@ PHP_FUNCTION(openssl_verify) zval **key; EVP_PKEY *pkey; -- int err; + int err; - EVP_MD_CTX md_ctx; -+ int err = 0; -+ EVP_MD_CTX *md_ctx; ++ EVP_MD_CTX *md_ctx; const EVP_MD *mdtype; long keyresource = -1; char * data; int data_len; -@@ -4890,10 +5037,13 @@ PHP_FUNCTION(openssl_verify) +@@ -4890,10 +5187,11 @@ PHP_FUNCTION(openssl_verify) RETURN_FALSE; } @@ -710,16 +903,14 @@ index a78a8fb..eda68f2 100644 - err = EVP_VerifyFinal (&md_ctx, (unsigned char *)signature, signature_len, pkey); - EVP_MD_CTX_cleanup(&md_ctx); + md_ctx = EVP_MD_CTX_create(); -+ if (md_ctx) { -+ EVP_VerifyInit (md_ctx, mdtype); -+ EVP_VerifyUpdate (md_ctx, data, data_len); -+ err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature, signature_len, pkey); -+ } ++ EVP_VerifyInit (md_ctx, mdtype); ++ EVP_VerifyUpdate (md_ctx, data, data_len); ++ err = EVP_VerifyFinal (md_ctx, (unsigned char *)signature, signature_len, pkey); + EVP_MD_CTX_destroy(md_ctx); if (keyresource == -1) { EVP_PKEY_free(pkey); -@@ -4917,7 +5067,7 @@ PHP_FUNCTION(openssl_seal) +@@ -4917,7 +5215,7 @@ PHP_FUNCTION(openssl_seal) char *method =NULL; int method_len = 0; const EVP_CIPHER *cipher; @@ -728,7 +919,15 @@ index a78a8fb..eda68f2 100644 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szza/|s", &data, &data_len, &sealdata, &ekeys, &pubkeys, &method, &method_len) == FAILURE) { return; -@@ -4967,9 +5117,10 @@ PHP_FUNCTION(openssl_seal) +@@ -4950,6 +5248,7 @@ PHP_FUNCTION(openssl_seal) + memset(eks, 0, sizeof(*eks) * nkeys); + key_resources = safe_emalloc(nkeys, sizeof(long), 0); + memset(key_resources, 0, sizeof(*key_resources) * nkeys); ++ memset(pkeys, 0, sizeof(*pkeys) * nkeys); + + /* get the public keys we are using to seal this data */ + zend_hash_internal_pointer_reset_ex(pubkeysht, &pos); +@@ -4967,27 +5266,28 @@ PHP_FUNCTION(openssl_seal) i++; } @@ -741,7 +940,10 @@ index a78a8fb..eda68f2 100644 goto clean_exit; } -@@ -4979,15 +5130,15 @@ PHP_FUNCTION(openssl_seal) + #if 0 + /* Need this if allow ciphers that require initialization vector */ +- ivlen = EVP_CIPHER_CTX_iv_length(&ctx); ++ ivlen = EVP_CIPHER_CTX_iv_length(ctx); iv = ivlen ? emalloc(ivlen + 1) : NULL; #endif /* allocate one byte extra to make room for \0 */ @@ -763,7 +965,7 @@ index a78a8fb..eda68f2 100644 goto clean_exit; } -@@ -5018,7 +5169,7 @@ PHP_FUNCTION(openssl_seal) +@@ -5018,7 +5318,7 @@ PHP_FUNCTION(openssl_seal) efree(buf); } RETVAL_LONG(len1 + len2); @@ -772,7 +974,7 @@ index a78a8fb..eda68f2 100644 clean_exit: for (i=0; i password_len) { - key = emalloc(keylen); -@@ -5262,19 +5424,19 @@ PHP_FUNCTION(openssl_encrypt) - outlen = data_len + EVP_CIPHER_block_size(cipher_type); - outbuf = safe_emalloc(outlen, 1, 1); - -- EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL); + EVP_EncryptInit(cipher_ctx, cipher_type, NULL, NULL); if (password_len > keylen) { - EVP_CIPHER_CTX_set_key_length(&cipher_ctx, password_len); @@ -883,16 +1076,17 @@ index a78a8fb..eda68f2 100644 outlen += i; if (options & OPENSSL_RAW_DATA) { outbuf[outlen] = '\0'; -@@ -5301,7 +5463,7 @@ PHP_FUNCTION(openssl_encrypt) +@@ -5301,7 +5610,8 @@ PHP_FUNCTION(openssl_encrypt) if (free_iv) { efree(iv); } - EVP_CIPHER_CTX_cleanup(&cipher_ctx); ++ EVP_CIPHER_CTX_cleanup(cipher_ctx); + EVP_CIPHER_CTX_free(cipher_ctx); } /* }}} */ -@@ -5313,7 +5475,7 @@ PHP_FUNCTION(openssl_decrypt) +@@ -5313,7 +5623,7 @@ PHP_FUNCTION(openssl_decrypt) char *data, *method, *password, *iv = ""; int data_len, method_len, password_len, iv_len = 0; const EVP_CIPHER *cipher_type; @@ -901,29 +1095,17 @@ index a78a8fb..eda68f2 100644 int i, outlen, keylen; unsigned char *outbuf, *key; int base64_str_len; -@@ -5335,10 +5497,17 @@ PHP_FUNCTION(openssl_decrypt) - RETURN_FALSE; - } +@@ -5359,17 +5669,23 @@ PHP_FUNCTION(openssl_decrypt) + outlen = data_len + EVP_CIPHER_block_size(cipher_type); + outbuf = emalloc(outlen + 1); +- EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL); + cipher_ctx = EVP_CIPHER_CTX_new(); + if (!cipher_ctx) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create cipher context"); + RETURN_FALSE; + } -+ - if (!(options & OPENSSL_RAW_DATA)) { - base64_str = (char*)php_base64_decode((unsigned char*)data, data_len, &base64_str_len); - if (!base64_str) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to base64 decode the input"); -+ EVP_CIPHER_CTX_free(cipher_ctx); - RETURN_FALSE; - } - data_len = base64_str_len; -@@ -5359,17 +5528,17 @@ PHP_FUNCTION(openssl_decrypt) - outlen = data_len + EVP_CIPHER_block_size(cipher_type); - outbuf = emalloc(outlen + 1); - -- EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL); ++ + EVP_DecryptInit(cipher_ctx, cipher_type, NULL, NULL); if (password_len > keylen) { - EVP_CIPHER_CTX_set_key_length(&cipher_ctx, password_len); @@ -943,16 +1125,17 @@ index a78a8fb..eda68f2 100644 outlen += i; outbuf[outlen] = '\0'; RETVAL_STRINGL((char *)outbuf, outlen, 0); -@@ -5386,7 +5555,7 @@ PHP_FUNCTION(openssl_decrypt) +@@ -5386,7 +5702,8 @@ PHP_FUNCTION(openssl_decrypt) if (base64_str) { efree(base64_str); } - EVP_CIPHER_CTX_cleanup(&cipher_ctx); -+ EVP_CIPHER_CTX_free(cipher_ctx); ++ EVP_CIPHER_CTX_cleanup(cipher_ctx); ++ EVP_CIPHER_CTX_free(cipher_ctx); } /* }}} */ -@@ -5424,6 +5593,7 @@ PHP_FUNCTION(openssl_dh_compute_key) +@@ -5424,6 +5741,7 @@ PHP_FUNCTION(openssl_dh_compute_key) zval *key; char *pub_str; int pub_len; @@ -960,22 +1143,22 @@ index a78a8fb..eda68f2 100644 EVP_PKEY *pkey; BIGNUM *pub; char *data; -@@ -5433,14 +5603,20 @@ PHP_FUNCTION(openssl_dh_compute_key) +@@ -5433,14 +5751,21 @@ PHP_FUNCTION(openssl_dh_compute_key) return; } ZEND_FETCH_RESOURCE(pkey, EVP_PKEY *, &key, -1, "OpenSSL key", le_key); - if (!pkey || EVP_PKEY_type(pkey->type) != EVP_PKEY_DH || !pkey->pkey.dh) { -+ if (!pkey) { - RETURN_FALSE; - } -- ++ if (pkey == NULL) { ++ RETURN_FALSE; ++ } + if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DH) { + RETURN_FALSE; + } + dh = EVP_PKEY_get0_DH(pkey); + if (dh == NULL) { -+ RETURN_FALSE; -+ } + RETURN_FALSE; + } + pub = BN_bin2bn((unsigned char*)pub_str, pub_len, NULL); - data = emalloc(DH_size(pkey->pkey.dh) + 1); @@ -985,36 +1168,8 @@ index a78a8fb..eda68f2 100644 if (len >= 0) { data[len] = 0; -diff --git a/ext/openssl/tests/001.phpt b/ext/openssl/tests/001.phpt -index 4ca9970..2d0aa90 100644 ---- a/ext/openssl/tests/001.phpt -+++ b/ext/openssl/tests/001.phpt -@@ -18,19 +18,20 @@ for ($z = "", $i = 0; $i < 1024; $i++) { - usleep($i); - } - --$privkey = openssl_pkey_new(); -+$conf = array('config' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'openssl.cnf'); -+$privkey = openssl_pkey_new($conf); - - if ($privkey === false) - die("failed to create private key"); - - $passphrase = "banana"; --$key_file_name = tempnam("/tmp", "ssl"); -+$key_file_name = tempnam(sys_get_temp_dir(), "ssl"); - if ($key_file_name === false) - die("failed to get a temporary filename!"); - - echo "Export key to file\n"; - --openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase) or die("failed to export to file $key_file_name"); -+openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase, $conf) or die("failed to export to file $key_file_name"); - - echo "Load key from file - array syntax\n"; - diff --git a/ext/openssl/tests/bug41033.phpt b/ext/openssl/tests/bug41033.phpt -index 4aeae66..4e9bea3 100644 +index 4aeae66..50c78fe 100644 --- a/ext/openssl/tests/bug41033.phpt +++ b/ext/openssl/tests/bug41033.phpt @@ -13,11 +13,11 @@ $pub = 'file://' . dirname(__FILE__) . '/' . 'bug41033pub.pem'; @@ -1022,17 +1177,17 @@ index 4aeae66..4e9bea3 100644 $prkeyid = openssl_get_privatekey($prv, "1234"); $ct = "Hello I am some text!"; -openssl_sign($ct, $signature, $prkeyid, OPENSSL_ALGO_DSS1); -+openssl_sign($ct, $signature, $prkeyid, OPENSSL_ALGO_SHA1); ++openssl_sign($ct, $signature, $prkeyid, OPENSSL_VERSION_NUMBER < 0x10100000 ? OPENSSL_ALGO_DSS1 : OPENSSL_ALGO_SHA1); echo "Signature: ".base64_encode($signature) . "\n"; $pukeyid = openssl_get_publickey($pub); -$valid = openssl_verify($ct, $signature, $pukeyid, OPENSSL_ALGO_DSS1); -+$valid = openssl_verify($ct, $signature, $pukeyid, OPENSSL_ALGO_SHA1); ++$valid = openssl_verify($ct, $signature, $pukeyid, OPENSSL_VERSION_NUMBER < 0x10100000 ? OPENSSL_ALGO_DSS1 : OPENSSL_ALGO_SHA1); echo "Signature validity: " . $valid . "\n"; diff --git a/ext/openssl/tests/bug66501.phpt b/ext/openssl/tests/bug66501.phpt -index 7ad5e21..99ac4f5 100644 +index 7ad5e21..c2146ab 100644 --- a/ext/openssl/tests/bug66501.phpt +++ b/ext/openssl/tests/bug66501.phpt @@ -16,7 +16,7 @@ AwEHoUQDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNWVugYFtPg/xLQw0mHkIPZ4DvK @@ -1040,106 +1195,86 @@ index 7ad5e21..99ac4f5 100644 -----END EC PRIVATE KEY-----'; $key = openssl_pkey_get_private($pkey); -$res = openssl_sign($data ='alpha', $sign, $key, 'ecdsa-with-SHA1'); -+$res = openssl_sign($data ='alpha', $sign, $key, 'SHA1'); ++$res = openssl_sign($data ='alpha', $sign, $key, OPENSSL_VERSION_NUMBER < 0x10100000 ? 'ecdsa-with-SHA1' : 'SHA1'); var_dump($res); --EXPECTF-- bool(true) diff --git a/ext/openssl/tests/openssl_error_string_basic.phpt b/ext/openssl/tests/openssl_error_string_basic.phpt -index 82f3099..04cc550 100644 +index 82f3099..d94048d 100644 --- a/ext/openssl/tests/openssl_error_string_basic.phpt +++ b/ext/openssl/tests/openssl_error_string_basic.phpt -@@ -89,7 +89,7 @@ expect_openssl_errors('openssl_pkey_export_to_file opening', ['02001002', '2006D - expect_openssl_errors('openssl_pkey_export_to_file pem', ['0906D06C']); - // file to export cannot be written - @openssl_pkey_export_to_file($private_key_file, $invalid_file_for_write); --expect_openssl_errors('openssl_pkey_export_to_file write', ['2006D002', '09072007']); -+expect_openssl_errors('openssl_pkey_export_to_file write', ['2006D002']); - // succesful export - @openssl_pkey_export($private_key_file_with_pass, $out, 'wrong pwd'); - expect_openssl_errors('openssl_pkey_export', ['06065064', '0906A065']); @@ -105,7 +105,7 @@ expect_openssl_errors('openssl_private_decrypt', ['04065072']); // public encrypt and decrypt with failed padding check and padding @openssl_public_encrypt("data", $crypted, $public_key_file, 1000); @openssl_public_decrypt("data", $crypted, $public_key_file); -expect_openssl_errors('openssl_private_(en|de)crypt padding', ['0906D06C', '04068076', '0407006A', '04067072']); -+expect_openssl_errors('openssl_private_(en|de)crypt padding', ['0906D06C', '04068076', '04067072']); ++expect_openssl_errors('openssl_private_(en|de)crypt padding', OPENSSL_VERSION_NUMBER < 0x10100000 ? ['0906D06C', '04068076', '0407006A', '04067072'] : ['0906D06C', '04068076', '04067072']); // X509 echo "X509 errors\n"; -@@ -126,7 +126,7 @@ expect_openssl_errors('openssl_x509_checkpurpose purpose', ['0B086079']); - echo "CSR errors\n"; - // file for csr (file:///) fails when opennig (BIO_new_file) - @openssl_csr_get_subject("file://" . $invalid_file_for_read); --expect_openssl_errors('openssl_csr_get_subject open', ['02001002', '2006D080', '20068079', '0906D06C']); -+expect_openssl_errors('openssl_csr_get_subject open', ['02001002', '2006D080']); - // file or str csr is not correct PEM - failing PEM_read_bio_X509_REQ - @openssl_csr_get_subject($crt_file); - expect_openssl_errors('openssl_csr_get_subjec pem', ['0906D06C']); diff --git a/ext/openssl/tests/sni_server.phpt b/ext/openssl/tests/sni_server.phpt -index d44a69f..2d045df 100644 +index d44a69f..ef23258 100644 --- a/ext/openssl/tests/sni_server.phpt +++ b/ext/openssl/tests/sni_server.phpt -@@ -3,6 +3,8 @@ sni_server - --SKIPIF-- - false, ++ 'verify_peer_name' => false, ++ 'allow_self_signed' => true, + 'cafile' => __DIR__ . '/sni_server_ca.pem', + 'capture_peer_cert' => true + ]; diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c -index d549033..589dc8a 100644 +index d549033..c2d477c 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c -@@ -935,13 +935,9 @@ static int set_local_cert(SSL_CTX *ctx, php_stream *stream TSRMLS_DC) /* {{{ */ +@@ -935,7 +935,7 @@ static int set_local_cert(SSL_CTX *ctx, php_stream *stream TSRMLS_DC) /* {{{ */ static const SSL_METHOD *php_select_crypto_method(long method_value, int is_client TSRMLS_DC) /* {{{ */ { if (method_value == STREAM_CRYPTO_METHOD_SSLv2) { -#ifndef OPENSSL_NO_SSL2 -- return is_client ? SSLv2_client_method() : SSLv2_server_method(); --#else ++#if !defined(OPENSSL_NO_SSL2) && OPENSSL_VERSION_NUMBER < 0x10100000L + return is_client ? SSLv2_client_method() : SSLv2_server_method(); + #else php_error_docref(NULL TSRMLS_CC, E_WARNING, - "SSLv2 support is not compiled into the OpenSSL library PHP is linked against"); - return NULL; --#endif - } else if (method_value == STREAM_CRYPTO_METHOD_SSLv3) { - #ifndef OPENSSL_NO_SSL3 - return is_client ? SSLv3_client_method() : SSLv3_server_method(); -@@ -980,11 +976,6 @@ static long php_get_crypto_method_ctx_flags(long method_flags TSRMLS_DC) /* {{{ +@@ -1588,12 +1588,26 @@ int php_openssl_setup_crypto(php_stream *stream, + } + /* }}} */ + ++#define PHP_SSL_MAX_VERSION_LEN 32 ++ ++static char *php_ssl_cipher_get_version(const SSL_CIPHER *c, char *buffer, size_t max_len) /* {{{ */ ++{ ++ const char *version = SSL_CIPHER_get_version(c); ++ strncpy(buffer, version, max_len); ++ if (max_len <= strlen(version)) { ++ buffer[max_len - 1] = 0; ++ } ++ return buffer; ++} ++/* }}} */ ++ + static zval *capture_session_meta(SSL *ssl_handle) /* {{{ */ { - long ssl_ctx_options = SSL_OP_ALL; + zval *meta_arr; + char *proto_str; + long proto = SSL_version(ssl_handle); + const SSL_CIPHER *cipher = SSL_get_current_cipher(ssl_handle); ++ char version_str[PHP_SSL_MAX_VERSION_LEN]; --#ifndef OPENSSL_NO_SSL2 -- if (!(method_flags & STREAM_CRYPTO_METHOD_SSLv2)) { -- ssl_ctx_options |= SSL_OP_NO_SSLv2; -- } --#endif - #ifndef OPENSSL_NO_SSL3 - if (!(method_flags & STREAM_CRYPTO_METHOD_SSLv3)) { - ssl_ctx_options |= SSL_OP_NO_SSLv3; -@@ -1602,7 +1593,6 @@ static zval *capture_session_meta(SSL *ssl_handle) /* {{{ */ - #endif - case TLS1_VERSION: proto_str = "TLSv1"; break; - case SSL3_VERSION: proto_str = "SSLv3"; break; -- case SSL2_VERSION: proto_str = "SSLv2"; break; - default: proto_str = "UNKNOWN"; - } + switch (proto) { + #if OPENSSL_VERSION_NUMBER >= 0x10001001L +@@ -1611,7 +1625,7 @@ static zval *capture_session_meta(SSL *ssl_handle) /* {{{ */ + add_assoc_string(meta_arr, "protocol", proto_str, 1); + add_assoc_string(meta_arr, "cipher_name", (char *) SSL_CIPHER_get_name(cipher), 1); + add_assoc_long(meta_arr, "cipher_bits", SSL_CIPHER_get_bits(cipher, NULL)); +- add_assoc_string(meta_arr, "cipher_version", SSL_CIPHER_get_version(cipher), 1); ++ add_assoc_string(meta_arr, "cipher_version", php_ssl_cipher_get_version(cipher, version_str, PHP_SSL_MAX_VERSION_LEN), 1); -@@ -2416,13 +2406,8 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen, - sslsock->enable_on_connect = 1; - sslsock->method = get_crypto_method(context, STREAM_CRYPTO_METHOD_ANY_CLIENT); - } else if (strncmp(proto, "sslv2", protolen) == 0) { --#ifdef OPENSSL_NO_SSL2 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSLv2 support is not compiled into the OpenSSL library PHP is linked against"); - return NULL; --#else -- sslsock->enable_on_connect = 1; -- sslsock->method = STREAM_CRYPTO_METHOD_SSLv2_CLIENT; --#endif - } else if (strncmp(proto, "sslv3", protolen) == 0) { - #ifdef OPENSSL_NO_SSL3 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSLv3 support is not compiled into the OpenSSL library PHP is linked against"); + return meta_arr; + } diff --git a/ext/phar/util.c b/ext/phar/util.c index 828be8f..06e4e55 100644 --- a/ext/phar/util.c @@ -1193,6 +1328,3 @@ index 828be8f..06e4e55 100644 #endif *signature_len = phar_hex_str((const char*)sig, sig_len, signature TSRMLS_CC); --- -2.9.4 - diff --git a/dev-lang/php/php-5.6.38.ebuild b/dev-lang/php/php-5.6.38-r1.ebuild similarity index 99% rename from dev-lang/php/php-5.6.38.ebuild rename to dev-lang/php/php-5.6.38-r1.ebuild index 7a39c66..23b4656 100644 --- a/dev-lang/php/php-5.6.38.ebuild +++ b/dev-lang/php/php-5.6.38-r1.ebuild @@ -1,4 +1,4 @@ -# Copyright 1999-2018 Gentoo Foundation +# Copyright 1999-2018 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=6