@@ -719,16 +719,26 @@ static inline int php_openssl_config_check_syntax(const char * section_label, co
719
719
}
720
720
/* }}} */
721
721
722
+ static char * php_openssl_conf_get_string (
723
+ LHASH_OF (CONF_VALUE ) * conf , const char * group , const char * name ) {
724
+ char * str = CONF_get_string (conf , group , name );
725
+ if (str == NULL ) {
726
+ /* OpenSSL reports an error if a configuration value is not found.
727
+ * However, we don't want to generate errors for optional configuration. */
728
+ ERR_clear_error ();
729
+ }
730
+ return str ;
731
+ }
732
+
722
733
static int php_openssl_add_oid_section (struct php_x509_request * req ) /* {{{ */
723
734
{
724
735
char * str ;
725
736
STACK_OF (CONF_VALUE ) * sktmp ;
726
737
CONF_VALUE * cnf ;
727
738
int i ;
728
739
729
- str = CONF_get_string (req -> req_config , NULL , "oid_section" );
740
+ str = php_openssl_conf_get_string (req -> req_config , NULL , "oid_section" );
730
741
if (str == NULL ) {
731
- php_openssl_store_errors ();
732
742
return SUCCESS ;
733
743
}
734
744
sktmp = CONF_get_section (req -> req_config , str );
@@ -813,10 +823,8 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
813
823
}
814
824
815
825
/* read in the oids */
816
- str = CONF_get_string (req -> req_config , NULL , "oid_file" );
817
- if (str == NULL ) {
818
- php_openssl_store_errors ();
819
- } else if (!php_openssl_open_base_dir_chk (str )) {
826
+ str = php_openssl_conf_get_string (req -> req_config , NULL , "oid_file" );
827
+ if (str != NULL && !php_openssl_open_base_dir_chk (str )) {
820
828
BIO * oid_bio = BIO_new_file (str , PHP_OPENSSL_BIO_MODE_R (PKCS7_BINARY ));
821
829
if (oid_bio ) {
822
830
OBJ_create_objects (oid_bio );
@@ -828,11 +836,11 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
828
836
return FAILURE ;
829
837
}
830
838
SET_OPTIONAL_STRING_ARG ("digest_alg" , req -> digest_name ,
831
- CONF_get_string (req -> req_config , req -> section_name , "default_md" ));
839
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "default_md" ));
832
840
SET_OPTIONAL_STRING_ARG ("x509_extensions" , req -> extensions_section ,
833
- CONF_get_string (req -> req_config , req -> section_name , "x509_extensions" ));
841
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "x509_extensions" ));
834
842
SET_OPTIONAL_STRING_ARG ("req_extensions" , req -> request_extensions_section ,
835
- CONF_get_string (req -> req_config , req -> section_name , "req_extensions" ));
843
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "req_extensions" ));
836
844
SET_OPTIONAL_LONG_ARG ("private_key_bits" , req -> priv_key_bits ,
837
845
CONF_get_number (req -> req_config , req -> section_name , "default_bits" ));
838
846
@@ -841,11 +849,9 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
841
849
if (optional_args && (item = zend_hash_str_find (Z_ARRVAL_P (optional_args ), "encrypt_key" , sizeof ("encrypt_key" )- 1 )) != NULL ) {
842
850
req -> priv_key_encrypt = Z_TYPE_P (item ) == IS_TRUE ? 1 : 0 ;
843
851
} else {
844
- str = CONF_get_string (req -> req_config , req -> section_name , "encrypt_rsa_key" );
852
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "encrypt_rsa_key" );
845
853
if (str == NULL ) {
846
- str = CONF_get_string (req -> req_config , req -> section_name , "encrypt_key" );
847
- /* it is sure that there are some errors as str was NULL for encrypt_rsa_key */
848
- php_openssl_store_errors ();
854
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "encrypt_key" );
849
855
}
850
856
if (str != NULL && strcmp (str , "no" ) == 0 ) {
851
857
req -> priv_key_encrypt = 0 ;
@@ -873,12 +879,10 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
873
879
874
880
/* digest alg */
875
881
if (req -> digest_name == NULL ) {
876
- req -> digest_name = CONF_get_string (req -> req_config , req -> section_name , "default_md" );
882
+ req -> digest_name = php_openssl_conf_get_string (req -> req_config , req -> section_name , "default_md" );
877
883
}
878
884
if (req -> digest_name != NULL ) {
879
885
req -> digest = req -> md_alg = EVP_get_digestbyname (req -> digest_name );
880
- } else {
881
- php_openssl_store_errors ();
882
886
}
883
887
if (req -> md_alg == NULL ) {
884
888
req -> md_alg = req -> digest = EVP_sha1 ();
@@ -900,10 +904,8 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
900
904
#endif
901
905
902
906
/* set the string mask */
903
- str = CONF_get_string (req -> req_config , req -> section_name , "string_mask" );
904
- if (str == NULL ) {
905
- php_openssl_store_errors ();
906
- } else if (!ASN1_STRING_set_default_mask_asc (str )) {
907
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "string_mask" );
908
+ if (str != NULL && !ASN1_STRING_set_default_mask_asc (str )) {
907
909
php_error_docref (NULL , E_WARNING , "Invalid global string mask setting %s" , str );
908
910
return FAILURE ;
909
911
}
@@ -2836,9 +2838,8 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z
2836
2838
php_openssl_store_errors ();
2837
2839
return FAILURE ;
2838
2840
}
2839
- attr_sect = CONF_get_string (req -> req_config , req -> section_name , "attributes" );
2841
+ attr_sect = php_openssl_conf_get_string (req -> req_config , req -> section_name , "attributes" );
2840
2842
if (attr_sect == NULL ) {
2841
- php_openssl_store_errors ();
2842
2843
attr_sk = NULL ;
2843
2844
} else {
2844
2845
attr_sk = CONF_get_section (req -> req_config , attr_sect );
@@ -3660,10 +3661,7 @@ static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req
3660
3661
return NULL ;
3661
3662
}
3662
3663
3663
- randfile = CONF_get_string (req -> req_config , req -> section_name , "RANDFILE" );
3664
- if (randfile == NULL ) {
3665
- php_openssl_store_errors ();
3666
- }
3664
+ randfile = php_openssl_conf_get_string (req -> req_config , req -> section_name , "RANDFILE" );
3667
3665
php_openssl_load_rand_file (randfile , & egdsocket , & seeded );
3668
3666
3669
3667
if ((req -> priv_key = EVP_PKEY_new ()) != NULL ) {
0 commit comments