Bug 98018 - [regression] Kopete unable to connect using dante SOCKS proxy with KNetwork based scoket implementation
Summary: [regression] Kopete unable to connect using dante SOCKS proxy with KNetwork b...
Status: RESOLVED FIXED
Alias: None
Product: kdelibs
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: VHI grave
Target Milestone: ---
Assignee: Thiago Macieira
URL:
Keywords:
: 88215 88766 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-27 20:38 UTC by Jason 'vanRijn' Kasper
Modified: 2007-02-10 01:44 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason 'vanRijn' Kasper 2005-01-27 20:38:00 UTC
Version:            (using KDE KDE 3.3.91)
Installed from:    Compiled From Sources
Compiler:          gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)  
OS:                Linux

I am using kopete from the kde3.4-beta1 release (compiled from konstruct).

I need to get kopete to work with the SOCKS proxy that I have.  I am running Fedora Core 3, and have installed the dante client.  I am using "ssh -D" to be my SOCKS server, as shown on this page:   http://www.spinics.net/lists/kde/msg01883.html

My /etc/socks.conf is this:

--------------------
debug: 1
logoutput: /tmp/dante.out
route {
       from: 0.0.0.0/0   to: 0.0.0.0/0  via: 127.0.0.1 port = 11080
       proxyprotocol: socks_v4
}
route {
       from: 0.0.0.0/0   to: .  via: 127.0.0.1 port = 11080
       proxyprotocol: socks_v4
}
--------------------

And my ssh command is this:

ssh -v -f -N -D 11080 user@host

Both gaim and firefox work correctly with the SOCKS proxy in this way.  Also, konqueror works correctly with this setup.  

When I run konqueror and have it use my SOCKS proxy, I see this from ssh's debug (-v) output:

ebug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 1: new [dynamic-tcpip]
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 2: new [dynamic-tcpip]
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 3: new [dynamic-tcpip]
debug1: channel 2: free: direct-tcpip: listening port 11080 for 64.233.187.104 port 443, connect from 127.0.0.1 port 37325, nchannels 4
debug1: channel 3: free: direct-tcpip: listening port 11080 for 64.233.171.105 port 443, connect from 127.0.0.1 port 37326, nchannels 3
debug1: channel 1: free: direct-tcpip: listening port 11080 for 64.233.171.107 port 80, connect from 127.0.0.1 port 37324, nchannels 2


And, as I said, the page actually does come up correctly.  And I see this in both kopete's command line output as well as konqueror's output:

kdecore (KSocks): Found Dante SOCKS
kdecore (KSocks): SOCKS has been activated!


When I run kopete and ask it to connect to my MSN account (though it does this for AIM and ICQ also), here's what I see from my ssh debug:

debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 1: new [dynamic-tcpip]

That's it.  And, while kopete keeps trying to connect to MSN, I see this in dante's output:

Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863
Jan 27 11:09:59 KDE[16533]: Rconnect(): 207.46.104.20.1863                

...

over and over and over again.  And kopete is never able to connect to MSN (or AIM or ICQ).  Since Konqueror is able to use my SOCKS firewall, as is firefox, it seems that the bug is somewhere in kopete.

What else can I give that would be helpful?

Thanks!!!
Comment 1 Matt Rogers 2005-01-27 20:53:42 UTC
This seems to be a regression the functionality of the KNetwork classes vs. KExtendedSocket. Protocols that use KNetwork classes won't connect via proxy. Protocols that use KExtendedSocket should work via proxy. (except IRC, but that's another problem, i'm sure)
Comment 2 Jason 'vanRijn' Kasper 2005-01-27 21:05:00 UTC
I'm hoping some of this helps...

After talking with mattr in #kopete, I've discovered that the ONLY kopete account that I can log into via the SOCKS proxy is a yahoo account.

In addition, I've just used gaim to connect via the SOCKS proxy and it worked fine, using a SOCKS4 setting, and this is what I see from ssh's debug....

debug1: channel 4: free: direct-tcpip: listening port 11080 for 207.46.106.142 port 1863, connect from 127.0.0.1 port 37432, nchannels 5
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 1: new [dynamic-tcpip]
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 4: new [dynamic-tcpip]
debug1: channel 1: free: direct-tcpip: listening port 11080 for 207.46.104.20 port 1863, connect from 127.0.0.1 port 37436, nchannels 6
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 1: new [dynamic-tcpip]
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 6: new [dynamic-tcpip]
debug1: channel 1: free: direct-tcpip: listening port 11080 for 65.54.179.228 port 443, connect from 127.0.0.1 port 37438, nchannels 7
debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug1: channel 1: new [dynamic-tcpip]
debug1: channel 6: free: direct-tcpip: listening port 11080 for 65.54.179.192 port 443, connect from 127.0.0.1 port 37439, nchannels 7
debug1: channel 1: free: direct-tcpip: listening port 11080 for 65.54.179.198 port 443, connect from 127.0.0.1 port 37441, nchannels 6

Hope this helps you guys fix this!!  =:)
Comment 3 Thiago Macieira 2005-01-27 23:31:27 UTC
*** Bug 88766 has been marked as a duplicate of this bug. ***
Comment 4 Ismail Donmez 2005-02-11 11:02:27 UTC
We got report of same problem in Konversation. Looks like a KNetwork problem. Thiago is there a chance of fixing this before 3.4?
Comment 5 Thiago Macieira 2005-02-11 11:55:33 UTC
I hope to!

