36
36
#include <openssl/ssl.h>
37
37
#include <openssl/pkcs12.h>
38
38
#else
39
- static int phar_call_openssl_signverify (int is_sign , php_stream * fp , zend_off_t end , char * key , size_t key_len , char * * signature , size_t * signature_len , uint32_t sig_type );
39
+ static zend_result phar_call_openssl_signverify (bool is_sign , php_stream * fp , zend_off_t end , char * key , size_t key_len , char * * signature , size_t * signature_len , uint32_t sig_type );
40
40
#endif
41
41
42
42
/* for links to relative location, prepend cwd of the entry */
@@ -1427,14 +1427,23 @@ static int phar_hex_str(const char *digest, size_t digest_len, char **signature)
1427
1427
/* }}} */
1428
1428
1429
1429
#ifndef PHAR_HAVE_OPENSSL
1430
- static int phar_call_openssl_signverify (int is_sign , php_stream * fp , zend_off_t end , char * key , size_t key_len , char * * signature , size_t * signature_len , uint32_t sig_type ) /* {{{ */
1430
+ static zend_result phar_call_openssl_signverify (bool is_sign , php_stream * fp , zend_off_t end , char * key , size_t key_len , char * * signature , size_t * signature_len , uint32_t sig_type ) /* {{{ */
1431
1431
{
1432
- zend_fcall_info fci ;
1433
- zend_fcall_info_cache fcc ;
1434
- zval retval , zp [4 ], openssl ;
1432
+ zval retval , zp [4 ];
1435
1433
zend_string * str ;
1436
1434
1437
- ZVAL_STRINGL (& openssl , is_sign ? "openssl_sign" : "openssl_verify" , is_sign ? sizeof ("openssl_sign" )- 1 : sizeof ("openssl_verify" )- 1 );
1435
+ zend_function * fn = NULL ;
1436
+ if (is_sign ) {
1437
+ fn = zend_hash_str_find_ptr (CG (function_table ), ZEND_STRL ("openssl_sign" ));
1438
+ } else {
1439
+ fn = zend_hash_str_find_ptr (CG (function_table ), ZEND_STRL ("openssl_verify" ));
1440
+ }
1441
+
1442
+ /* OpenSSL is not available, even as a shared module */
1443
+ if (fn == NULL ) {
1444
+ return FAILURE ;
1445
+ }
1446
+
1438
1447
if (* signature_len ) {
1439
1448
ZVAL_STRINGL (& zp [1 ], * signature , * signature_len );
1440
1449
} else {
@@ -1461,20 +1470,9 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
1461
1470
zval_ptr_dtor_str (& zp [0 ]);
1462
1471
zval_ptr_dtor_str (& zp [1 ]);
1463
1472
zval_ptr_dtor_str (& zp [2 ]);
1464
- zval_ptr_dtor_str (& openssl );
1465
- return FAILURE ;
1466
- }
1467
-
1468
- if (FAILURE == zend_fcall_info_init (& openssl , 0 , & fci , & fcc , NULL , NULL )) {
1469
- zval_ptr_dtor_str (& zp [0 ]);
1470
- zval_ptr_dtor_str (& zp [1 ]);
1471
- zval_ptr_dtor_str (& zp [2 ]);
1472
- zval_ptr_dtor_str (& openssl );
1473
1473
return FAILURE ;
1474
1474
}
1475
1475
1476
- fci .param_count = 4 ;
1477
- fci .params = zp ;
1478
1476
Z_ADDREF (zp [0 ]);
1479
1477
if (is_sign ) {
1480
1478
ZVAL_NEW_REF (& zp [1 ], & zp [1 ]);
@@ -1483,17 +1481,8 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
1483
1481
}
1484
1482
Z_ADDREF (zp [2 ]);
1485
1483
1486
- fci .retval = & retval ;
1487
-
1488
- if (FAILURE == zend_call_function (& fci , & fcc )) {
1489
- zval_ptr_dtor_str (& zp [0 ]);
1490
- zval_ptr_dtor (& zp [1 ]);
1491
- zval_ptr_dtor_str (& zp [2 ]);
1492
- zval_ptr_dtor_str (& openssl );
1493
- return FAILURE ;
1494
- }
1484
+ zend_call_known_function (fn , NULL , NULL , & retval , /* param_count */ 4 , zp , NULL );
1495
1485
1496
- zval_ptr_dtor_str (& openssl );
1497
1486
Z_DELREF (zp [0 ]);
1498
1487
1499
1488
if (is_sign ) {
@@ -1507,7 +1496,6 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
1507
1496
zval_ptr_dtor_str (& zp [2 ]);
1508
1497
1509
1498
switch (Z_TYPE (retval )) {
1510
- default :
1511
1499
case IS_LONG :
1512
1500
zval_ptr_dtor (& zp [1 ]);
1513
1501
if (1 == Z_LVAL (retval )) {
@@ -1520,6 +1508,7 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
1520
1508
zval_ptr_dtor (& zp [1 ]);
1521
1509
return SUCCESS ;
1522
1510
case IS_FALSE :
1511
+ default :
1523
1512
zval_ptr_dtor (& zp [1 ]);
1524
1513
return FAILURE ;
1525
1514
}
@@ -1585,7 +1574,7 @@ zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t s
1585
1574
#ifndef PHAR_HAVE_OPENSSL
1586
1575
tempsig = sig_len ;
1587
1576
1588
- if (FAILURE == phar_call_openssl_signverify (0 , fp , end_of_phar , ZSTR_VAL (pubkey ), ZSTR_LEN (pubkey ), & sig , & tempsig , sig_type )) {
1577
+ if (FAILURE == phar_call_openssl_signverify (false , fp , end_of_phar , ZSTR_VAL (pubkey ), ZSTR_LEN (pubkey ), & sig , & tempsig , sig_type )) {
1589
1578
zend_string_release_ex (pubkey , 0 );
1590
1579
1591
1580
if (error ) {
@@ -1975,7 +1964,7 @@ zend_result phar_create_signature(phar_archive_data *phar, php_stream *fp, char
1975
1964
siglen = 0 ;
1976
1965
php_stream_seek (fp , 0 , SEEK_END );
1977
1966
1978
- if (FAILURE == phar_call_openssl_signverify (1 , fp , php_stream_tell (fp ), PHAR_G (openssl_privatekey ), PHAR_G (openssl_privatekey_len ), (char * * )& sigbuf , & siglen , phar -> sig_flags )) {
1967
+ if (FAILURE == phar_call_openssl_signverify (true , fp , php_stream_tell (fp ), PHAR_G (openssl_privatekey ), PHAR_G (openssl_privatekey_len ), (char * * )& sigbuf , & siglen , phar -> sig_flags )) {
1979
1968
if (error ) {
1980
1969
spprintf (error , 0 , "unable to write phar \"%s\" with requested openssl signature" , phar -> fname );
1981
1970
}
0 commit comments