Monday, 24 April 2017

convert php secure stream socket to nodejs

i have a problem with nodejs secure socket i have php program to create secure socket server and client can connect to it for proccessing but i want to convert program to nodejs but nodejs not working. when i use tcp socket the client create connection to server and node server receive data and print it but data is encrypted. when i'm secure the socket with tls server started but client data not recevied. here is php socket config please help me to convert it to nodejs.

$instance->server = stream_socket_server(ssl://127.0.0.1:8000, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);

context is returned by this function

public static function getSSLContext() {
        global $rootPath;
        $pemPassphrase = 'passphrase';
        $pemfile = $rootPath . '/server.pem';

        $context = stream_context_create();

        // local_cert must be in PEM format
        stream_context_set_option($context, 'ssl', 'local_cert', $pemfile);
        // Pass Phrase (password) of private key
        stream_context_set_option($context, 'ssl', 'passphrase', pemPassphrase);

        stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
        stream_context_set_option($context, 'ssl', 'verify_peer', false);
        return $context;
    }



via Mohsen Saeedi

No comments:

Post a Comment