Unfortunately, I have no working SOCKS proxy, no SOCKS client libraries installed and it's been three years since I've looked at SOCKS code.

For KDE4, I hope to get rid of KSocks dependency on SOCKS client libraries and, instead, write our own SOCKS client code, much as has been done for the HTTP proxy support.
Comment 6 Jason Keirstead 2005-02-11 13:27:26 UTC
Thiago - if you want a SOCKS proxy to test this on, I am sure I can run one for you on my PC here (it is up 24/7). Ping me in private mail if you want me to set one up.
Comment 7 Jason 'vanRijn' Kasper 2005-02-11 13:32:04 UTC
I was just going to add...  The easiest way to do this is to simply install the dante client libraries (rpms are pretty readily available, iirc) and run the SSH command that I have shown above.  SSH can act as a SOCKS4/5 proxy, which means that you don't actually have to set up a SOCKS server--all you have to do is have an SSH tunnel and that will be your SOCKS4/5 proxy server too (ssh -D).

Please forgive if this is stating the obvious.  =:)
Comment 8 Thiago Macieira 2005-02-22 12:02:09 UTC
Raising severity even more.
Comment 9 Thiago Macieira 2005-02-28 03:58:05 UTC
Sorry, debugging indicates nothing wrong in KDE code.

So far, I'm leaning on libdsocks bug. I'll continue investigating.
Comment 10 Thiago Macieira 2005-02-28 04:28:21 UTC
Indeed it's a bug in Dante, but it's one we already had workarounds for.
Comment 11 Thiago Macieira 2005-02-28 04:30:35 UTC
CVS commit by thiago: 

Adding workaround for the Dante bug with asynchronous connection. This
will make a *synchronous* connection every time Dante is used. So, too
bad if you're using Dante, your KDE application will freeze its UI whenever
a socket connects.

For KDE4, I plan to write the SOCKS protocol myself and avoid this kind
of problems.

To be backported.
BUG:98018


  M +17 -1     ksockssocketdevice.cpp   1.7


--- kdelibs/kdecore/network/ksockssocketdevice.cpp  #1.6:1.7
@@ -119,5 +119,21 @@ bool KSocksSocketDevice::connect(const K
     return false;               // failed creating!
 
-  if (KSocks::self()->connect(m_sockfd, address.address(), address.length()) == -1)
+  int retval;
+  if (KSocks::self()->hasWorkingAsyncConnect())
+    retval = KSocks::self()->connect(m_sockfd, address.address(), 
+                                     address.length());
+  else
+    {
+      // work around some SOCKS implementation bugs
+      // we will do a *synchronous* connection here!
+      // FIXME: KDE4, write a proper SOCKS implementation
+      bool isBlocking = blocking();
+      setBlocking(true);
+      retval = KSocks::self()->connect(m_sockfd, address.address(), 
+                                       address.length());
+      setBlocking(isBlocking);
+    }
+
+  if (retval == -1)
     {
       if (errno == EISCONN)


Comment 12 Martin Ellis 2005-02-28 13:29:10 UTC
Hi Thiago,

Thanks so much for looking into this.

> Adding workaround for the Dante bug with asynchronous connection.
Cool.  All working for me in Kopete and Konversation. :o)

Have you reported upstream?

> This will make a *synchronous* connection every time Dante is used.
No big deal, I didn't notice any difference from a normal connect.

Thanks again,
Martin

Comment 13 Thiago Macieira 2005-03-01 01:37:52 UTC
I'm not really sure. It was Waldo Bastian who first found the bug, not me. I'm not sure if he reported it upstream.
Comment 14 Thiago Macieira 2005-03-05 03:30:47 UTC
CVS commit by thiago: 

(Backport 1.6:1.7) Backporting the fix to KDE 3.4.x. Sorry, this didn't
make into 3.4.0.

CCBUG:98018


  M +17 -1     ksockssocketdevice.cpp   1.6.2.1


--- kdelibs/kdecore/network/ksockssocketdevice.cpp  #1.6:1.6.2.1
@@ -119,5 +119,21 @@ bool KSocksSocketDevice::connect(const K
     return false;               // failed creating!
 
-  if (KSocks::self()->connect(m_sockfd, address.address(), address.length()) == -1)
+  int retval;
+  if (KSocks::self()->hasWorkingAsyncConnect())
+    retval = KSocks::self()->connect(m_sockfd, address.address(), 
+                                     address.length());
+  else
+    {
+      // work around some SOCKS implementation bugs
+      // we will do a *synchronous* connection here!
+      // FIXME: KDE4, write a proper SOCKS implementation
+      bool isBlocking = blocking();
+      setBlocking(true);
+      retval = KSocks::self()->connect(m_sockfd, address.address(), 
+                                       address.length());
+      setBlocking(isBlocking);
+    }
+
+  if (retval == -1)
     {
       if (errno == EISCONN)


Comment 15 Thiago Macieira 2005-03-30 16:04:08 UTC
*** Bug 88215 has been marked as a duplicate of this bug. ***