52

問題: 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
  • %道% E:\wamp\php
  • 再起動
  • phpinfo:
    ----OpenSSLサポートが有効になってい
    ます----OpenSSLライブラリバージョンOpenSSL1.0.1e2013年2月11日
    ----OpenSSLヘッダーバージョンOpenSSL0.9.8y2013年2月5日
  • でconfigを指定する場合としない場合configargs
  • <Directory E:\wamp\php\extras>apacheconfigで指定する場合としない場合
  • openssl.cnfvirtualhost public_htmlにコピーされ、それをポイントしても同じエラーが発生する
  • error_logに何もログインしていません
  • 調査:私は過去2日間これを調査しましたが、これ以上の情報がないことに驚いたので、ここに投稿します。OpenSSLconfigまたはapache/phpがconfigを正しく読み取っていないことに問題があるようです。

コード:

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

閉じてください。

一年後...

そのため、1年後に再びこれを実行していることに気付きました。コンピューターに設定した、またはスクリプトの実行中に設定したPATH変数に関係なく、ファイルが見つからないというエラーが発生し続けました。の配列にconfigパラメータを渡すことで解決できました。OpenSSLを正常に使用する機能をテストする関数は次のとおりです。config_argsopenssl_pkey_new

    /**
     * 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>";
    }
4

10 に答える 10

9

以下のコードは期待どおりに機能します。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関数を使用していた別のスクリプトまたはプロセスからのエラーが含まれる可能性があります。(> 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;
?>
于 2013-03-26T20:36:41.963 に答える
5

ここにいくつかのこと:

%PATH%また、windowsとsystem32が含まれている必要があるため、%PATH%は次のようc:\windows;c:\windows\system32;E:\wamp\phpe:\wamp\phpなり、openssldllファイルが含まれている必要があります。

また、ヘッダーバージョンと一致するopensslバージョンを試してください。32ビットの場合はここから、64ビットの場合はここから0.9.8y 5 Feb 2013ダウンロードしてください。

このコードは私にとってはうまくいくようです:

// 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");
于 2013-07-01T16:36:30.133 に答える
4

同様の問題が発生しました。スクリプトの先頭で環境変数「OPENSSL_CONF」を手動で設定するのに役立ちました。

どういうわけか、環境変数が正しく設定されていないか、私のphp(セットアップ:AMPPS、Win7 64ビット)に到達しませんでした。

以下で使用されている場所の例は、標準のAMPPSインストールで使用する必要があるパスです。したがって、AMPPSを使用している場合は、コピーして貼り付けてください。

putenv("OPENSSL_CONF=C:\Program Files (x86)\Ampps\php\extras\openssl.cnf");
于 2013-10-20T10:50:34.243 に答える
3

FcgidInitialEnvApache 2.4 + mod_fcgidを使用している場合は、httpd.confファイルを追加してOpenSSLconfファイルを指定できます。

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

WAMPなどの事前構成されたパッケージを使用していません。ApacheLoungeからApacheを、 windows.php.netからPHPを入手し、自分で構成しました。

于 2015-12-12T11:42:04.357 に答える
2

クリーンなソリューション:

  1. ここからPHPWindowsバイナリのアーカイブをダウンロードします(どちらでも構いません):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 \ extras \ openssl.cnf」(二重引用符なし))。

ここに画像の説明を入力してください

OPENSSL_CONFシステム変数へのパスを追加する必要があります。システム変数に追加するだけでPathは不十分です。Windows 7では、「コントロールパネル>システムとセキュリティ>システム>システムの詳細設定(左側のメニュー)>詳細(タブ)>環境変数...」の下に設定ダイアログがあります。そこに変数を追加しOPENSSL_CONFます。

使用前にopenssl.cnfファイルを準備する必要はありません-箱から出してすぐに機能します。ただし、設定を微調整したい場合は可能です。

于 2016-08-09T04:03:19.977 に答える
1

この方法でOpenSSLをインストールしましたか?WindowsへのOpenSSLのインストール

  1. http://gnuwin32.sourceforge.net/packages/openssl.htmにアクセスし、「Binaries」の「Setup」バージョンであるopenssl-0.9.7c-bin.exeをダウンロードします。

  2. openssl-0.9.7c-bin.exeをダブルクリックして、OpenSSLを\ local\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によって出力されたコマンドのリストが表示されている場合は、インストールが正しく行われていることがわかります。

于 2013-06-07T17:41:09.987 に答える
0

私の場合、ファイルをc:\ windows\system32にコピーすると役に立ちました

libeay32.dll、ssleay32.dll

それらはOpenSSL_INSTALL_PATH\binにあります。

于 2014-10-14T18:07:56.340 に答える
0
<?php 

         // also see  stackoverflow.com/questions/59195251/php-get-private-key-from-a-single-line-private-key 
         // micmap.org/php-by-example/de/function/openssl_get_publickey
         // best  stackoverflow.com/questions/15558321/openssl-not-working-on-windows-errors-0x02001003-0x2006d080-0x0e064002
         // sandrocirulli.net/how-to-encrypt-and-decrypt-emails-and-files/



         echo '<pre>';


        function testOpenSSL($openssl_args)
        {

                $res = openssl_pkey_new($openssl_args); // <-- CONFIG ARRAY
                openssl_error_string(); // May throw error even though its working fine!
                if (empty($res)) {return false;}
                $openssl_args['keysnew']=$res;
                        //var_dump($res);echo '<br><br>';


                // Extract the private key from $res to $privKey
                openssl_pkey_export($res, $privKey, NULL, $openssl_args); // <-- CONFIG ARRAY
                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);
                openssl_error_string(); // May throw error even though its working fine!
                if ($pubKey === FALSE){return false;}
                $pubKey = $pubKey["key"];   

                // Encrypt the data to $encrypted using the public key
                $data = $openssl_args['data'];          
                $res = openssl_public_encrypt($data, $encrypted, $pubKey);
                if ($res === FALSE){return false;}
                        #var_dump($res);exit; //bool
                // 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;
                $openssl_args['pub_key']=$pubKey;
                $openssl_args['priv_key']=$privKey;
                $openssl_args['encr']=$encrypted;
                $openssl_args['decr']=$decrypted; 

                return $openssl_args;

        }




        // try sam openssl.cnf   , most error on windows xampp
        $try= 5;     
        $openssl_cnf_path = array(
            0=>'C:\xampp\apache\conf\openssl.cnf',   //11259 bytes
            1=>'C:\xampp\apache\bin\openssl.cnf',   //11259 bytes

            2=>'C:\xampp\php\windowsXamppPhp\extras\ssl\openssl.cnf',  //10909
            3=>'C:\xampp\php\extras\ssl\openssl.cnf',   //10909 byes
            4=>'C:\xampp\php\extras\openssl\openssl.cnf',   //9374 bytes

            5=>'C:\Program Files\Git\usr\ssl\openssl.cnf',  //10909 bytes
            6=>'C:\Program Files\Git\mingw64\ssl\openssl.cnf',  //10909 bytes
            );

        $data = ' todo in spin activate theme elementor-child plugin qw_casino ... permalinks postname media Lib. add new upload paysave pic make empty page   with template-casino in -child make page4todo in spin activate theme elementor-child plugin qw_casin245'; /**  ... permalinks postname media Lib. add new upload paysave pic make empty page   with template-casino in -child make page6todo in spin activate theme elementor-child plugin qw_casino  .. permalinks postname media Lib.add new upload paysave pic  make empty501'; 
        /** mist max str len 501  in RFC3447 can operate on messages of length up to k - 11 octets (k is the octet length of the RSA modulus) so if you are using 2048-bit RSA key then maximum length of the plain data to be encrypted is 245 bytes.  /***/

        echo 'str len : ', strlen($data);

        $openssl_args = array(
            "config" => $openssl_cnf_path[$try],
            "digest_alg" => "sha512",
            //"private_key_bits" => 4096,
            "private_key_bits" => 2048,
            "private_key_type" => OPENSSL_KEYTYPE_RSA,
            "try_path_ar" => $openssl_cnf_path,
            "data" => $data,
            );



        // Example
        $res = testOpenSSL($openssl_args);
        if ($res === FALSE)
        {
            echo "<h4 style='background-color: red;'>Fail</h4>";
        } else {
            echo '<h3 style=\'background-color: green; color:white;\'>with $try= '.$try.' decrypted ok: '.$res['decr'].'</h3>';
        }

                //////////////////////////////////////////
                //
                echo '<br>vardump res <br>';  var_dump($res);   
                echo '<br>======================<br>';      

        $privKey=$res['priv_key'];
        $pubKey =$res['pub_key'];
        file_put_contents('pri_key.txt',$privKey);
        file_put_contents('priv_key.txt',$privKey);
        file_put_contents('pub_key.txt',$pubKey);


        echo '<br><br><pre>';


        /* Encrypt the data using the public key
         * The encrypted data is stored in $encrypted */
        openssl_public_encrypt($data, $encrypted, $pubKey);
                echo '<br>public encrypt: '; var_dump( base64_encode($encrypted));


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



        // inverse testOpenSSL
        openssl_private_encrypt($data, $encrypted, $privKey);
                echo '<br><br> invers<br>pri encrypt: '; var_dump( base64_encode($encrypted));

        openssl_public_decrypt($encrypted, $decrypted, $pubKey);
                echo ' pub decrypt: ', $decrypted , '<br>'; 
于 2020-02-27T16:42:47.827 に答える
0

XAMPPでも同様の問題が発生しました。OPENSSL_CONFin[xampp_dir]\apache\conf\extra\httpd-xampp.confが正しく設定されていないことがわかりました[xampp_dir]/apache/bin/openssl.cnf。それを修正した後[xampp_dir]/apache/conf/openssl.cnf、動作します。

于 2022-02-16T10:29:34.113 に答える
-1

Virtual Boxを使用して、VMを作成し、LAMPスタックをインストールすることをお勧めします。これにより、「よりリアルな」環境が得られます。Linuxでは、OpenSSLのトラブルシューティングだけでなく簡単です。

そうは言っても、あなたの問題はプラグインファイル自体が見つからないことだと思います。それが正しいパスに存在し、マシン上に存在し、Apacheが実行されるプロセスにそれを読み取る権限があることを確認してください。

于 2013-06-19T21:00:50.010 に答える