php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62014 Warnings from OpenSSL functions
Submitted: 2012-05-13 10:49 UTC Modified: 2012-05-16 22:09 UTC
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:4 (66.7%)
From: samueld23 at live dot com Assigned:
Status: Closed Package: OpenSSL related
PHP Version: 5.4.3 OS: Windows Server 2008 R2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: samueld23 at live dot com
New email:
PHP Version: OS:

 

 [2012-05-13 10:49 UTC] samueld23 at live dot com
Description:
------------
When I run the test script I've pasted in the "test script" section of this bug 
report, I get the warnings shown under "actual result" of this bug report.

I'm running this code on Windows Servef 2008 R2. I have tried running this exact 
same code under both PHP 5.4.3 and PHP 5.3.13.

(However, the code works just fine on Mac OS X 10.7.4, using PHP version 5.3.10.)

Test script:
---------------
<?php

$privateKey = openssl_pkey_new(array(
  'private_key_bits' => 1024,
  'private_key_type' => OPENSSL_KEYTYPE_RSA,
));

openssl_pkey_export_to_file($privateKey, 'private_key', "somepassword");

$keyDetails = openssl_pkey_get_details($privateKey);
file_put_contents('public_key', $keyDetails['key']);

?>

Expected result:
----------------
I expect two files to get output, one with a private key and another with a 
public key. In fact, this is exactly what happens on Mac OS X (as described in 
the "description" section of this bug report). On Windows, it's for some reasons 
not working, as described in the "actual result" section of this bug report.

Actual result:
--------------
When I run the script on the command prompt (using "cd <path to script>" and "
<path to php>\php.exe <path to script>\script.php"), I get the following output:

PHP Warning:  openssl_pkey_export_to_file(): cannot get key from parameter 1 in 
C:\Users\Administrator\Documents\script.php on line 8
PHP Warning:  openssl_pkey_get_details() expects parameter 1 to be resource, 
boolean given in C:\Users\Administrator\Documents\script.php on line 11

What ends up happening is that only one EMPTY file 'public_key' gets created.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-16 20:52 UTC] riptide dot tempora at opinehub dot com
Is the directory writeable by PHP? (Not familiar with Windows environments)

What happens if you do this?
<?php

$privateKey = openssl_pkey_new(array(
  'private_key_bits' => 1024,
  'private_key_type' => OPENSSL_KEYTYPE_RSA,
));

var_dump($privateKey);

if(openssl_pkey_export_to_file($privateKey, 'private_key', "somepassword")) {
  $keyDetails = openssl_pkey_get_details($privateKey);
  file_put_contents('public_key', $keyDetails['key']);
} else {
  die("Error");
}
?>
 [2012-05-16 21:11 UTC] samueld23 at live dot com
Your script gives me the following output:

bool(false)
PHP Warning:  openssl_pkey_export_to_file(): cannot get key from parameter 1 in 
C:\Users\Administrator\Documents\script.php on line 10
Error
 [2012-05-16 21:15 UTC] samueld23 at live dot com
The problem, therefore, appears to be in the key generation function. It's the 
var_dump call that is outputting

bool(false)

Interestingly, the same var_dump outputs the following on Mac OS X:

resource(4) of type (OpenSSL key)

So it's working fine on Mac OS X, but not on Windows. Any ideas why?
 [2012-05-16 22:09 UTC] samueld23 at live dot com
-Status: Open +Status: Closed
 [2012-05-16 22:09 UTC] samueld23 at live dot com
I fixed this "problem" by setting up the environmental variables as described 
here: http://php.net/manual/en/openssl.installation.php

I have marked this non-bug as closed, Thanks for your help, and sorry for wasting 
your time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC