Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:36:34+00:00 2026-05-17T17:36:34+00:00

I’m writing a server which is accepting incoming TCP connections. Let’s suppose the server

  • 0

I’m writing a server which is accepting incoming TCP connections. Let’s suppose the server has accepted a TCP connection, and has already received 16 (or so) bytes from the client. Knowing those 16 bytes how can the server detect whether the client wants to initiate an SSL handshake?

I’ve made an experiment, which showed that on my Linux system connecting to localhost (either 127.0.0.1 or AF_UNIX) via SSL makes the client send the following handshake (hexdump), followed by 16 seemingly random bytes:

8064010301004b0000001000003900003800003500001600001300000a07
00c000003300003200002f03008000000500000401008000001500001200
0009060040000014000011000008000006040080000003020080

How should the server probe these first few bytes, just to be able to determine whether the client is sending an SSL handshake? The probe must return true for all valid SSL handshakes, and it must return false with high probability for a message sent by the client which is not an SSL handshake. It is not allowed to use any libraries (like OpenSSL) for the probe. The probe must be a simple code (like a few dozen lines in C or Python).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:36:35+00:00Added an answer on May 17, 2026 at 5:36 pm

    I could figure this out based on the implementation of the ClientHello.parse method in
    http://tlslite.cvs.sourceforge.net/viewvc/tlslite/tlslite/tlslite/messages.py?view=markup

    I am giving two solutions here in Python. IsSSlClientHandshakeSimple is a simple regexp, which can yield some false positives quite easily; IsSslClientHandshake is more complicated: it checks the consistency of lengths, and the range of some other numbers.

    import re
    
    def IsSslClientHandshakeSimple(buf):
      return bool(re.match(r'(?s)\A(?:\x80[\x0f-\xff]\x01[\x00-\x09][\x00-\x1f]'
                           r'[\x00-\x05].\x00.\x00.|'
                           r'\x16[\x2c-\xff]\x01\x00[\x00-\x05].'
                           r'[\x00-\x09][\x00-\x1f])', buf))
    
    def IsSslClientHandshake(buf):
      if len(buf) < 2:  # Missing record header.
        return False
      if len(buf) < 2 + ord(buf[1]):  # Incomplete record body.
        return False
      # TODO(pts): Support two-byte lengths in buf[1].
      if ord(buf[0]) == 0x80:  # SSL v2.
        if ord(buf[1]) < 9:  # Message body too short.
          return False
        if ord(buf[2]) != 0x01:  # Not client_hello.
          return False
        if ord(buf[3]) > 9:  # Client major version too large. (Good: 0x03)
          return False
        if ord(buf[4]) > 31:  # Client minor version too large. (Good: 0x01)
          return False
        cipher_specs_size = ord(buf[5]) << 8 | ord(buf[6])
        session_id_size = ord(buf[7]) << 8 | ord(buf[8])
        random_size = ord(buf[9]) << 8 | ord(buf[10])
        if ord(buf[1]) < 9 + cipher_specs_size + session_id_size + random_size:
          return False
        if cipher_specs_size % 3 != 0:  # Cipher specs not a multiple of 3 bytes.
          return False
      elif ord(buf[0]) == 0x16:  # SSL v1.
        # TODO(pts): Test this.
        if ord(buf[1]) < 39:  # Message body too short.
          return False
        if ord(buf[2]) != 0x01:  # Not client_hello.
          return False
        head_size = ord(buf[3]) << 16 | ord(buf[4]) << 8 | ord(buf[5])
        if ord(buf[1]) < head_size + 4:  # Head doesn't fit in message body.
          return False
        if ord(buf[6]) > 9:  # Client major version too large. (Good: 0x03)
          return False
        if ord(buf[7]) > 31:  # Client minor version too large. (Good: 0x01)
          return False
        # random is at buf[8 : 40]
        session_id_size = ord(buf[40])
        i = 41 + session_id_size
        if ord(buf[1]) < i + 2:  # session_id + cipher_suites_size doesn't fit.
          return False
        cipher_specs_size = ord(buf[i]) << 8 | ord(buf[i + 1])
        if cipher_specs_size % 2 != 0:
          return False
        i += 2 + cipher_specs_size
        if ord(buf[1]) < i + 1: # cipher_specs + c..._methods_size doesn't fit.
          return False
        if ord(buf[1]) < i + 1 + ord(buf[i]): # compression_methods doesn't fit.
          return False
      else:  # Not SSL v1 or SSL v2.
        return False
    return True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am writing an app with both english and french support. The app requests
I have a text area in my form which accepts all possible characters from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.