@@ -865,7 +865,7 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
865
865
zend_long cipher_algo = Z_LVAL_P (item );
866
866
const EVP_CIPHER * cipher = php_openssl_get_evp_cipher_from_algo (cipher_algo );
867
867
if (cipher == NULL ) {
868
- php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm for private key" );
868
+ php_error_docref (NULL , E_WARNING , "Unknown cipher method for private key" );
869
869
return FAILURE ;
870
870
} else {
871
871
req -> priv_key_encrypt_cipher = cipher ;
@@ -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 method " );
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 method " );
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 hashing algorithm" );
1849
1849
return NULL ;
1850
1850
} else if (!X509_digest (peer , mdtype , md , & n )) {
1851
1851
php_openssl_store_errors ();
@@ -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 ) {
@@ -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!a!p!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,17 +6477,10 @@ 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
6486
php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
@@ -6522,26 +6521,23 @@ 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
6543
php_error_docref (NULL , E_WARNING , "Unknown signature algorithm" );
@@ -6584,7 +6580,7 @@ PHP_FUNCTION(openssl_seal)
6584
6580
const EVP_CIPHER * cipher ;
6585
6581
EVP_CIPHER_CTX * ctx ;
6586
6582
6587
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "szza|sz " , & data , & data_len ,
6583
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "szza|s!z " , & data , & data_len ,
6588
6584
& sealdata , & ekeys , & pubkeys , & method , & method_len , & iv ) == FAILURE ) {
6589
6585
RETURN_THROWS ();
6590
6586
}
@@ -6610,7 +6606,7 @@ PHP_FUNCTION(openssl_seal)
6610
6606
6611
6607
iv_len = EVP_CIPHER_iv_length (cipher );
6612
6608
if (!iv && iv_len > 0 ) {
6613
- zend_argument_value_error (6 , "must provide an IV for chosen cipher algorithm " );
6609
+ zend_argument_value_error (6 , "cannot be null for the chosen cipher method " );
6614
6610
RETURN_THROWS ();
6615
6611
}
6616
6612
@@ -6715,7 +6711,7 @@ PHP_FUNCTION(openssl_open)
6715
6711
size_t method_len = 0 , iv_len = 0 ;
6716
6712
const EVP_CIPHER * cipher ;
6717
6713
6718
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "szsz|ss " , & data , & data_len , & opendata ,
6714
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "szsz|s!s! " , & data , & data_len , & opendata ,
6719
6715
& ekey , & ekey_len , & privkey , & method , & method_len , & iv , & iv_len ) == FAILURE ) {
6720
6716
RETURN_THROWS ();
6721
6717
}
@@ -6734,7 +6730,7 @@ PHP_FUNCTION(openssl_open)
6734
6730
if (method ) {
6735
6731
cipher = EVP_get_cipherbyname (method );
6736
6732
if (!cipher ) {
6737
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm " );
6733
+ php_error_docref (NULL , E_WARNING , "Unknown cipher method " );
6738
6734
RETURN_FALSE ;
6739
6735
}
6740
6736
} else {
@@ -6744,7 +6740,7 @@ PHP_FUNCTION(openssl_open)
6744
6740
cipher_iv_len = EVP_CIPHER_iv_length (cipher );
6745
6741
if (cipher_iv_len > 0 ) {
6746
6742
if (!iv ) {
6747
- zend_argument_value_error (6 , "must provide an IV for chosen cipher algorithm " );
6743
+ zend_argument_value_error (6 , "cannot be null for the chosen cipher method " );
6748
6744
RETURN_THROWS ();
6749
6745
}
6750
6746
if ((size_t )cipher_iv_len != iv_len ) {
@@ -6866,7 +6862,7 @@ PHP_FUNCTION(openssl_digest)
6866
6862
}
6867
6863
mdtype = EVP_get_digestbyname (method );
6868
6864
if (!mdtype ) {
6869
- php_error_docref (NULL , E_WARNING , "Unknown signature algorithm " );
6865
+ php_error_docref (NULL , E_WARNING , "Unknown digest method " );
6870
6866
RETURN_FALSE ;
6871
6867
}
6872
6868
@@ -7126,7 +7122,7 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
7126
7122
7127
7123
cipher_type = EVP_get_cipherbyname (method );
7128
7124
if (!cipher_type ) {
7129
- php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm " );
7125
+ php_error_docref (NULL , E_WARNING , "Unknown cipher method " );
7130
7126
return NULL ;
7131
7127
}
7132
7128
@@ -7242,7 +7238,7 @@ PHP_OPENSSL_API zend_string* php_openssl_decrypt(
7242
7238
7243
7239
cipher_type = EVP_get_cipherbyname (method );
7244
7240
if (!cipher_type ) {
7245
- php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm " );
7241
+ php_error_docref (NULL , E_WARNING , "Unknown cipher method " );
7246
7242
return NULL ;
7247
7243
}
7248
7244
@@ -7304,7 +7300,7 @@ PHP_FUNCTION(openssl_decrypt)
7304
7300
size_t data_len , method_len , password_len , iv_len = 0 , tag_len = 0 , aad_len = 0 ;
7305
7301
zend_string * ret ;
7306
7302
7307
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sss|lsss " , & data , & data_len , & method , & method_len ,
7303
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "sss|lss!s " , & data , & data_len , & method , & method_len ,
7308
7304
& password , & password_len , & options , & iv , & iv_len , & tag , & tag_len , & aad , & aad_len ) == FAILURE ) {
7309
7305
RETURN_THROWS ();
7310
7306
}
@@ -7328,7 +7324,7 @@ PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length(const char *method)
7328
7324
7329
7325
cipher_type = EVP_get_cipherbyname (method );
7330
7326
if (!cipher_type ) {
7331
- php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm " );
7327
+ php_error_docref (NULL , E_WARNING , "Unknown cipher method " );
7332
7328
return -1 ;
7333
7329
}
7334
7330
0 commit comments