def web_socket_do_extra_handshake(request):
    message = 'HTTP/1.1 401 Unauthorized\r\n'
    message += 'WWW-Authenticate: Basic realm="Access to staging site"\r\n'
    message += '\r\n'
    request.connection.write(message)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
def web_socket_transfer_data(request):
    # pywebsocket does not mask message by default. We need to build a frame
    # manually to mask it.
    request.connection.write(
        stream.create_text_frame('First message', mask=False))

    request.connection.write(
        stream.create_text_frame(
            'Fragmented ', opcode=common.OPCODE_TEXT, fin=0, mask=False))
    request.connection.write(
        stream.create_text_frame(
            'message', opcode=common.OPCODE_CONTINUATION, fin=1, mask=False))

    request.connection.write(stream.create_text_frame('', mask=False))

    msgutil.send_message(request, 'END')

    # Wait for the client to start closing handshake. To receive a close frame,
    # we must use an internal method of request.ws_stream.
    opcode, payload, final, reserved1, reserved2, reserved3 = \
        request.ws_stream._receive_frame()
    assert opcode == common.OPCODE_CLOSE
    assert final
    assert not reserved1
    assert not reserved2
    assert not reserved3

    # Send a masked close frame. Clients should be able to handle this frame
    # and the WebSocket object should be closed cleanly.
    request.connection.write(stream.create_close_frame('', mask=False))

    # Prevents pywebsocket from starting its own closing handshake.
    raise handshake.AbortedByUserException('Abort the connection')
Esempio n. 3
0
def web_socket_do_extra_handshake(request):
    msg = b'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
    msg += (b'p' * 1024) + b'\r\n'
    msg += b'\r\n'
    request.connection.write(msg)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
def web_socket_do_extra_handshake(request):
    message = 'HTTP/1.1 101 Switching Protocols\r\n'
    message += 'Upgrade: websocket\r\n'
    message += 'Connection: Upgrade\r\n'
    message += 'Sec-WebSocket-Accept: XXXXthisiswrongXXXX\r\n'
    message += '\r\n'
    request.connection.write(message.encode())
    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    message = 'HTTP/1.0 101 Switching Protocols\r\n'
    message += 'Upgrade: websocket\r\n'
    message += 'Connection: Upgrade\r\n'
    message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    message += '\r\n'
    request.connection.write(message)
    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
Esempio n. 6
0
def web_socket_do_extra_handshake(request):
    msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
           b'Upgrade: websocket\r\n'
           b'Connection: Upgrade\r\n'
           b'Sec-WebSocket-Accept: 3rfd')
    request.connection.write(msg)
    # Prevent pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Close the connection')
Esempio n. 7
0
def web_socket_do_extra_handshake(request):
    msg = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
    msg += ("p" * 1024) + "\r\n"
    msg += "\r\n"
    msg += request.ws_challenge_md5
    request.connection.write(msg)
    raise handshake.AbortedByUserException(
        "Abort the connection"
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    #   Missing 'Upgrade: websocket\r\n'
    msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
           b'Connection: Upgrade\r\n'
           b'Sec-WebSocket-Accept: %s\r\n'
           b'\r\n') % compute_accept_from_unicode(request.headers_in['Sec-WebSocket-Key'])
    request.connection.write(msg)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
def web_socket_transfer_data(request):
    msg = "\0hello\xff"
    msg += "\x80\x81\x01"  # Skip 1*128+1 bytes.
    msg += "\x01\xff"
    msg += "\0should be skipped\xff"
    request.connection.write(msg)
    raise handshake.AbortedByUserException(
        "Abort the connection"
    )  # Prevents pywebsocket from starting closing handshake.
def web_socket_do_extra_handshake(request):
    msg = 'HTTP/1.1 101 Switching Protocols\r\n'
    msg += 'Upgrade: websocket\r\n'
    msg += 'Connection: Upgrade\r\n'
    msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    msg += 'Sec-WebSocket-Extensions: x-webkit-deflate-frame\r\n'
    msg += 'Sec-WebSocket-Extensions: foo\r\n'
    msg += '\r\n'
    request.connection.write(msg)
    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
