Skip to content

Instantly share code, notes, and snippets.

@simlegate
Last active November 16, 2015 15:56
Show Gist options
  • Save simlegate/5a36407963168a2d88b0 to your computer and use it in GitHub Desktop.
Save simlegate/5a36407963168a2d88b0 to your computer and use it in GitHub Desktop.

Revisions

  1. simlegate revised this gist Nov 16, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sec_websocket_key_rule.rb
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@

    # Digest::SHA1.base64digest(sec_websoekct_key + token)

    # NOTICE!! hexdigest is invalid.
    encrypted = Digest::SHA1.digest(sec_websoekct_key + token)

    sec_websokect_accept = Base64.encode64(encrypted).strip
  2. simlegate created this gist Nov 16, 2015.
    33 changes: 33 additions & 0 deletions sec_websocket_key_rule.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    require 'digest/sha1'
    require 'base64'

    # client request
    # GET / HTTP/1.1
    # Upgrade: websocket
    # Connection: Upgrade
    # Host: example.com
    # Origin: null
    # Sec-WebSocket-Key: sN9cRrP/n9NdMgdcy2VJFQ==
    # Sec-WebSocket-Version: 13

    # server response
    # HTTP/1.1 101 Switching Protocols
    # Upgrade: websocket
    # Connection: Upgrade
    # Sec-WebSocket-Accept: fFBooB7FAkLlXgRSz0BT3v4hq5s=
    # Sec-WebSocket-Origin: null
    # Sec-WebSocket-Location: ws://example.com/

    sec_websoekct_key = 'sN9cRrP/n9NdMgdcy2VJFQ=='

    p "sec_websoekct_key is #{sec_websoekct_key}"

    token = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'

    # Digest::SHA1.base64digest(sec_websoekct_key + token)

    encrypted = Digest::SHA1.digest(sec_websoekct_key + token)

    sec_websokect_accept = Base64.encode64(encrypted).strip

    p "generated sec_websokect_accept is #{sec_websokect_accept}"