OpenSSL的不能工作在Windows,错误0x02001003 0x2006D080 0x0E064002 [英] OpenSSL not working on Windows, errors 0x02001003 0x2006D080 0x0E064002

查看:5795
本文介绍了OpenSSL的不能工作在Windows,错误0x02001003 0x2006D080 0x0E064002的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

环境:

 的Windows NT 6.1点¯x构建7601(Windows 7的企业版Service Pack 1)i586系统
阿帕奇/ 2.4.4(Win32的)
PHP / 5.4.13 86
PHP目录:E:\\ WAMP \\ PHP \\
虚拟主机目录:E:\\项目\\ 1 \\的public_html

我已经尝试:


  • 安装说明 HTTP://www.php .NET /手动/ EN / openssl.installation.php

  • 的php.ini 扩展= p​​hp_openssl.dll

  • openssl.cnf中 E:\\ WAMP \\ PHP \\演员\\ 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

  • 带和不指定<目录E:\\ WAMP \\ PHP \\临时演员>在Apache的配置

  • 复制 openssl.cnf中来虚拟主机的public_html,指出了,仍然得到同样的错误

  • 没有登录 error_log中

  • 研究之:我花了最后2天研究这个,惊讶没有它的详细信息,所以我在这里发帖。似乎与OpenSSL的配置或Apache / PHP无法正常读取配置问题。

code:

  $ privateKey = openssl_pkey_new();
而($消息= openssl_error_string()){
    回声$消息'< BR />'.PHP_EOL;
}

结果:

 错误:02001003:系统库:FOPEN:没有这样的过程
错误:2006D080:BIO套路:BIO_new_file:没有这样的文件
错误:0E064002:配置文件的套路:CONF_load:系统库
错误:02001003:系统库:FOPEN:没有这样的过程
错误:2006D080:BIO套路:BIO_new_file:没有这样的文件
错误:0E064002:配置文件的套路:CONF_load:系统库

OpenSSL的手动:

  E:\\ WAMP \\ Apache的\\ BIN> openssl.exe PKEY
警告:无法打开配置文件:C:/openssl-1.0.1e/ssl/openssl.cnfE:\\ WAMP \\ Apache的\\ BIN>设置OPENSSL_CONF =E:\\ WAMP \\ PHP \\演员\\ openssl.cnf中E:\\ WAMP \\ Apache的\\ BIN> openssl.exe PKEY
3484:错误:0200107B:系统库:FOPEN:未知的错误:\\加密\\生物\\ bss_file.c:169:的fopen('E:\\ WAMP \\ PHP \\演员\\ openssl.cnf中',RB)
3484:错误:2006D002:BIO套路:BIO_new_file:系统lib目录下:\\加密\\生物\\ bss_file.c:174:
3484:错误:0E078002:配置文件的套路:DEF_LOAD:系统lib目录下:\\加密\\的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的功能,没有那么多的服务器端配置。

最后code:

  //创建密钥对
$解析度= openssl_pkey_new();//获取私钥
openssl_pkey_export($资源,$的privKey);//获取公钥
$ PUBKEY = openssl_pkey_get_details($水库);
$ PUBKEY = $ PUBKEY [钥匙];//实际的文件
$ PRIVATE_KEY = NULL;
$ Unsigned_Cert = openssl_csr_new($信息,$ PRIVATE_KEY,$的Configs);
$ Signed_Cert = openssl_csr_sign($ Unsigned_Cert,空,PRIVATE_KEY $ 365,$的Configs);
openssl_pkcs12_export_to_file($ Signed_Certtest.p12,$ PRIVATE_KEY,123456);

关闭了。

一年后...

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

  / **
     *测试使用解密密钥的能力:1)建立酒馆/私法密钥对2)提取酒吧/私法键3)明文加密使用键4)
     *
     * @返回布尔|串假,如果失败,字符串,如果成功
     * /
    功能testOpenSSL($ opensslConfigPath = NULL)
    {
        如果($ opensslConfigPath == NULL)
        {
            $ opensslConfigPath =E:/Services/Apache/httpd-2.4.9-win32-VC11/conf/openssl.cnf
        }
        $配置=阵列(
            配置= GT; $ opensslConfigPath,
            digest_alg=> SHA512
            private_key_bits=> 4096,
            private_key_type=> OPENSSL_KEYTYPE_RSA,
        );        $解析度= openssl_pkey_new($配置); //< - CONFIG ARRAY
        如果(空($水库)){返回false;}        //提取从$水库至$的privKey私钥
        openssl_pkey_export($资源,$的privKey,NULL,$配置); //< - CONFIG ARRAY        //提取从$水库至$ PUBKEY公钥
        $ PUBKEY = openssl_pkey_get_details($水库);
        如果($ PUBKEY === FALSE){返回false;}        $ PUBKEY = $ PUBKEY [钥匙];        $数据='明文数据放在这里;        //加密数据以$加密使用公开密钥
        $解析度= openssl_public_encrypt($数据,$加密,$ PUBKEY);
        如果($水库=== FALSE){返回false;}        //解密使用私有密钥的数据,并存储解密中$结果
        $解析度= openssl_private_decrypt($加密,解密$,$的privKey);
        如果($水库=== FALSE){返回false;}        返回$解密;
    }    //用法示例:
    $解析度= testOpenSSL();
    如果($水库=== FALSE)
    {
        回声<跨度风格=背景色:红色;'>&失败LT; / SPAN>中;
    }其他{
        回声<跨度风格=背景色:绿色;'>通:$水库< / SPAN>中;
    }


