Thread: SSL... too many tcp sessions...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    4

    SSL... too many tcp sessions...

    All:

    I work for an application-service provider.. sort of... anyway. One of our many applications is actually a TN3270/telnet application which has hooks into a microsoft DLL to tunnel/encrypt the user traffic over SSL. So on the network, we see encrypted packets destined to/from port 443.

    This traffic hits a load-balancer that offloads the SSL encrypt/decrypt process.

    We are having an issue where, it seems, everything a single user does (like just login, or pull up a VT100 screen) ends up launching 8-12 TCP connections. Over the course of a day 160 users launched upwards of 90000 tcp sessions. Each session is very predictable. its the same number of packets, and on the server side follows nearly the exact same sequence numbers every time.

    We have many thousands of users that use this application. Needless to say, this is starting to cripple our load balancer.

    Its my belief.. as an ex-programmer from a decade+ ago, that for the duration a user is logged into this app there should be a single TCP session.

    Does anyone know why this might be occuring or if there is someway of fixing this? I am speaking in the broadest possible terms here because I am a network engineer, not a programmer. I will try to get more details if I can.

    Derick
    CCIE 15672

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    SSL is bloatware. Those extra sessions are for key exchange. You would be better off implimenting your own security if you have a mathematician on staff. There realyl is no way aroudn it unless you directly impliment the SSL yourself using the API functions. Going through a 3rd party DLL there is nothign you can do.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    4

    alright...

    So.. I'm guessing that there are multiple passes occuring to InitializeSecurityContext (clienthandshakeloop), and instead of reusing the preexisting connection (I'm guessing by reusing the output-buffer pointer), we are launching a new connection for each exchange with the load-balancer that is doing the SSL offload...


    Is that terribly far off? All 8 or so connections are launched in the same 100ms window. This would mean its the last of the 8 connections that does something useful.

    Not all SSL stuff behaves this way, not even all Secure32.dll stuff, so I'm guessing its coded wrong.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Im guessing its coded wrong as well. It really shouldnt take more than a single session. Personally I impliment our own encryption routines. Its more secure and faster IMO.

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You would be better off implimenting your own security if you have a mathematician on staff.
    It could be more secure for you. Maybe. But telling some dude who is probably not an experienced cryptographer to replace a widely used and quite secure system with something they manage to invent is bad advice IMO.

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by mike_g View Post
    It could be more secure for you. Maybe. But telling some dude who is probably not an experienced cryptographer to replace a widely used and quite secure system with something they manage to invent is bad advice IMO.
    I made no such recommendation. As I stated 'if you have a mathemetician on staff'. Not just some yahoo that can add and subtract, but a fully qualified professional mathemetician. Sorry if I didnt put in the 'fully qualified professional' qualification. In general when I say programmer that doesnt mean 'some kid that can write a web page', but 'a fully qualified professional programmer'. Most people understand this.
    Last edited by abachler; 05-06-2008 at 10:17 AM.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by ccie15672 View Post
    We are having an issue where, it seems, everything a single user does (like just login, or pull up a VT100 screen) ends up launching 8-12 TCP connections.
    Ok, this is almost surely a consequence of the of that DLL you are using. If you look here, you'll see both ports are unassigned. My guess is the DLL behavior is to establish connections on those ports. Why it does it, is left for speculation. What's the DLL?

    As far as I know, you are generally right when you say it should use only one TCP connection for the duration of the session. However, something in your description doesn't fit and its probably worth looking at; the immediate problem that caught my attention is that you seem to be establishing connections on the wrong port. 443, aka https is meant for http connections over TLS/SSL. However you mention the use of a terminal emulation application. On this case, the correct protocol should be SSH, Secure Shell, on port 22.

    Worth taking a look at.

    Meanwhile, is the 8-12 connection being maintained by the DLL? That is, is it listening on one of these two ports, while some other process is connecting through the other port? Which process?

    Basically, describe exactly what connections are taking place and their players.

    EDIT: There's more to be said about your probable problem. For instance, it's quiet possible the DLL uses that connection to emulate SCP and FTPS connections... but first, your answers
    Last edited by Mario F.; 05-07-2008 at 08:54 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    4

    hello all

    Well then.

    Since I originally posted, I have gained a great deal of clarity on what is going on with this app.

    First, it is not actually tunneling tn3270 over SSL. It is, in fact, HTTP over SSL. So there is a front-end "option" that makes it look like TN3270, but when the user does a query or fills in the fields on the "screen" and hits send, its actually an HTTP Post that goes out. Users don't have to use the tn3270 screen option. In this case, its a web page with numerous elements. These elements each must hit the server querying for specific information or submitting specific information. All of this is done with HTTP posts.

    They are using Wininet.

    Essentially every query or transaction for each element results in a new TCP connection over which a single HTTP post is "executed." If an element refreshes... its a new TCP connection. All elements on all pages hit the same server with the same certificate.

    Users who do not have publicly registered certificates... each transaction/query ends up being two TCP connections. This happens for unknown reasons, but a capture/decrypt shows the first TCP session there is a certificate/key exchange and then the connection is FIN'd straight away. Then the second connection is opened and the data is exchanged.

    So a page with 5 or 6 elements may end up launching 10 or 12 TCP connections straight away to load all the elements.



    Isn't this supposed to be what HTTP persistent connections are for? Couldn't they re-use the handle that is returned when they initially login to the server?

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    yes,they could, apparently they didn't. Welcome to the reality of programming.

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    4
    Hey one last update..

    To make a long story short, our programmers admitted to not implementing HTTP "persistent connections" as specified in RFC 2616, Section 8.1. See HTTP spec here.

    So now they are moving forward with that. Also the double TCP connections for unsigned/unregistered certificates is a known issue with the WinInet DLL they were using, so they are abandoning it for winhttp.

    The end!

    Thanks for the replies. I bought a C programming book because all of this. I should read it one of these days.

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Well, given that all programmers are usually working under unrealistic time constraints, you should feel lucky it works at all. I'm rewriting a class that took 2 months to write the first time, so of course the boss expects the rewrite to take 2 days because ' you can reuse the old code'. If the old code was worth reusing, we wouldn't be doing a rewrite, but whatever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TCP Header problem (error)
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-25-2008, 07:30 AM
  2. Accessing TCP flags in TCP packets on Linux using C !!
    By vishamr in forum Linux Programming
    Replies: 2
    Last Post: 10-16-2006, 08:48 AM
  3. SSL and 503 FTP Error :: Socket
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-18-2005, 04:15 PM
  4. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  5. TCP TIME_WAIT state
    By Engineer in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-27-2001, 08:50 AM