@@ -1182,7 +1182,7 @@ PHP_MINIT_FUNCTION(openssl)
1182
1182
REGISTER_LONG_CONSTANT ("X509_PURPOSE_ANY" , X509_PURPOSE_ANY , CONST_CS |CONST_PERSISTENT );
1183
1183
#endif
1184
1184
1185
- /* signature algorithm constants */
1185
+ /* digest algorithm constants */
1186
1186
REGISTER_LONG_CONSTANT ("OPENSSL_ALGO_SHA1" , OPENSSL_ALGO_SHA1 , CONST_CS |CONST_PERSISTENT );
1187
1187
REGISTER_LONG_CONSTANT ("OPENSSL_ALGO_MD5" , OPENSSL_ALGO_MD5 , CONST_CS |CONST_PERSISTENT );
1188
1188
REGISTER_LONG_CONSTANT ("OPENSSL_ALGO_MD4" , OPENSSL_ALGO_MD4 , CONST_CS |CONST_PERSISTENT );
@@ -1563,7 +1563,7 @@ PHP_FUNCTION(openssl_spki_new)
1563
1563
mdtype = php_openssl_get_evp_md_from_algo (algo );
1564
1564
1565
1565
if (!mdtype ) {
1566
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
1566
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
1567
1567
goto cleanup ;
1568
1568
}
1569
1569
@@ -1589,7 +1589,7 @@ PHP_FUNCTION(openssl_spki_new)
1589
1589
1590
1590
if (!NETSCAPE_SPKI_sign (spki , pkey , mdtype )) {
1591
1591
php_openssl_store_errors ();
1592
- php_error_docref (NULL , E_WARNING , "Unable to sign with specified algorithm" );
1592
+ php_error_docref (NULL , E_WARNING , "Unable to sign with specified digest algorithm" );
1593
1593
goto cleanup ;
1594
1594
}
1595
1595
@@ -1845,7 +1845,7 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_b
1845
1845
zend_string * ret ;
1846
1846
1847
1847
if (!(mdtype = EVP_get_digestbyname (method ))) {
1848
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
1848
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
1849
1849
return NULL ;
1850
1850
} else if (!X509_digest (peer , mdtype , md , & n )) {
1851
1851
php_openssl_store_errors ();
@@ -2313,7 +2313,7 @@ PHP_FUNCTION(openssl_x509_checkpurpose)
2313
2313
Z_PARAM_OBJ_OF_CLASS_OR_STR (cert_obj , php_openssl_certificate_ce , cert_str )
2314
2314
Z_PARAM_LONG (purpose )
2315
2315
Z_PARAM_OPTIONAL
2316
- Z_PARAM_ARRAY_OR_NULL (zcainfo )
2316
+ Z_PARAM_ARRAY (zcainfo )
2317
2317
Z_PARAM_STRING_OR_NULL (untrusted , untrusted_len )
2318
2318
ZEND_PARSE_PARAMETERS_END ();
2319
2319
@@ -3753,7 +3753,7 @@ static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req
3753
3753
{
3754
3754
EC_KEY * eckey ;
3755
3755
if (req -> curve_name == NID_undef ) {
3756
- php_error_docref (NULL , E_WARNING , "Missing configuration value: ' curve_name' not set" );
3756
+ php_error_docref (NULL , E_WARNING , "Missing configuration value: \" curve_name\" not set" );
3757
3757
return NULL ;
3758
3758
}
3759
3759
eckey = EC_KEY_new_by_curve_name (req -> curve_name );
@@ -4465,11 +4465,13 @@ PHP_FUNCTION(openssl_pkey_get_private)
4465
4465
size_t passphrase_len = sizeof ("" )- 1 ;
4466
4466
php_openssl_pkey_object * key_object ;
4467
4467
4468
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|s" , & cert , & passphrase , & passphrase_len ) == FAILURE ) {
4468
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|s! " , & cert , & passphrase , & passphrase_len ) == FAILURE ) {
4469
4469
RETURN_THROWS ();
4470
4470
}
4471
4471
4472
- PHP_OPENSSL_CHECK_SIZE_T_TO_INT (passphrase_len , passphrase , 2 );
4472
+ if (passphrase ) {
4473
+ PHP_OPENSSL_CHECK_SIZE_T_TO_INT (passphrase_len , passphrase , 2 );
4474
+ }
4473
4475
4474
4476
pkey = php_openssl_pkey_from_zval (cert , 0 , passphrase , passphrase_len );
4475
4477
if (pkey == NULL ) {
@@ -4805,7 +4807,7 @@ PHP_FUNCTION(openssl_pbkdf2)
4805
4807
}
4806
4808
4807
4809
if (!digest ) {
4808
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
4810
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
4809
4811
RETURN_FALSE ;
4810
4812
}
4811
4813
@@ -4847,7 +4849,7 @@ PHP_FUNCTION(openssl_pkcs7_verify)
4847
4849
4848
4850
RETVAL_LONG (-1 );
4849
4851
4850
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "pl|pappp " , & filename , & filename_len ,
4852
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "pl|p!ap!p!p! " , & filename , & filename_len ,
4851
4853
& flags , & signersfilename , & signersfilename_len , & cainfo ,
4852
4854
& extracerts , & extracerts_len , & datafilename , & datafilename_len , & p7bfilename , & p7bfilename_len ) == FAILURE ) {
4853
4855
RETURN_THROWS ();
@@ -6082,7 +6084,7 @@ PHP_FUNCTION(openssl_cms_decrypt)
6082
6084
Z_PARAM_PATH (outfilename , outfilename_len )
6083
6085
Z_PARAM_ZVAL (recipcert )
6084
6086
Z_PARAM_OPTIONAL
6085
- Z_PARAM_ZVAL (recipkey )
6087
+ Z_PARAM_ZVAL_OR_NULL (recipkey )
6086
6088
Z_PARAM_LONG (encoding )
6087
6089
ZEND_PARSE_PARAMETERS_END ();
6088
6090
@@ -6128,8 +6130,7 @@ PHP_FUNCTION(openssl_cms_decrypt)
6128
6130
cms = SMIME_read_CMS (in , & datain );
6129
6131
break ;
6130
6132
default :
6131
- php_error_docref (NULL , E_WARNING ,
6132
- "Unknown OPENSSL encoding" );
6133
+ zend_argument_value_error (5 , "must be an OPENSSL_ENCODING_* constant" );
6133
6134
goto clean_exit ;
6134
6135
}
6135
6136
@@ -6456,13 +6457,18 @@ PHP_FUNCTION(openssl_sign)
6456
6457
char * data ;
6457
6458
size_t data_len ;
6458
6459
EVP_MD_CTX * md_ctx ;
6459
- zval * method = NULL ;
6460
- zend_long signature_algo = OPENSSL_ALGO_SHA1 ;
6460
+ zend_string * method_str = NULL ;
6461
+ zend_long method_long = OPENSSL_ALGO_SHA1 ;
6461
6462
const EVP_MD * mdtype ;
6462
6463
6463
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "szz|z" , & data , & data_len , & signature , & key , & method ) == FAILURE ) {
6464
- RETURN_THROWS ();
6465
- }
6464
+ ZEND_PARSE_PARAMETERS_START (3 , 4 )
6465
+ Z_PARAM_STRING (data , data_len )
6466
+ Z_PARAM_ZVAL (signature )
6467
+ Z_PARAM_ZVAL (key )
6468
+ Z_PARAM_OPTIONAL
6469
+ Z_PARAM_STR_OR_LONG (method_str , method_long )
6470
+ ZEND_PARSE_PARAMETERS_END ();
6471
+
6466
6472
pkey = php_openssl_pkey_from_zval (key , 0 , "" , 0 );
6467
6473
if (pkey == NULL) {
6468
6474
if (!EG (exception )) {
@@ -6471,20 +6477,13 @@ PHP_FUNCTION(openssl_sign)
6471
6477
RETURN_FALSE ;
6472
6478
}
6473
6479
6474
- if (method == NULL || Z_TYPE_P (method ) == IS_LONG ) {
6475
- if (method != NULL ) {
6476
- signature_algo = Z_LVAL_P (method );
6477
- }
6478
- mdtype = php_openssl_get_evp_md_from_algo (signature_algo );
6479
- } else if (Z_TYPE_P (method ) == IS_STRING ) {
6480
- mdtype = EVP_get_digestbyname (Z_STRVAL_P (method ));
6480
+ if (method_str ) {
6481
+ mdtype = EVP_get_digestbyname (ZSTR_VAL (method_str ));
6481
6482
} else {
6482
- // TODO Use proper ZPP check.
6483
- zend_argument_type_error (4 , "must be of type string|int|null, %s given" , zend_zval_type_name (method ));
6484
- RETURN_THROWS ();
6483
+ mdtype = php_openssl_get_evp_md_from_algo (method_long );
6485
6484
}
6486
6485
if (!mdtype ) {
6487
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
6486
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
6488
6487
RETURN_FALSE ;
6489
6488
}
6490
6489
@@ -6522,29 +6521,26 @@ PHP_FUNCTION(openssl_verify)
6522
6521
size_t data_len ;
6523
6522
char * signature ;
6524
6523
size_t signature_len ;
6525
- zval * method = NULL ;
6526
- zend_long signature_algo = OPENSSL_ALGO_SHA1 ;
6524
+ zend_string * method_str = NULL ;
6525
+ zend_long method_long = OPENSSL_ALGO_SHA1 ;
6527
6526
6528
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "ssz|z" , & data , & data_len , & signature , & signature_len , & key , & method ) == FAILURE ) {
6529
- RETURN_THROWS ();
6530
- }
6527
+ ZEND_PARSE_PARAMETERS_START (3 , 4 )
6528
+ Z_PARAM_STRING (data , data_len )
6529
+ Z_PARAM_STRING (signature , signature_len )
6530
+ Z_PARAM_ZVAL (key )
6531
+ Z_PARAM_OPTIONAL
6532
+ Z_PARAM_STR_OR_LONG (method_str , method_long )
6533
+ ZEND_PARSE_PARAMETERS_END ();
6531
6534
6532
6535
PHP_OPENSSL_CHECK_SIZE_T_TO_UINT (signature_len , signature , 2 );
6533
6536
6534
- if (method == NULL || Z_TYPE_P (method ) == IS_LONG ) {
6535
- if (method != NULL ) {
6536
- signature_algo = Z_LVAL_P (method );
6537
- }
6538
- mdtype = php_openssl_get_evp_md_from_algo (signature_algo );
6539
- } else if (Z_TYPE_P (method ) == IS_STRING ) {
6540
- mdtype = EVP_get_digestbyname (Z_STRVAL_P (method ));
6537
+ if (method_str ) {
6538
+ mdtype = EVP_get_digestbyname (ZSTR_VAL (method_str ));
6541
6539
} else {
6542
- // TODO Use proper ZPP check.
6543
- zend_argument_type_error (4 , "must be of type string|int|null, %s given" , zend_zval_type_name (method ));
6544
- RETURN_THROWS ();
6540
+ mdtype = php_openssl_get_evp_md_from_algo (method_long );
6545
6541
}
6546
6542
if (!mdtype ) {
6547
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
6543
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
6548
6544
RETURN_FALSE ;
6549
6545
}
6550
6546
@@ -6579,8 +6575,8 @@ PHP_FUNCTION(openssl_seal)
6579
6575
unsigned char iv_buf [EVP_MAX_IV_LENGTH + 1 ], * buf = NULL , * * eks ;
6580
6576
char * data ;
6581
6577
size_t data_len ;
6582
- char * method = NULL ;
6583
- size_t method_len = 0 ;
6578
+ char * method ;
6579
+ size_t method_len ;
6584
6580
const EVP_CIPHER * cipher ;
6585
6581
EVP_CIPHER_CTX * ctx ;
6586
6582
@@ -6600,13 +6596,13 @@ PHP_FUNCTION(openssl_seal)
6600
6596
6601
6597
cipher = EVP_get_cipherbyname (method );
6602
6598
if (!cipher ) {
6603
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
6599
+ php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm" );
6604
6600
RETURN_FALSE ;
6605
6601
}
6606
6602
6607
6603
iv_len = EVP_CIPHER_iv_length (cipher );
6608
6604
if (!iv && iv_len > 0 ) {
6609
- zend_argument_value_error (6 , "must provide an IV for chosen cipher algorithm" );
6605
+ zend_argument_value_error (6 , "cannot be null for the chosen cipher algorithm" );
6610
6606
RETURN_THROWS ();
6611
6607
}
6612
6608
@@ -6707,11 +6703,11 @@ PHP_FUNCTION(openssl_open)
6707
6703
size_t data_len ;
6708
6704
char * ekey ;
6709
6705
size_t ekey_len ;
6710
- char * method = NULL , * iv = NULL ;
6711
- size_t method_len = 0 , iv_len = 0 ;
6706
+ char * method , * iv = NULL ;
6707
+ size_t method_len , iv_len = 0 ;
6712
6708
const EVP_CIPHER * cipher ;
6713
6709
6714
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "szszs|s" , & data , & data_len , & opendata ,
6710
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "szszs|s! " , & data , & data_len , & opendata ,
6715
6711
& ekey , & ekey_len , & privkey , & method , & method_len , & iv , & iv_len ) == FAILURE ) {
6716
6712
RETURN_THROWS ();
6717
6713
}
@@ -6729,14 +6725,14 @@ PHP_FUNCTION(openssl_open)
6729
6725
6730
6726
cipher = EVP_get_cipherbyname (method );
6731
6727
if (!cipher ) {
6732
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
6728
+ php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm" );
6733
6729
RETURN_FALSE ;
6734
6730
}
6735
6731
6736
6732
cipher_iv_len = EVP_CIPHER_iv_length (cipher );
6737
6733
if (cipher_iv_len > 0 ) {
6738
6734
if (!iv ) {
6739
- zend_argument_value_error (6 , "must provide an IV for chosen cipher algorithm" );
6735
+ zend_argument_value_error (6 , "cannot be null for the chosen cipher algorithm" );
6740
6736
RETURN_THROWS ();
6741
6737
}
6742
6738
if ((size_t )cipher_iv_len != iv_len ) {
@@ -6782,7 +6778,7 @@ static void php_openssl_add_method(const OBJ_NAME *name, void *arg) /* {{{ */
6782
6778
}
6783
6779
/* }}} */
6784
6780
6785
- /* {{{ Return array of available digest methods */
6781
+ /* {{{ Return array of available digest algorithms */
6786
6782
PHP_FUNCTION (openssl_get_md_methods )
6787
6783
{
6788
6784
zend_bool aliases = 0 ;
@@ -6797,7 +6793,7 @@ PHP_FUNCTION(openssl_get_md_methods)
6797
6793
}
6798
6794
/* }}} */
6799
6795
6800
- /* {{{ Return array of available cipher methods */
6796
+ /* {{{ Return array of available cipher algorithms */
6801
6797
PHP_FUNCTION (openssl_get_cipher_methods )
6802
6798
{
6803
6799
zend_bool aliases = 0 ;
@@ -6858,7 +6854,7 @@ PHP_FUNCTION(openssl_digest)
6858
6854
}
6859
6855
mdtype = EVP_get_digestbyname (method );
6860
6856
if (!mdtype ) {
6861
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
6857
+ php_error_docref (NULL , E_WARNING , "Unknown digest algorithm" );
6862
6858
RETURN_FALSE ;
6863
6859
}
6864
6860
@@ -7012,7 +7008,7 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
7012
7008
}
7013
7009
} else if (!enc && tag && tag_len > 0 ) {
7014
7010
if (!mode -> is_aead ) {
7015
- php_error_docref (NULL , E_WARNING , "The tag cannot be used because the cipher method does not support AEAD" );
7011
+ php_error_docref (NULL , E_WARNING , "The tag cannot be used because the cipher algorithm does not support AEAD" );
7016
7012
} else if (!EVP_CIPHER_CTX_ctrl (cipher_ctx , mode -> aead_set_tag_flag , tag_len , (unsigned char * ) tag )) {
7017
7013
php_error_docref (NULL , E_WARNING , "Setting tag for AEAD cipher decryption failed" );
7018
7014
return FAILURE ;
@@ -7024,7 +7020,7 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
7024
7020
if (key_len > password_len ) {
7025
7021
if ((OPENSSL_DONT_ZERO_PAD_KEY & options ) && !EVP_CIPHER_CTX_set_key_length (cipher_ctx , password_len )) {
7026
7022
php_openssl_store_errors ();
7027
- php_error_docref (NULL , E_WARNING , "Key length cannot be set for the cipher method " );
7023
+ php_error_docref (NULL , E_WARNING , "Key length cannot be set for the cipher algorithm " );
7028
7024
return FAILURE ;
7029
7025
}
7030
7026
key = emalloc (key_len );
0 commit comments