解决方案

在code以下正常工作。但如果您运行 openssl_error_string() OpenSSL的方法,它显示了错误后:0E06D06C:配置文件的套路:NCONF_get_string:没有价值这是一些通知,我一直没能找到上的文档。

还要注意的是,根据 HTTP://www.php .NET /手动/ EN / function.openssl-错误string.php 你可以会看到错误导致错误,因为错误消息排队:


  

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


 < PHP
/ *创建私钥和公钥* /
$解析度= openssl_pkey_new();
openssl_error_string(); //即使它的工作的罚款可能会引发错误!/ *从$提取私钥资源为$的privKey * /
openssl_pkey_export($资源,$的privKey);
openssl_error_string(); //即使它的工作的罚款可能会引发错误!/ *提取从$水库公钥$ PUBKEY * /
$ PUBKEY = openssl_pkey_get_details($水库);
$ PUBKEY = $ PUBKEY [钥匙];$数据='i.amniels.com是一个伟大的网站!;/ *使用公钥加密的数据
 *将加密数据存储在$加密* /
openssl_public_encrypt($数据,$加密,$ PUBKEY);/ *使用私钥解密的数据,并存储所述
 *在$解密。 * /
openssl_private_decrypt($加密,解密$,$的privKey);回声$解密;
?>

Problem: OpenSSL is not working in my Windows environment. OpenSSL repeatedly reports errors 0x02001003, 0x2006D080 and 0x0E064002.

Environment:

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

What I've Attempted:

  • Installation Instructions 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
  • Rebooted
  • phpinfo:
    ----OpenSSL support enabled
    ----OpenSSL Library Version OpenSSL 1.0.1e 11 Feb 2013
    ----OpenSSL Header Version OpenSSL 0.9.8y 5 Feb 2013
  • With and without specifying config in configargs
  • With and without specifying <Directory E:\wamp\php\extras> in apache config
  • Copied openssl.cnf to virtualhost public_html, pointed to that and still get same errors
  • Nothing logged in error_log
  • Researched: I've spent the last 2 days researching this, surprised there isn't more info on it so I'm posting here. Seems to be problem with OpenSSL config or apache/php not reading config properly.

Code:

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

Results:

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 Manually:

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:

EDIT:

  1. Thanks to @Gordon I can now see open_ssl errors using openssl_error_string
  2. Completely uninstall EasyPHP. Manually installed stable versions of PHP/Apache. Same results! Definitely something I'm doing wrong with implementing openssl on windows.
  3. OpenSSL Manually section... additional error info

FINAL THOUGHTS:
I set up a linux box and I'm getting the same errors. After some playing around I see that even though it's throwing errors at the openssl_pkey_new it does eventually create my test p12 file. Long story short, the errors are misleading and it has to deal more with how you are using openssl functions not so much server-side configuration.

Final code:

// 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");

Close away.

A year later...

So I found myself doing this again a year later, and regardless of whatever PATH variables I set on the computer or during the script execution, it kept erroring about file not found. I was able to resolve it by passing in the config parameter in the config_args array in openssl_pkey_new. Here is a function that tests the ability to successfully use 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>";
    }

解决方案

The code below works as expected. BUT if you run openssl_error_string() after the openssl methods it shows error:0E06D06C:configuration file routines:NCONF_get_string:no value which is some notice I have not been able to find documentation on.

Further note that according to http://www.php.net/manual/en/function.openssl-error-string.php you could be seeing mis-leading errors as error messages are queued:

Be careful when using this function to check errors, as it seems to read from a buffer of > errors, which could include errors from another script or process that was using openssl > functions. (I was surprised to find it returing error messages before I had called any > openssl_* functions)

<?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;
?>

这篇关于OpenSSL的不能工作在Windows,错误0x02001003 0x2006D080 0x0E064002的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