@@ -1064,16 +1064,26 @@ static inline int php_openssl_config_check_syntax(const char * section_label, co
1064
1064
}
1065
1065
/* }}} */
1066
1066
1067
+ static char * php_openssl_conf_get_string (
1068
+ LHASH_OF (CONF_VALUE ) * conf , const char * group , const char * name ) {
1069
+ char * str = CONF_get_string (conf , group , name );
1070
+ if (str == NULL ) {
1071
+ /* OpenSSL reports an error if a configuration value is not found.
1072
+ * However, we don't want to generate errors for optional configuration. */
1073
+ ERR_clear_error ();
1074
+ }
1075
+ return str ;
1076
+ }
1077
+
1067
1078
static int php_openssl_add_oid_section (struct php_x509_request * req ) /* {{{ */
1068
1079
{
1069
1080
char * str ;
1070
1081
STACK_OF (CONF_VALUE ) * sktmp ;
1071
1082
CONF_VALUE * cnf ;
1072
1083
int i ;
1073
1084
1074
- str = CONF_get_string (req -> req_config , NULL , "oid_section" );
1085
+ str = php_openssl_conf_get_string (req -> req_config , NULL , "oid_section" );
1075
1086
if (str == NULL ) {
1076
- php_openssl_store_errors ();
1077
1087
return SUCCESS ;
1078
1088
}
1079
1089
sktmp = CONF_get_section (req -> req_config , str );
@@ -1158,10 +1168,8 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
1158
1168
}
1159
1169
1160
1170
/* read in the oids */
1161
- str = CONF_get_string (req -> req_config , NULL , "oid_file" );
1162
- if (str == NULL ) {
1163
- php_openssl_store_errors ();
1164
- } else if (!php_openssl_open_base_dir_chk (str )) {
1171
+ str = php_openssl_conf_get_string (req -> req_config , NULL , "oid_file" );
1172
+ if (str != NULL && !php_openssl_open_base_dir_chk (str )) {
1165
1173
BIO * oid_bio = BIO_new_file (str , PHP_OPENSSL_BIO_MODE_R (PKCS7_BINARY ));
1166
1174
if (oid_bio ) {
1167
1175
OBJ_create_objects (oid_bio );
@@ -1173,11 +1181,11 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
1173
1181
return FAILURE ;
1174
1182
}
1175
1183
SET_OPTIONAL_STRING_ARG ("digest_alg" , req -> digest_name ,
1176
- CONF_get_string (req -> req_config , req -> section_name , "default_md" ));
1184
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "default_md" ));
1177
1185
SET_OPTIONAL_STRING_ARG ("x509_extensions" , req -> extensions_section ,
1178
- CONF_get_string (req -> req_config , req -> section_name , "x509_extensions" ));
1186
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "x509_extensions" ));
1179
1187
SET_OPTIONAL_STRING_ARG ("req_extensions" , req -> request_extensions_section ,
1180
- CONF_get_string (req -> req_config , req -> section_name , "req_extensions" ));
1188
+ php_openssl_conf_get_string (req -> req_config , req -> section_name , "req_extensions" ));
1181
1189
SET_OPTIONAL_LONG_ARG ("private_key_bits" , req -> priv_key_bits ,
1182
1190
CONF_get_number (req -> req_config , req -> section_name , "default_bits" ));
1183
1191
@@ -1186,11 +1194,9 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
1186
1194
if (optional_args && (item = zend_hash_str_find (Z_ARRVAL_P (optional_args ), "encrypt_key" , sizeof ("encrypt_key" )- 1 )) != NULL ) {
1187
1195
req -> priv_key_encrypt = Z_TYPE_P (item ) == IS_TRUE ? 1 : 0 ;
1188
1196
} else {
1189
- str = CONF_get_string (req -> req_config , req -> section_name , "encrypt_rsa_key" );
1197
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "encrypt_rsa_key" );
1190
1198
if (str == NULL ) {
1191
- str = CONF_get_string (req -> req_config , req -> section_name , "encrypt_key" );
1192
- /* it is sure that there are some errrors as str was NULL for encrypt_rsa_key */
1193
- php_openssl_store_errors ();
1199
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "encrypt_key" );
1194
1200
}
1195
1201
if (str != NULL && strcmp (str , "no" ) == 0 ) {
1196
1202
req -> priv_key_encrypt = 0 ;
@@ -1218,12 +1224,10 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
1218
1224
1219
1225
/* digest alg */
1220
1226
if (req -> digest_name == NULL ) {
1221
- req -> digest_name = CONF_get_string (req -> req_config , req -> section_name , "default_md" );
1227
+ req -> digest_name = php_openssl_conf_get_string (req -> req_config , req -> section_name , "default_md" );
1222
1228
}
1223
1229
if (req -> digest_name != NULL ) {
1224
1230
req -> digest = req -> md_alg = EVP_get_digestbyname (req -> digest_name );
1225
- } else {
1226
- php_openssl_store_errors ();
1227
1231
}
1228
1232
if (req -> md_alg == NULL ) {
1229
1233
req -> md_alg = req -> digest = EVP_sha1 ();
@@ -1245,10 +1249,8 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
1245
1249
#endif
1246
1250
1247
1251
/* set the string mask */
1248
- str = CONF_get_string (req -> req_config , req -> section_name , "string_mask" );
1249
- if (str == NULL ) {
1250
- php_openssl_store_errors ();
1251
- } else if (!ASN1_STRING_set_default_mask_asc (str )) {
1252
+ str = php_openssl_conf_get_string (req -> req_config , req -> section_name , "string_mask" );
1253
+ if (str != NULL && !ASN1_STRING_set_default_mask_asc (str )) {
1252
1254
php_error_docref (NULL , E_WARNING , "Invalid global string mask setting %s" , str );
1253
1255
return FAILURE ;
1254
1256
}
@@ -3138,9 +3140,8 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z
3138
3140
php_openssl_store_errors ();
3139
3141
return FAILURE ;
3140
3142
}
3141
- attr_sect = CONF_get_string (req -> req_config , req -> section_name , "attributes" );
3143
+ attr_sect = php_openssl_conf_get_string (req -> req_config , req -> section_name , "attributes" );
3142
3144
if (attr_sect == NULL ) {
3143
- php_openssl_store_errors ();
3144
3145
attr_sk = NULL ;
3145
3146
} else {
3146
3147
attr_sk = CONF_get_section (req -> req_config , attr_sect );
@@ -3994,10 +3995,7 @@ static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req
3994
3995
return NULL ;
3995
3996
}
3996
3997
3997
- randfile = CONF_get_string (req -> req_config , req -> section_name , "RANDFILE" );
3998
- if (randfile == NULL ) {
3999
- php_openssl_store_errors ();
4000
- }
3998
+ randfile = php_openssl_conf_get_string (req -> req_config , req -> section_name , "RANDFILE" );
4001
3999
php_openssl_load_rand_file (randfile , & egdsocket , & seeded );
4002
4000
4003
4001
if ((req -> priv_key = EVP_PKEY_new ()) != NULL ) {
0 commit comments