我已经找到了几篇有这个问题的帖子,但我还没有使用他们的解决方案来解决我的问题。
这是我的测试脚本:
<?php
echo "\n*** Errors before calling openssl_pkey_new\n";
// no errors
while (($e = openssl_error_string()) !== false) {
var_dump($e);
}
$config = [
'config' => '/etc/ssl/openssl.cnf',
"digest_alg" => "sha1",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
];
var_dump(openssl_pkey_new($config));
echo "\n*** Errors after calling openssl_pkey_new\n";
while (($e = openssl_error_string()) !== false) {
echo "<pre>";print_r($e);echo "</pre>";
}还尝试了sha256和sha512。
cnf文件:
ls /etc/ssl/openssl.cnf
-rw-r--r-- 1 root root 10835 Jun 20 2014 /etc/ssl/openssl.cnf错误:
error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value我也尝试过将OPENSSL_CONF设置在脚本的顶部,但没有成功:
putenv('OPENSSL_CONF=/etc/ssl/openssl.cnf');我也尝试过使用自定义的openssl.cnf,但也没有成功:
cat /var/www/openssl.cnf
distinguished_name = req_distinguished_name
[req_distinguished_name]
[v3_req]
[v3_ca]会有什么问题呢?
忽略此错误并在使用openssl_pkey_new或有解决方案后清除它们是否安全?
提前谢谢你
发布于 2018-08-30 08:25:59
对问题的分析
查看openssl_pkey_new() documentation,它提到:
有关配置的更多信息,请参阅
openssl_csr_new()。
事实证明,openssl_pkey_new()和openssl_csr_new()实现共享读取配置的代码。您可以通过扩展为php_openssl_parse_config的符号PHP_SSL_REQ_PARSE在PHP源代码here中看到它的调用。它的第一个参数是x509_request类型。(CSR是证书签名请求的缩写,详见OpenSSL req app documentation)
通过对php_openssl_parse_config实现的筛选,发现有很多尝试读取与CSR相关的配置参数,但不仅仅是密钥生成。其中许多都会失败,并生成与您所指出的相同的错误。
为了使工作更容易,我直接检测了OpenSSL加密库,以打印有关任何失败的配置字符串查找的信息。使用该设置运行脚本会产生以下结果(在Ubuntu18.04上,使用/etc/ssl/openssl.cnf中的配置):
$ php conftest.php
_CONF_get_string failed for section "(null)", name "openssl_conf"
*** Errors before calling openssl_pkey_new
_CONF_get_string failed for section "(null)", name "oid_file"
_CONF_get_string failed for section "req", name "default_md"
_CONF_get_string failed for section "req", name "req_extensions"
_CONF_get_string failed for section "req", name "encrypt_rsa_key"
_CONF_get_string failed for section "req", name "encrypt_key"
_CONF_get_string failed for section "req", name "default_md"
resource(4) of type (OpenSSL key)
*** Errors after calling openssl_pkey_new
<pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre><pre>error:0E06D06C:configuration file routines:NCONF_get_string:no value</pre>一种解决方案
从分析中可以看出,在main部分中添加设置oid_file的值,在openssl.cnf的[req]部分中添加default_md、req_extensions和encrypt_rsa_key应该可以解决错误。实际上,在这样做之后,结果如下所示。
$ php conftest.php
*** Errors before calling openssl_pkey_new
resource(4) of type (OpenSSL key)
*** Errors after calling openssl_pkey_new结论
我认为您可以安全地忽略PHP对无关配置设置的错误调用。
发布于 2019-03-01 14:46:14
在mac上更新Mojave后,我在我的系统上遇到了这个问题。
解决方案
我在我的openssl.cnf文件中取消了对下列值的注释,该文件修复了该问题
default_bits = 2048发布于 2020-02-10 16:52:57
以下是一个最低配置,您可以在默认配置的基础上使用它来消除所有这些警告:
#PHP shim for an otherwise beautiful openssl.cnf
RANDFILE = /dev/null #PHP warns if this doesn't exist
oid_file = /dev/null #PHP warns if this doesn't exist
#PHP warns if oid_section isn't in the default section
#PHP warns if oid_section is used in another section (only on initialization)
oid_section = php_oids #set an empty OID section
.include /etc/ssl/openssl.cnf #include our working conf
[ req ]
#differs from attr format
attributes = php_attr #openssl_csr_new()
#not set in include
encrypt_rsa_key = yes #encrypt_key
#uncomment to override include
#req_extensions = php_req_extension #req_extensions
#x509_extensions = php_x509_extension #x509_extensions
#default_bits = 4096 #private_key_bits
#default_md = sha512 #digest_alg
#string_mask = utf8only #string_mask
#distinguished_name = php_distinguished_name #openssl_csr_new()
[ php_attr ] #empty attributes section (supports callengePassword,unstructuredName)
[ php_oids ] #empty OID section
[ php_distinguished_name ] #empty DN section (supports both DN conf formats)
[ php_x509_extension ] #empty x509 extension section
subjectKeyIdentifier = hash #at least one value required
[ php_req_extension ] #empty req extension section
subjectKeyIdentifier = hash #at least one value requiredhttps://stackoverflow.com/questions/52076800
复制相似问题