Class: Rex::Proto::Http::WebSocket::Frame
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- Rex::Proto::Http::WebSocket::Frame
- Defined in:
- lib/rex/proto/http/web_socket.rb
Class Method Summary collapse
- .apply_masking_key(data, mask) ⇒ Object
- .from_binary(value, last: true, mask: true) ⇒ Object
- .from_text(value, last: true, mask: true) ⇒ Object
Instance Method Summary collapse
-
#mask!(key = nil) ⇒ String
Update the frame instance in place to apply a masking key to the payload data as defined in RFC 6455 section 5.3.
- #payload_len ⇒ Object
- #payload_len=(value) ⇒ Object
-
#unmask! ⇒ String
Update the frame instance in place to apply a masking key to the payload data as defined in RFC 6455 section 5.3.
Class Method Details
.apply_masking_key(data, mask) ⇒ Object
379 380 381 382 383 384 385 386 387 |
# File 'lib/rex/proto/http/web_socket.rb', line 379 def self.apply_masking_key(data, mask) mask = [mask].pack('N').each_byte.to_a xored = '' data.each_byte.each_with_index do |byte, index| xored << (byte ^ mask[index % 4]).chr end xored end |
Instance Method Details
#mask!(key = nil) ⇒ String
Update the frame instance in place to apply a masking key to the payload data as defined in RFC 6455 section 5.3.
402 403 404 405 406 407 408 |
# File 'lib/rex/proto/http/web_socket.rb', line 402 def mask!(key = nil) header.masked.assign(1) key = rand(1..0xffffffff) if key.nil? header.masking_key.assign(key) payload_data.assign(self.class.apply_masking_key(payload_data, header.masking_key)) payload_data.value end |
#payload_len ⇒ Object
420 421 422 423 424 425 426 427 428 429 |
# File 'lib/rex/proto/http/web_socket.rb', line 420 def payload_len case header.payload_len_sm when 127 header.payload_len_lg when 126 header.payload_len_md else header.payload_len_sm end end |
#payload_len=(value) ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/rex/proto/http/web_socket.rb', line 431 def payload_len=(value) if value < 126 header.payload_len_sm.assign(value) elsif value < 0xffff header.payload_len_sm.assign(126) header.payload_len_md.assign(value) elsif value < 0x7fffffffffffffff header.payload_len_sm.assign(127) header.payload_len_lg.assign(value) else raise ArgumentError, 'payload length is outside the acceptable range' end end |
#unmask! ⇒ String
Update the frame instance in place to apply a masking key to the payload data as defined in RFC 6455 section 5.3.
414 415 416 417 418 |
# File 'lib/rex/proto/http/web_socket.rb', line 414 def unmask! payload_data.assign(self.class.apply_masking_key(payload_data, header.masking_key)) header.masked.assign(0) payload_data.value end |