vijaiaeroastro / irccloud

A simple heroku application to keep your irccloud connection alive always
The Unlicense
22 stars 27 forks source link

Connection Errror: 403 on connections #10

Open vibhoothi opened 3 years ago

vibhoothi commented 3 years ago

Hi,

Right now when we try to establish a connection we get sessionID and auth_token properly but we end up with 403 response, I tired to talk to IRCcloud feedback channel, itseems the HTTP method is deprecated, and we require to use/migrate to wss method.

https://github.com/irccloud/irccloud-tools/wiki/API-Overview#websocket

vijaiaeroastro commented 3 years ago

Hey @vibhoothiiaanand,

This was a long term coming. I will play with this tomorrow.

vijaiaeroastro commented 3 years ago

Hey @vibhoothiiaanand

I have created a websocket version of the script.

pip install autobahn[serializers]
pip install twisted
pip install service_identity

Install above modules and test the irccloud_ws.py script and let me know if it indeed keeps you from logging out.

vibhoothi commented 3 years ago

@vijaiaeroastro thanks for the quick turnaround,

I tried to see, on quick looks it looks like some issue in the way we are handling keeping connection,

Full logs:

```python python3 irccloud_ws.py 2021-05-13 14:46:25,921 INFO Successfully obtained authentication token. 2021-05-13 14:46:26,558 INFO Successfully obtained a session id. Unhandled Error Traceback (most recent call last): File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/log.py", line 101, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/log.py", line 85, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/context.py", line 118, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/context.py", line 83, in callWithContext return func(*args, **kw) --- --- File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/posixbase.py", line 692, in _doReadOrWrite why = selectable.doWrite() File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line 613, in doConnect self._connectDone() File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line 641, in _connectDone self.protocol.makeConnection(self) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/protocols/tls.py", line 211, in makeConnection ProtocolWrapper.makeConnection(self, transport) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/protocols/policies.py", line 72, in makeConnection self.wrappedProtocol.makeConnection(self) builtins.AttributeError: 'WebSocketClientProtocol' object has no attribute 'makeConnection' Unhandled Error Traceback (most recent call last): File "irccloud_ws.py", line 105, in ws_keep_alive reactor.run() File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/base.py", line 1423, in run self.mainLoop() File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/base.py", line 1436, in mainLoop reactorBaseSelf.doIteration(t) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/epollreactor.py", line 244, in doPoll log.callWithLogger(selectable, _drdw, selectable, fd, event) --- --- File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/log.py", line 101, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/log.py", line 85, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/context.py", line 118, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/python/context.py", line 83, in callWithContext return func(*args, **kw) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/posixbase.py", line 700, in _doReadOrWrite self._disconnectSelectable(selectable, why, inRead) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/posixbase.py", line 306, in _disconnectSelectable selectable.connectionLost(failure.Failure(why)) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line 506, in connectionLost self._commonConnection.connectionLost(self, reason) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line 324, in connectionLost protocol.connectionLost(reason) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/protocols/tls.py", line 394, in connectionLost ProtocolWrapper.connectionLost(self, reason) File "/home/mindfreeze/.local/lib/python3.8/site-packages/twisted/protocols/policies.py", line 111, in connectionLost self.wrappedProtocol.connectionLost(reason) builtins.AttributeError: 'WebSocketClientProtocol' object has no attribute 'connectionLost' ^C2021-05-13 14:46:36,905 ERROR IRC Cloud Session could not be Kept alive. mindfreeze@garuda ~/t/irccloud (master)> ```

I tried to see around online, on quick look I did not find any leads to fix-up, maybe due to handling of websockets

TehPeGaSuS commented 3 years ago

Exactly the same error, but this time on the self hosted version (all required python3 libs are installed).

Expand

