Class: Snxvpn::ExtInfo

Inherits:
Hash
  • Object
show all
Defined in:
lib/snxvpn/ext_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ ExtInfo

Returns a new instance of ExtInfo.



5
6
7
# File 'lib/snxvpn/ext_info.rb', line 5

def initialize(body)
  update Hash[body.scan(/Extender.(\w+) *= *"(.*?)" *;/)]
end

Instance Method Details

#payloadObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/snxvpn/ext_info.rb', line 9

def payload
  host_ip = IPAddr.new(IPSocket.getaddress(self['host_name']))
  snxinf  = [
    "\x13\x11\x00\x00".encode('binary'),  # 4-byte magic
    [976].pack('L<'),                     # 4-byte data length
    [host_ip.to_i].pack('L<'),            # 4-byte host IP
    self['host_name'].encode('binary').ljust(64, "\0"), # 64 bytes
    [self['port'].to_i].pack('L<'),     # 4-byte port
    ''.encode('binary').ljust(6, "\0"),   # 6-bytes blank
    self['server_cn'].encode('binary').ljust(256, "\0"), # 256 bytes
    self['user_name'].encode('binary').ljust(256, "\0"), # 256 bytes
    self['password'].encode('binary').ljust(128, "\0"),  # 128 bytes
    self['server_fingerprint'].encode('binary').ljust(256, "\0"), # 256 bytes
    "\x01\x00".encode('binary'), # 2 bytes
  ].join
end