> Hello,

> > David,
> > Perfect - thanks!
> > Peeking at the first byte with recv(sock, buffer, 1, MSG_PEEK) works :-)
> > I'm not very familiar with the SSL handshake. What are the
> chances of a "G"
> > or "P" being the first byte of the handshake itself?

> This is not good solution,

Yep, that's the first thing I said.

> what if you get OPTIONS, HEAD and many more
> HTTP keywords ?  What if new HTTP keywords will be created in the
> feature ? You will have deadlock.

You deadlock only in the case where someone has already connected to the
wrong port with the wrong protocol. IMO, it's much more important that you
don't fail when someone connects with the right protocol.

What if new SSL/TLS protocols are created in the future and have a different
first byte?

> Get first byte and check if this byte is 0x16 (SSL3/TLS1 handshake
> packet) or 0x80 (SSL2 handshake packet) and if you will get one
> of these, run SSL negotiation, otherwise process clear HTTP request.

This will *definitely* break if a new SSL/TLS protocol ever changes the
first byte sent. While this is less likely to happen, the failure in this
case is complete, even for clients using the right protocol on the right
port.

So it comes down to which of two possible failures you consider worse:

1) Unlikely to happen, but if it happens, you do the wrong thing when
everyone else does the right thing.

2) More likely to happen, but if it happens, only a client that was messed
up in the first place suffers any problems.

Note that this argument does not apply if I misunderstood the OP. The
impression I got was that this was an HTTPS server port and connection to it
with HTTP was an error on the part of the client.

The problem with trying to do two protocol on the same port, when the
protocols were not designed to be distinguishable, is that you run into
problems if you cannot guarantee that the two protocols do not remain
completely distinguishable.

I guess you can make a list of all the HTTP verbs you support and check for
the first characters of each. Again though, this is an ugly situation to be
in.

DS


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to