Edit report at https://bugs.php.net/bug.php?id=62014&edit=1

 ID:                 62014
 Comment by:         samueld23 at live dot com
 Reported by:        samueld23 at live dot com
 Summary:            Warnings from OpenSSL functions
 Status:             Open
 Type:               Bug
 Package:            OpenSSL related
 Operating System:   Windows Server 2008 R2
 PHP Version:        5.4.3
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2012-05-16 20:52:24] 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-13 10:49:57] 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.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62014&edit=1

Reply via email to