OpenSSL的不工作在Windows,错误0x02001003 0x2006D080 0x0E06

2019-07-22 11:22发布

问题:OpenSSL是不是在我的Windows环境下工作。 OpenSSL的多次报告错误0x02001003,0x2006D080和0x0E064002。

环境:

Windows NT x 6.1 build 7601 (Windows 7 Business Edition Service Pack 1) i586
Apache/2.4.4 (Win32)
PHP/5.4.13 x86
PHP Directory: E:\wamp\php\
Virtual Host Directory: E:\Projects\1\public_html

我已经尝试:

  • 安装说明 http://www.php.net/manual/en/openssl.installation.php
  • php.ini中 extension=php_openssl.dll
  • openssl.cnf中 E:\wamp\php\extras\openssl.cnf
  • %PATH% E:\wamp\php
  • 重新启动
  • 的phpinfo:
    ----启用OpenSSL的支持
    ---- OpenSSL库版本的OpenSSL 1.0.1e 2013年2月11日
    ---- OpenSSL的头版本的OpenSSL 0.9.8y 2013年2月5日
  • 有和没有在指定配置 configargs
  • 具有和不具有指定<Directory E:\wamp\php\extras>在apache配置
  • 复制openssl.cnf ,以虚拟主机的public_html,指出了,仍然得到同样的错误
  • 没有登录的error_log
  • 研究:我花了最后2天研究这个,惊讶的还有它没有更多,所以我在这里发帖。 似乎与OpenSSL的配置或Apache / PHP无法正常读取配置问题。

码:

$privateKey = openssl_pkey_new();
while($message = openssl_error_string()){
    echo $message.'<br />'.PHP_EOL;
}

结果:

error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib
error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib

OpenSSL的手动:

E:\wamp\apache\bin>openssl.exe pkey
WARNING: can't open config file: c:/openssl-1.0.1e/ssl/openssl.cnf

E:\wamp\apache\bin>set OPENSSL_CONF="E:\wamp\php\extras\openssl.cnf"

E:\wamp\apache\bin>openssl.exe pkey
3484:error:0200107B:system library:fopen:Unknown error:.\crypto\bio\bss_file.c:169:fopen('"E:\wamp\php\extras\openssl.cnf"','rb')
3484:error:2006D002:BIO routines:BIO_new_file:system lib:.\crypto\bio\bss_file.c:174:
3484:error:0E078002:configuration file routines:DEF_LOAD:system lib:.\crypto\conf\conf_def.c:199:

编辑:

  1. 由于@Gordon我现在可以用看open_ssl错误openssl_error_string
  2. 完全卸载的EasyPHP。 手动安装PHP / Apache的稳定版本。 同样的结果! 绝对的东西,我做错了在Windows上实现的OpenSSL。
  3. OpenSSL的手动节...其他错误信息

最后的想法:
我成立了一个Linux操作系统中,我得到了同样的错误。 一些上场后,我周围看到,即使它在openssl_pkey_new引发错误它最终创建我的测试P12文件。 长话短说,错误是误导性的,它必须处理更多的与您如何使用OpenSSL的功能没有那么多的服务器端配置。

最终代码:

// Create the keypair
$res=openssl_pkey_new();

// Get private key
openssl_pkey_export($res, $privkey);

// Get public key
$pubkey=openssl_pkey_get_details($res);
$pubkey=$pubkey["key"];

// Actual file
$Private_Key = null;
$Unsigned_Cert = openssl_csr_new($Info,$Private_Key,$Configs);
$Signed_Cert = openssl_csr_sign($Unsigned_Cert,null,$Private_Key,365,$Configs);
openssl_pkcs12_export_to_file($Signed_Cert,"test.p12",$Private_Key,"123456");

很近。

一年后...