Esempio n. 11
0
def web_socket_transfer_data(request):
    # Send three messages, and then wait for three messages.
    msgutil.send_message(request, '1')
    msgutil.send_message(request, '2')
    msgutil.send_message(request, '3')

    for expected in (u'1', u'2', u'3'):
        message = msgutil.receive_message(request)
        if type(message) != str or message != expected:
            raise handshake.AbortedByUserException('Abort the connection')
Esempio n. 12
0
def web_socket_do_extra_handshake(request):
    accept = compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    message = ('HTTP/1.1 101 Switching Protocols\r\n'
               'Upgrade: websocket\r\n'
               'Connection: Upgrade\r\n'
               'Sec-WebSocket-Accept: %s\r\n'
               'Sec-WebSocket-Protocol: sip \r\n'
               '\r\n' % accept)
    request.connection.write(message)
    # Prevent pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Close the connection')
def web_socket_do_extra_handshake(request):
    # This will cause the handshake to fail because it pushes the length of the
    # status line past 1024 characters
    msg = '.' * 1024
    msg += 'HTTP/1.1 101 Switching Protocols\r\n'
    msg += 'Upgrade: websocket\r\n'
    msg += 'Connection: Upgrade\r\n'
    msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    msg += '\r\n'
    request.connection.write(msg)
    raise handshake.AbortedByUserException('abort the connection') # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    msg = 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
#   Missing 'Upgrade: WebSocket\r\n'
    msg += 'Connection: Upgrade\r\n'
    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
    msg += '\r\n'
    msg += request.ws_challenge_md5
    request.connection.write(msg)
    print msg
    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
