Jump to content

Archived

This topic is now archived and is closed to further replies.

qja

Extension that returns the SSL-Certificate of the peer

Recommended Posts

hi!

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:
[code]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;
    }[/code]
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:
[code]#define PHP_STREAM_TO_ZVAL(stream, arg) \
    php_stream_from_zval_no_verify(stream, arg); \
    if (stream == NULL) {    \
        RETURN_FALSE;    \
    }

PHP_FUNCTION(ssl_get_cert)
{
    zval **arg1;
    
    php_stream *stream = NULL;
    int x509;

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

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

    
}
[/code]

the code in my .php file would be something like

[code]$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);
...
[/code]

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


Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.