所以,我发现自己在一年后,也不管我在电脑上或脚本执行过程中设置任何PATH变量再次这样做,不停地示数约未找到文件。 我能够通过传递来解决它config的参数config_args阵列openssl_pkey_new 。 下面是测试成功使用OpenSSL的能力的功能:

    /**
     * Tests the ability to 1) create pub/priv key pair 2) extract pub/priv keys 3) encrypt plaintext using keys 4) decrypt using keys
     * 
     * @return boolean|string False if fails, string if success
     */
    function testOpenSSL($opensslConfigPath = NULL)
    {
        if ($opensslConfigPath == NULL)
        {
            $opensslConfigPath = "E:/Services/Apache/httpd-2.4.9-win32-VC11/conf/openssl.cnf";
        }
        $config = array(
            "config" => $opensslConfigPath,
            "digest_alg" => "sha512",
            "private_key_bits" => 4096,
            "private_key_type" => OPENSSL_KEYTYPE_RSA,
        );

        $res = openssl_pkey_new($config); // <-- CONFIG ARRAY
        if (empty($res)) {return false;}

        // Extract the private key from $res to $privKey
        openssl_pkey_export($res, $privKey, NULL, $config); // <-- CONFIG ARRAY

        // Extract the public key from $res to $pubKey
        $pubKey = openssl_pkey_get_details($res);
        if ($pubKey === FALSE){return false;}

        $pubKey = $pubKey["key"];

        $data = 'plaintext data goes here';

        // Encrypt the data to $encrypted using the public key
        $res = openssl_public_encrypt($data, $encrypted, $pubKey);
        if ($res === FALSE){return false;}

        // Decrypt the data using the private key and store the results in $decrypted
        $res = openssl_private_decrypt($encrypted, $decrypted, $privKey);
        if ($res === FALSE){return false;}

        return $decrypted;
    }

    // Example usage:
    $res = testOpenSSL();
    if ($res === FALSE)
    {
        echo "<span style='background-color: red;'>Fail</span>";
    } else {
        echo "<span style='background-color: green;'>Pass: ".$res."</span>";
    }

Answer 1:

下面的代码按预期工作。 你要是跑不过openssl_error_string() OpenSSL的方法后显示error:0E06D06C:configuration file routines:NCONF_get_string:no value这是一些通知我一直没能找到有关文档。

根据进一步注意到http://www.php.net/manual/en/function.openssl-error-string.php你可能会看到错误导致错误,因为错误消息排队:

使用此功能时,检查错误,因为它似乎从>错误的缓冲区,这可能包括使用OpenSSL的>功能从另一个脚本或程序错误读取要小心。 (我很惊讶地发现它returing错误消息之前,我曾呼吁任何> openssl_ *功能)

<?php
/* Create the private and public key */
$res = openssl_pkey_new();
openssl_error_string(); // May throw error even though its working fine!

/* Extract the private key from $res to $privKey */
openssl_pkey_export($res, $privKey);
openssl_error_string(); // May throw error even though its working fine!

/* Extract the public key from $res to $pubKey */
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];

$data = 'i.amniels.com is a great website!';

/* Encrypt the data using the public key
 * The encrypted data is stored in $encrypted */
openssl_public_encrypt($data, $encrypted, $pubKey);

/* Decrypt the data using the private key and store the
 * result in $decrypted. */
openssl_private_decrypt($encrypted, $decrypted, $privKey);

echo $decrypted;
?>


Answer 2:

我有一个类似的问题,对我来说帮助设置环境变量“OPENSSL_CONF” 手动在我的剧本的开头。

不知怎的,环境变量设置不正确,或没打通我的PHP(设置:AMPPS,Win7的64位)。

下面使用的示例位置是你必须有一个标准AMPPS安装时使用的路径,因此,如果您使用的AMPPS,只需复制和粘贴:

putenv("OPENSSL_CONF=C:\Program Files (x86)\Ampps\php\extras\openssl.cnf");


Answer 3:

这里的几件事情:

%PATH%还应包括Windows和SYSTEM32这样你%PATH%应该像c:\windows;c:\windows\system32;E:\wamp\phpe:\wamp\php应该是OpenSSL的dll文件

也尽量OpenSSL的版本相匹配的头版本0.9.8y 5 Feb 2013下载这里的32位和这里的64位

此代码似乎为我工作:

// Create the keypair
$res=openssl_pkey_new();

// Get private key
openssl_pkey_export($res, $privkey);

