# SSLv2 bad detection, patch

**URL:** <https://www.ruby-forum.com/t/sslv2-bad-detection-patch/190958>\
**Category:** NGINX\
**Created:** [July 1, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/sslv2-bad-detection-patch/190958 "2010-07-01T17:01:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MirosSSSS\_aw\_Jawors](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@MirosSSSS\_aw\_Jawors](https://www.ruby-forum.com/u/MirosSSSS_aw_Jawors)\
**Post date:** [July 1, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/sslv2-bad-detection-patch/190958/1 "2010-07-01T17:01:34Z")

</div>

Problem:  
old web application supporting SSLv2 only can’t connect to the  
web service migrated behind ssl-offloading nginx.

Analysis:  
nginx considers connection as plain http. Traffic analysis using  
various client options shows that 0x80 isn’t the only possibility  
to show up as first byte in ssl client hello.

Nginx code excerpt ( nginx-0.7.67, src/http/ngx\_http\_request.c:551 ):  
if (buf[0] == 0x80 /\* SSLv2 _/ || buf[0] == 0x16 /_ SSLv3/TLSv1  
\*/) {  
^^

openssl code excerpt ( openssl-0.9.8k, as such version is installed on  
server side, ssl/s23\_srvr.c:268 ):

```
            if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
                      ^^

```

Difference in SSL logic detection underlined.

Solution:  
Fix SSLv2 detection. Patch attached.

---

<div class="post-metadata">

**Author:** ![MirosSSSS\_aw\_Jawors](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@MirosSSSS\_aw\_Jawors](https://www.ruby-forum.com/u/MirosSSSS_aw_Jawors)\
**Post date:** [July 1, 2010, 7:01pm UTC](https://www.ruby-forum.com/t/sslv2-bad-detection-patch/190958/2 "2010-07-01T19:01:36Z")

</div>

Hello!

On Thu, Jul 01, 2010 at 05:00:49PM +0200, MirosÅ‚aw Jaworski wrote:

> Problem:  
> old web application supporting SSLv2 only can’t connect to the  
> web service migrated behind ssl-offloading nginx.
> 
> Analysis:  
> nginx considers connection as plain http. Traffic analysis using  
> various client options shows that 0x80 isn’t the only possibility  
> to show up as first byte in ssl client hello.

A bit more details analisys:

Non-0x80 first byte indicate that message length is more than 255  
bytes. Session id and challenge data in client hello are  
limited to 16 and 32 bytes, and fixed fields use 9 bytes, this  
gives us something about 198 bytes for cipher specs, i.e. 66  
ciphers listed. Typical openssl have about 30 ciphers by default,  
so 66 isn’t something unrealistic.

In fact, first byte may not even contain high bit set if message  
length is more than 32k. But it’s really unlike to happen in real  
life (and won’t work with openssl at least as far as I see).

See here for SSLv2 specs:

> **[Network Security Services (NSS) — Firefox Source Docs documentation](https://firefox-source-docs.mozilla.org/security/nss/index.html)**

> Difference in SSL logic detection underlined.  
> Actually, the openssl also checks first byte of message as you can  
> see here. But just checking for & 0x80 should be fine as it  
> catches typical http-to-https case.

> Solution:  
> Fix SSLv2 detection. Patch attached.

Thanks for the patch. Looks good for me.

Maxim D.
