Jump to content


Extension that returns the SSL-Certificate of the peer

  • Please log in to reply
No replies to this topic

#1 qja

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 June 2006 - 06:37 PM


that´s my first post in this forum. And hopefully not my last one.

Iam currently writing my first php extension and got into a problem.

My goal is a function that takes the return value of a
fsockopen call as argument. I want to use this open
connection to get the SSL-Certificate of this peer.

Iam using most of the code of the function:
php_stream_sock_ssl_activate_with_method (can be found in main/network.c)

the error i get is:
if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET)) {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_stream_sock_ssl_activate_with_method: stream is not a network stream");
        return FAILURE;
this code is copied and pasted from the method in the php src.

So the stream is not a network stream.

Now i will show you my ssl_get_cert function:
#define PHP_STREAM_TO_ZVAL(stream, arg) \
    php_stream_from_zval_no_verify(stream, arg); \
    if (stream == NULL) {    \
        RETURN_FALSE;    \

    zval **arg1;
    php_stream *stream = NULL;
    int x509;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg1) == FAILURE)

    PHP_STREAM_TO_ZVAL(stream, &arg1);
    Z_TYPE_P(return_value) = IS_RESOURCE;
    php_get_ssl_cer(stream, Z_LVAL_P(return_value) TSRMLS_CC);


the code in my .php file would be something like

$fp = fsockopen ("www.acrm.de", 443,$errno, $errstr, 3);
if (!$fp) {
     print("No connection");
   echo "$errstr ($errno)<br />\n";
} else {
     $testcert = ssl_get_cert($fp);

but $fp is not a network stream... if i comment the part were the error gets thrown it doesn´t work
either so i think i need a network stream...

I hope you can help me out guys cause iam stuck.

thanks for every suggestion/help

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users