Class: Analyzers::CbcMac::VariableLength::Oracles::Tcp

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb

Instance Method Summary collapse

Constructor Details

#initialize(mac_host = '54.165.60.84', mac_port = 81, verify_host = '54.165.60.84', verify_port = 82) ⇒ Tcp

Returns a new instance of Tcp.



8
9
10
11
12
13
14
15
# File 'lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb', line 8

def initialize(mac_host = '54.165.60.84', mac_port = 81, verify_host = '54.165.60.84', verify_port = 82)
  @mac_host      = mac_host
  @mac_port      = mac_port
  @verify_host   = verify_host
  @verify_port   = verify_port
  @mac_socket    = nil
  @verify_socket = nil
end

Instance Method Details

#connectObject



16
17
18
19
20
# File 'lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb', line 16

def connect
  @mac_socket    = TCPSocket.open(@mac_host,@mac_port)
  @verify_socket = TCPSocket.open(@verify_host,@verify_port)
  #puts "Connected to server successfully."
end

#disconnectObject

puts “Connected to server successfully.”



21
22
23
24
# File 'lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb', line 21

def disconnect
  @verify_socket.close if @verfiy_socket
  @mac_socket.close    if @mac_socket
end

#mac(message) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb', line 26

def mac(message)
  connect unless @mac_socket
  packet = assemble_mac_message(message)

  @mac_socket.write(packet)
  @mac_socket.read(16)
end

#verify(message, tag) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/crypto-toolbox/analyzers/cbc_mac/variable_length/oracles/tcp.rb', line 34

def verify(message,tag)
  connect unless @verify_socket

  packet = assemble_verify_message(message,tag)
  
  @verify_socket.write(packet)
  @verify_socket.read(2).to_i
end