elephant.io icon indicating copy to clipboard operation
elephant.io copied to clipboard

Error While Trying To Establish a Connection on SSL HTTPS

Open jbalbert opened this issue 6 years ago • 15 comments

Hello Good Day!

I have a problem establishing a connection server with my ssl certificate.

"An error occurred while trying to establish a connection to the server"

I have this code :

$this->client = new Client(new Version1X("https://www.sockettestserver.com:3000"));

And now I checked one of the tickets here like passing this $options:

$options = [
    'context' => [
        'ssl' => [
            'verify_peer' => false,
             'verify_peer_name' => false
        ]
    ]
];

$this->client = new Client(new Version1X("https://www.sockettestserver.com:3000",  $options));

But still I can't establish any connection.

If I am sending an http request it is working and it listens to port 3000 just fine. But when I changed the connection to https I am getting that error.

Hope you can help me.

Thanks is advance.

jbalbert avatar Mar 22 '19 02:03 jbalbert

As said in https://github.com/Wisembly/elephant.io/issues/179#issuecomment-448460882, please catch the exception and dump the getErrorMessage().

It should pinpoint you the error on why it couldn't connect your to the server.

BTW, IIUC, you are trying to make a ssl connection on a insecured port. Don't you have another port that is open for ssl ?

Taluu avatar Mar 22 '19 09:03 Taluu

I am using port 443 for the ssl connection. Should I try using it instead of port 3000?

Is this also maybe one of the reason i cant make a connection?

jbalbert avatar Mar 22 '19 10:03 jbalbert

Probably, give it a try. :}

Taluu avatar Mar 22 '19 11:03 Taluu

Okay Thanks. I am really new to sockets and ssl connections. I will give it try and give you a feedback.

jbalbert avatar Mar 22 '19 11:03 jbalbert

Hello @Taluu , I tried using port 443, Here's what i got " This server does not support the websocket transport, aborting ", Is this a problem on my node server or the elephant io itself?

Thank you

jbalbert avatar Mar 26 '19 01:03 jbalbert

AFAIK, I think it's a problem on your node server. I think you're serving through http (not https) on the port 3000, and the port 443 is not listened by your node server but your http server (which can be different).

You also cannot (AFAIK) serve both secured and unsecured connections on the same port. So you should configure your node server to deliver a https connection on another port (or through the 3000).

Taluu avatar Mar 26 '19 10:03 Taluu

I run into this issue, solved by : https://www.php.net/manual/fr/function.stream-context-create.php#74795 and https://www.php.net/manual/fr/context.http.php#121763

Must use context "http" not "ssl" in wisembly/elephant.io/src/Engine/SocketIO/Version1X.php line 165

$protocol = true === $this->url['secured'] ? 'http' : 'http';

lorenzyannick avatar Jan 31 '20 10:01 lorenzyannick

Care to make a PR ?

Taluu avatar Jan 31 '20 10:01 Taluu

yes... I'll try later but with a proper code because because this lines is useless $protocol = true === $this->url['secured'] ? 'http' : 'http'; same as : $protocol = 'http'

lorenzyannick avatar Jan 31 '20 10:01 lorenzyannick

yes, but not in 3.3.1 My fault... https://github.com/Wisembly/elephant.io/blob/v3.3.1/src/Engine/SocketIO/Version1X.php

lorenzyannick avatar Jan 31 '20 10:01 lorenzyannick

Yep just saw, that's why I deleted my comment. :}

I think there was an error at some point that needed the ssl context for ssl connections instead of https, but using the https:// protocol should be fine (with ssl context if you need some certificates).

Taluu avatar Jan 31 '20 10:01 Taluu

Socket connect is ok (+ HEADERS working) in dev-master But emit not working (write function ?) Seems to be the same problem... I fall back to 3.3.1 and change only Version1X.php line 165

I'll try to investigate later...

lorenzyannick avatar Jan 31 '20 10:01 lorenzyannick

@lorenzyannick any news in your investigation? I have the same error

daryn-k avatar Oct 03 '21 17:10 daryn-k

After passing $context parameter I fixed my situation.

    $options = [
      'context' => [
          'ssl' => [
              'verify_peer' => false,
               'verify_peer_name' => false
          ]
      ]
    ];
    
    $this->client = new Client(new Version1X("https://www.sockettestserver.com:3000",  $options));

daryn-k avatar Oct 03 '21 17:10 daryn-k

I'm having the same issue, the options you provide @daryn-k works. But why suddenly this issue?

hugoalexmartins avatar Oct 04 '21 21:10 hugoalexmartins