"sha1", -6ren">
gpt4 book ai didi

php - openssl_pkey_new 抛出错误配置文件例程 :NCONF_get_string:no value

转载 作者:行者123 更新时间:2023-12-04 02:57:50 37 4
gpt4 key购买 nike

我发现了几个有这个问题的帖子,但我没有使用他们的解决方案解决我的问题。

这是我的测试脚本:

<?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 后忽略此错误并清除它们是否安全或有解决方案?

先感谢您

最佳答案

问题分析

看着openssl_pkey_new() documentation ,它提到:

See openssl_csr_new() for more information about configargs.



原来是 openssl_pkey_new()openssl_csr_new()实现共享读取配置的代码。您可以在 PHP 源代码 here 中看到它的调用。通过符号 PHP_SSL_REQ_PARSE扩展为 php_openssl_parse_config .它的第一个参数是 x509_request类型。 (CSR 代表证书签名请求,有关更多信息,请参阅 OpenSSL req app documentation)

筛选实现 php_openssl_parse_config ,结果证明有很多尝试读取与 CSR 相关的配置参数,而不仅仅是 key 生成。其中许多失败并产生与您指出的相同的错误。

为了让生活更轻松,我直接检测了 OpenSSL 加密库以打印有关任何失败的配置字符串查找的信息。使用该设置运行脚本会产生以下结果(在 Ubuntu 18.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>

一个办法

从分析来看,似乎为设置 oid_file 添加了值。在主要部分和 default_md , req_extensionsencrypt_rsa_key[req] openssl.cnf的部分应该可以解决错误。确实,这样做之后,结果如下。
$ php conftest.php 

*** Errors before calling openssl_pkey_new
resource(4) of type (OpenSSL key)

*** Errors after calling openssl_pkey_new

结论

我认为您可以放心地忽略 PHP 对无关配置设置的错误调用。

关于php - openssl_pkey_new 抛出错误配置文件例程 :NCONF_get_string:no value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52076800/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com