Class: VNCRec::RFB::Authentication::Abstract
- Inherits:
-
Object
- Object
- VNCRec::RFB::Authentication::Abstract
- Defined in:
- lib/vncrec/rfb/authentication.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#get_security_types ⇒ Object
Once the protocol version has been decided, the server and client must agree on the type of security to be used on the connection.
- #handle_types(types) ⇒ Object
- #handshake ⇒ Object
-
#initialize(io, *args) ⇒ Abstract
constructor
A new instance of Abstract.
- #perform_authentication ⇒ Object
-
#security_result ⇒ Object
The server sends a word to inform the client whether the security handshaking was successful.
-
#send_type ⇒ Object
If the server listed at least one valid security type supported by the client, the client sends back a single byte indicating which security type is to be used on the connection.
- #to_msg ⇒ Object
Constructor Details
#initialize(io, *args) ⇒ Abstract
Returns a new instance of Abstract.
5 6 7 |
# File 'lib/vncrec/rfb/authentication.rb', line 5 def initialize(io, *args) @io = io end |
Instance Method Details
#get_security_types ⇒ Object
Once the protocol version has been decided, the server and client must agree on the type of security to be used on the connection. The server lists the security types that it supports:
--------------------------————--------------------------- | No. of bytes | Type | Description | | | [Value] | | --------------------------————--------------------------- | 1 | U8 | number-of-security-types | | number-of-security-types | U8 array | security-types | --------------------------————--------------------------- If the server listed at least one valid security type supported by the client, the client sends back a single byte indicating which security type is to be used on the connection:
+--------------+--------------+---------------+
| No. of bytes | Type [Value] | Description |
+--------------+--------------+---------------+
| 1 | U8 | security-type |
+--------------+--------------+---------------+
If number-of-security-types is zero, then for some reason the connection failed (e.g., the server cannot support the desired protocol version). This is followed by a string describing the reason (where a string is specified as a length followed by that many ASCII characters):
+---------------+--------------+---------------+
| No. of bytes | Type [Value] | Description |
+---------------+--------------+---------------+
| 4 | U32 | reason-length |
| reason-length | U8 array | reason-string |
+---------------+--------------+---------------+
The server closes the connection after sending the reason-string.
@return [Integer] types
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vncrec/rfb/authentication.rb', line 57 def get_security_types num_of_st = @io.readbyte if num_of_st == 0 # failed reason_len = @io.readpartial(4).unpack('L>')[0] reason = @io.readpartial(reason_len) raise reason else result = [] num_of_st.times do result << @io.readbyte end result end end |
#handle_types(types) ⇒ Object
72 73 74 |
# File 'lib/vncrec/rfb/authentication.rb', line 72 def handle_types(types) raise 'The server does not support requested auth method' unless types.include? @code end |
#handshake ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/vncrec/rfb/authentication.rb', line 13 def handshake types = get_security_types handle_types(types) send_type perform_authentication security_result end |
#perform_authentication ⇒ Object
113 114 115 |
# File 'lib/vncrec/rfb/authentication.rb', line 113 def perform_authentication raise 'NI' end |
#security_result ⇒ Object
The server sends a word to inform the client whether the security handshaking was successful.
+--------------+--------------+-------------+
| No. of bytes | Type [Value] | Description |
+--------------+--------------+-------------+
| 4 | U32 | status: |
| | 0 | OK |
| | 1 | failed |
+--------------+--------------+-------------+
If unsuccessful, the server sends a string describing the reason for the failure, and then closes the connection:
+---------------+--------------+---------------+
| No. of bytes | Type [Value] | Description |
+---------------+--------------+---------------+
| 4 | U32 | reason-length |
| reason-length | U8 array | reason-string |
+---------------+--------------+---------------+
104 105 106 107 108 109 110 111 |
# File 'lib/vncrec/rfb/authentication.rb', line 104 def security_result word = (@io.readpartial 4).unpack('L>').first if word != 0 reason_len = (@io.readpartial 4).unpack('L>').first reason = @io.readpartial(reason_len) raise reason end end |
#send_type ⇒ Object
If the server listed at least one valid security type supported by the client, the client sends back a single byte indicating which security type is to be used on the connection.
79 80 81 |
# File 'lib/vncrec/rfb/authentication.rb', line 79 def send_type @io.syswrite to_msg end |
#to_msg ⇒ Object
9 10 11 |
# File 'lib/vncrec/rfb/authentication.rb', line 9 def to_msg [@code].pack('C') end |