```python $ IRCCLOUD_USERNAME="email@address.here" IRCCLOUD_PASSWORD="pa$$w0rd_h3r3" python3 irccloud_ws.py 2021-05-13 16:06:47,022 INFO Successfully obtained authentication token. 2021-05-13 16:06:47,752 INFO Successfully obtained a session id. Unhandled Error Traceback (most recent call last): File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 103, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 86, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 122, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 85, in callWithContext return func(*args,**kw) --- --- File "/usr/lib/python3/dist-packages/twisted/internet/posixbase.py", line 619, in _doReadOrWrite why = selectable.doWrite() File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 627, in doConnect self._connectDone() File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 656, in _connectDone self.protocol.makeConnection(self) File "/usr/lib/python3/dist-packages/twisted/protocols/tls.py", line 213, in makeConnection ProtocolWrapper.makeConnection(self, transport) File "/usr/lib/python3/dist-packages/twisted/protocols/policies.py", line 75, in makeConnection self.wrappedProtocol.makeConnection(self) builtins.AttributeError: 'WebSocketClientProtocol' object has no attribute 'makeConnection' Unhandled Error Traceback (most recent call last): File "irccloud_ws.py", line 102, in ws_keep_alive reactor.run() File "/usr/lib/python3/dist-packages/twisted/internet/base.py", line 1267, in run self.mainLoop() File "/usr/lib/python3/dist-packages/twisted/internet/base.py", line 1279, in mainLoop self.doIteration(t) File "/usr/lib/python3/dist-packages/twisted/internet/epollreactor.py", line 235, in doPoll log.callWithLogger(selectable, _drdw, selectable, fd, event) --- --- File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 103, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 86, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 122, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 85, in callWithContext return func(*args,**kw) File "/usr/lib/python3/dist-packages/twisted/internet/posixbase.py", line 627, in _doReadOrWrite self._disconnectSelectable(selectable, why, inRead) File "/usr/lib/python3/dist-packages/twisted/internet/posixbase.py", line 258, in _disconnectSelectable selectable.connectionLost(failure.Failure(why)) File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 519, in connectionLost self._commonConnection.connectionLost(self, reason) File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 327, in connectionLost protocol.connectionLost(reason) File "/usr/lib/python3/dist-packages/twisted/protocols/tls.py", line 403, in connectionLost ProtocolWrapper.connectionLost(self, reason) File "/usr/lib/python3/dist-packages/twisted/protocols/policies.py", line 125, in connectionLost self.wrappedProtocol.connectionLost(reason) builtins.AttributeError: 'WebSocketClientProtocol' object has no attribute 'connectionLost' ^C2021-05-13 16:06:51,731 ERROR IRC Cloud Session could not be Kept alive. ```

After this works I'll submit some fixes to the irccloud.self branch.

vijaiaeroastro commented 3 years ago

Hey @PeGaSuS-Coder,

Don't worry. Once the testing is finished. I will update both repositories 😃

vijaiaeroastro commented 3 years ago

@vibhoothiiaanand Will make sure this gets fixed somehow this week. I have never used websockets in my personal work. Hence, i am struggling a bit 😃

osm commented 3 years ago

Hi,

If you still need some help, I hacked a keep alive app in go which seems to be working.

  1. Fetch a form token (like before)
  2. Fetch a session token (like before as well, but store some more data) When fetching the session token you should also store the following properties: websocket_host and websocket_path.
  3. Connect to the websocket (like you've also did in your code, but with some minor changes) https://github.com/vijaiaeroastro/irccloud/blob/master/irccloud_ws.py#L92 The host should be set to websocket_host from the previous step. https://github.com/vijaiaeroastro/irccloud/blob/master/irccloud_ws.py#L88 The URL should be wss://$websocket_host/$websocket_path also with the values from previous step.
  4. Once you've connected to the websocket you need to send this payload: https://github.com/osm/icka/blob/master/main.go#L34-L38 cookie should be set with the session id that you fetch from here: https://github.com/vijaiaeroastro/irccloud/blob/master/irccloud_ws.py#L53 _method should be auth _reqid should be set to 1 (or probably any integer would work)
  5. Once the message from 4 is sent you should receive data on the websocket connection with a JSON response, a successful attempt should return something like { "success": true, ... }

The complete go code can be found here: https://github.com/osm/icka/blob/master/main.go

vijaiaeroastro commented 3 years ago

Hey @osm,

Nice work. I am really not interested in maintaining this stuff anymore. Most of the simpler websocket libraries that i tried in Python simply suck when it comes to secure sockets and i hate using twisted for this. Even i was considering a Go based solution since Gorilla provides a nice implementation. But it wouldn't be fair to simply take your code in Go and put it in my repo either.

I will most likely not maintain these repositories anymore and redirect traffic to your repo 😃

I am not even on IRC anymore honestly. Only maintained this since it grew too popular.

Vijai