Connecting Tech Pros Worldwide Help | Site Map

Request for help with fsockopen

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 17th, 2007, 03:25 PM
Alex
Guest
 
Posts: n/a
Default Request for help with fsockopen

Hi all,
I'm having a problem with fsockopen function, I'm programming with php
4.3 and need to do an HTTP POST over secure socket, ssl, here's my
code:

$context = stream_context_create();
$result = stream_context_set_option($context, 'ssl', 'local_cert',
"/certificate/cert.pem");
$result = stream_context_set_option($context, 'ssl', 'passphrase',
"passphrase");

$sock = fsockopen("ssl://myhost", 443 , $errno, $errstr, 30, $context);
if (!$sock) die("$errstr ($errno)\n");

I get this error when trying to run this code:
Warning: fsockopen(): Unable to set local cert chain file
`/certificate/cert.pem'; Check that your cafile/capath settings include
details of your certificate and its issuer in /path/to/file.php on line
xxx

Dunno what to do, I thought there's something wrong in my certificate
but couldn't find any real explanation on google or php site, If anyone
can help, it would be much appreciated.


  #2  
Old January 17th, 2007, 05:55 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Request for help with fsockopen

On 17 Jan 2007 08:21:06 -0800, "Alex" <dna.soldout@gmail.comwrote:
Quote:
>I'm having a problem with fsockopen function, I'm programming with php
>4.3 and need to do an HTTP POST over secure socket, ssl, here's my
>code:
>
>$context = stream_context_create();
>$result = stream_context_set_option($context, 'ssl', 'local_cert',
>"/certificate/cert.pem");
>$result = stream_context_set_option($context, 'ssl', 'passphrase',
>"passphrase");
>
>$sock = fsockopen("ssl://myhost", 443 , $errno, $errstr, 30, $context);
>if (!$sock) die("$errstr ($errno)\n");
>
>I get this error when trying to run this code:
>Warning: fsockopen(): Unable to set local cert chain file
>`/certificate/cert.pem'; Check that your cafile/capath settings include
>details of your certificate and its issuer in /path/to/file.php on line
>xxx
>
>Dunno what to do, I thought there's something wrong in my certificate
>but couldn't find any real explanation on google or php site, If anyone
>can help, it would be much appreciated.
Just to rule out the easy ones first: do you really have a /certificate
directory at the root directory of the filesystem of your server? Remember,
that parameter is not a relative URL.

There's a couple of hits on Google too, particularly one in a user note on the
SOAP part of the manual - is that any help?


http://www.google.co.uk/search?q=%22...th+settings%22

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
  #3  
Old January 18th, 2007, 12:15 PM
Alex
Guest
 
Posts: n/a
Default Re: Request for help with fsockopen

hi, thakyou for reply, here's what I discovered:

Quote:
Just to rule out the easy ones first: do you really have a /certificate
directory at the root directory of the filesystem of your server? Remember,
that parameter is not a relative URL.
No, I really don't have a /certificate at root, I was using absolute
path, but in reality it is a relative path and it does have the cert in
pem format.
Quote:
There's a couple of hits on Google too, particularly one in a user note on the
SOAP part of the manual - is that any help?
>
Unfortunately not, but I did find a resolution by adding these two
lines of code that add some option parameters to the stream:

$result = stream_context_set_option($context, 'ssl',
'allow_self_signed', true);
$result = stream_context_set_option($context, 'ssl', 'verify_peer',
false);

This way I should accept a certificate self_signed by CA and I don't
verify it. Kinda unsafe but works well.

Alex

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.