// Get public key
$pubkey=openssl_pkey_get_details($res);
$pubkey=$pubkey["key"];
$Info = array(
    "countryName" => "UK",
    "stateOrProvinceName" => "Somerset",
    "localityName" => "Glastonbury",
    "organizationName" => "The Brain Room Limited",
    "organizationalUnitName" => "PHP Documentation Team",
    "commonName" => "Wez Furlong",
    "emailAddress" => "wez@example.com"
);

// Actual file
$Private_Key = null;
$Unsigned_Cert = openssl_csr_new($Info,$Private_Key);
$Signed_Cert = openssl_csr_sign($Unsigned_Cert,null,$Private_Key,365);
openssl_pkcs12_export_to_file($Signed_Cert,"test.p12",$Private_Key,"123456");


Answer 4:

你有没有通过此方法安装OpenSSL的? 在Windows上安装OpenSSL的

  1. 转到http://gnuwin32.sourceforge.net/packages/openssl.htm ,并下载“二进制”的“设置”版本,的OpenSSL 0.9.7c-bin.exe。

  2. 上的OpenSSL 0.9.7c-bin.exe双击OpenSSL安装到\本地\的GnuWin32目录。

  3. 回到同一页面,下载“文档”中的“设置”版本,并将其安装到同一个目录。

  4. 打开命令行窗口,并尝试使用以下命令:代码:

    \local\gnuwin32\bin\openssl -help
    openssl:Error: '-help' is an invalid command.

    Standard commands
    asn1parse      ca             ciphers        crl            crl2pkcs7
    dgst           dh             dhparam        dsa            dsaparam
    enc            engine         errstr         gendh          gendsa
    genrsa         nseq           ocsp           passwd         pkcs12
    pkcs7          pkcs8          rand           req            rsa
    rsautl         s_client       s_server       s_time         sess_id
    smime          speed          spkac          verify         version
    x509
    ......

如果你看到的OpenSSL打印命令的列表,你知道你的安装正确。



Answer 5:

如果你使用Apache 2.4 + mod_fcgid,您可以通过添加指定的OpenSSL的conf文件FcgidInitialEnv在httpd.conf文件:

# OPENSSL CONF
FcgidInitialEnv OPENSSL_CONF "D:/apps/php70/extras/ssl/openssl.cnf"

我不使用预配置的软件包,如WAMP,我已经得到了来自Apache的Apache的休息室从和PHP windows.php.net ,并通过自己的配置。



Answer 6:

干净的解决方案:

  1. 从这里下载存档(并不重要)用于PHP Windows二进制: http://windows.php.net/download
  2. 在里面你发现文件/extras/ssl/openssl.cnf
  3. 提取openssl.cnf中的某个地方(如 “C:/WEB/PHP/extras/ssl/openssl.cnf”)
  4. 添加全局系统变量OPENSSL_CONF与您所使用的路径(如“C:\ WEB \ PHP \演员\ openssl.cnf中”(不包括双引号))。

您必须将路径添加到OPENSSL_CONF系统变量。 它添加到Path系统变量是不够的! 在Windows 7你找到下的设置对话框:“控制面板>系统和安全>系统>高级系统设置(左侧菜单)>高级(标签)>环境变量...”。 新增了可变OPENSSL_CONF那里。

它并不需要准备使用前openssl.cnf中的文件 - 它会工作的开箱。 但你可以,如果要微调设定。



Answer 7:

在我的情况下将文件复制到C:\ Windows \ System32下帮了我

的libeay32.dll,ssleay32.dll

人们可以在OpenSSL_INSTALL_PATH \ bin中找到它们。



Answer 8:

我可能会建议使用虚拟盒 ,创建虚拟机并安装LAMP堆栈。 这会给你一个“更真实”的环境。 以及故障排除OpenSSL是在Linux上更容易。

随着中说,我相信你的问题是你无法找到该插件文件本身。 确保它生活在了正确的道路,并存在你的机器并运行Apache下有权读取它的进程上。



文章来源: OpenSSL not working on Windows, errors 0x02001003 0x2006D080 0x0E064002