Esempio n. 15
0
def web_socket_do_extra_handshake(request):
    msg = b"HTTP/1.1 101 Switching Protocols\r\n"
    msg += b"Upgrade: websocket\r\n"
    msg += b"Connection: Upgrade\r\n"
    msg += b"Sec-WebSocket-Accept: "
    msg += compute_accept_from_unicode(request.headers_in["Sec-WebSocket-Key"])
    msg += b"\xa5:\r\n"
    msg += b"\r\n"
    request.connection.write(msg)
    print(msg)
    raise handshake.AbortedByUserException("Abort the connection") # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    msg = b'HTTP/1.1 101 Switching Protocols\n'  # Does not end with "\r\n".
    msg += b'Upgrade: websocket\r\n'
    msg += b'Connection: Upgrade\r\n'
    msg += b'Sec-WebSocket-Accept: '
    msg += compute_accept_from_unicode(request.headers_in['Sec-WebSocket-Key'])
    msg += b'\r\n\r\n'
    request.connection.write(msg)
    print(msg)
    raise handshake.AbortedByUserException(
        'Abort the connection'
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    message = b'HTTP/1.1 101 Switching Protocols\r\n'
    message += b'Upgrade: websocket\r\n'
    message += b'Connection: Upgrade\r\n'
    message += b'Sec-WebSocket-Accept: '
    message += compute_accept_from_unicode(
        request.headers_in['Sec-WebSocket-Key'])
    message += 'Sec-WebSocket-Protocol: Non-áscii-value\r\n'.encode()
    message += b'\r\n\r\n'
    request.connection.write(message)
    raise handshake.AbortedByUserException(
        'Abort the connection'
    )  # Prevents pywebsocket from sending its own handshake message.
Esempio n. 18
0
def web_socket_do_extra_handshake(request):
  accept = compute_accept(
      request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
  message = (b'HTTP/1.1 101 Switching Protocols\r\n'
             b'Upgrade: websocket\r\n'
             b'Connection: Upgrade\r\n'
             b'Sec-WebSocket-Accept: %s\r\n'
             b'Sec-WebSocket-Extensions: permessage-deflate;\r\n'
             b'  server_max_window_bits=10\r\n'
             b'\r\n' % accept)
  request.connection.write(message)
  # Prevent pywebsocket from sending its own handshake message.
  raise handshake.AbortedByUserException('Close the connection')
Esempio n. 19
0
def web_socket_do_extra_handshake(request):
    msg = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
    msg += "Upgrade: WebSocket\r\n"
    msg += "Connection: Upgrade\r\n"
    msg += "Sec-WebSocket-Location: " + request.ws_location + "\r\n"
    msg += "Sec-WebSocket-Origin: " + request.ws_origin + "\r\n"
    msg += "\xa5:\r\n"
    msg += "\r\n"
    msg += request.ws_challenge_md5
    request.connection.write(msg)
    print msg
    raise handshake.AbortedByUserException(
        "Abort the connection"
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    frame = stream.create_text_frame('Frame-contains-thirty-one-bytes')

    message = frame
    message += 'HTTP/1.1 101 Switching Protocols non-ascií\r\n'
    message += 'Upgrade: websocket\r\n'
    message += 'Connection: Upgrade\r\n'
    message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(
        request.headers_in['Sec-WebSocket-Key'])[0]
    message += '\r\n'
    request.connection.write(message)
    raise handshake.AbortedByUserException(
        'Abort the connection'
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    message = b'HTTP/1.1 101 Switching Protocols\r\n'
    message += b'Upgrade: websocket\r\n'
    message += b'Connection: Upgrade\r\n'
    message += b'WebSocket-Origin: http://localhost:8880\r\n'
    message += b'WebSocket-Location: ws://localhost:8880/bogus\r\n'
    message += b'Sec-WebSocket-Accept: '
    message += compute_accept_from_unicode(
        request.headers_in['Sec-WebSocket-Key'])
    message += b'\r\n\r\n'
    request.connection.write(message)
    raise handshake.AbortedByUserException(
        'Abort the connection'
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):

    resources = request.ws_resource.split('?', 1)
    parameter = None
    if len(resources) == 2:
        parameter = resources[1]
        message = 'HTTP/'
        message += parameter
        message += ' 101 Switching Protocols\r\n'
    message += 'Upgrade: websocket\r\n'
    message += 'Connection: Upgrade\r\n'
    message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    message += '\r\n'
    request.connection.write(message)
    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    # This will cause the handshake to fail because it pushes the length of the
    # status line past 1024 characters
    msg = '.' * 1024
    msg += 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
    msg += 'Upgrade: WebSocket\r\n'
    msg += 'Connection: Upgrade\r\n'
    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
    msg += '\r\n'
    msg += request.ws_challenge_md5
    request.connection.write(msg)
    raise handshake.AbortedByUserException(
        'abort the connection'
    )  # Prevents pywebsocket from sending its own handshake message.
def web_socket_do_extra_handshake(request):
    resources = request.ws_resource.split('?', 1)
    parameters = None
    if len(resources) == 2:
        parameters = parse.unquote(resources[1])

    message = b'HTTP/1.1 101 Switching Protocols\r\n'
    message += b'Upgrade: websocket\r\n'
    message += b'Connection: Upgrade\r\n'
    message += b'Sec-WebSocket-Accept: ' + compute_accept(
        request.headers_in['Sec-WebSocket-Key'])
    message += b'\r\nSec-WebSocket-Extensions: permessage-deflate'
    if parameters:
        message += b'; ' + parameters.encode()
    message += '\r\n\r\n'
    request.connection.write(message)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
Esempio n. 25
0
def web_socket_do_extra_handshake(request):
    resources = request.ws_resource.split('?', 1)
    parameters = None
    if len(resources) == 2:
        parameters = urllib.unquote(resources[1])

    message = 'HTTP/1.1 101 Switching Protocols\r\n'
    message += 'Upgrade: websocket\r\n'
    message += 'Connection: Upgrade\r\n'
    message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
    message += 'Sec-WebSocket-Extensions: x-webkit-deflate-frame'
    if parameters:
        message += '; %s\r\n' % parameters
    else:
        message += '\r\n'
    message += '\r\n'
    request.connection.write(message)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
Esempio n. 26
0
def web_socket_transfer_data(request):
    msg = 16 * '\xff'
    request.connection.write(msg)
    raise handshake.AbortedByUserException(
        'Abort the connection'
    )  # Prevents pywebsocket from starting closing handshake.
Esempio n. 27
0
def web_socket_transfer_data(request):
    raise handshake.AbortedByUserException("abort for test")
Esempio n. 28
0
def web_socket_do_extra_handshake(request):
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')
Esempio n. 29
0
def web_socket_do_extra_handshake(request):
    raise handshake.AbortedByUserException(
        "Aborted in web_socket_do_extra_handshake")
def web_socket_do_extra_handshake(request):
    message = b'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n'
    request.connection.write(message)
    # Prevents pywebsocket from sending its own handshake message.
    raise handshake.AbortedByUserException('Abort the connection')