Module: CryptoToolchain::SRP::Framework

Included in:
Client, Server, SimpleClient, SimpleServer
Defined in:
lib/crypto_toolchain/srp/framework.rb

Constant Summary collapse

EVENT_WHITELIST =
%w( hello verify shutdown error authentication_success ).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def email
  @email
end

#gObject (readonly)

Returns the value of attribute g.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def g
  @g
end

#kObject (readonly)

Returns the value of attribute k.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def k
  @k
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def key
  @key
end

#nObject (readonly)

Returns the value of attribute n.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def n
  @n
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def password
  @password
end

#privkeyObject (readonly)

Returns the value of attribute privkey.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def privkey
  @privkey
end

#pubkeyObject (readonly)

Returns the value of attribute pubkey.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def pubkey
  @pubkey
end

#saltObject (readonly)

Returns the value of attribute salt.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def salt
  @salt
end

#socketObject (readonly)

Returns the value of attribute socket.



5
6
7
# File 'lib/crypto_toolchain/srp/framework.rb', line 5

def socket
  @socket
end

Instance Method Details

#error_received(*args) ⇒ Object

Raises:

  • (StandardError)


49
50
51
# File 'lib/crypto_toolchain/srp/framework.rb', line 49

def error_received(*args)
  raise StandardError.new(args.join(" "))
end

#event_loopObject



31
32
33
34
35
36
37
38
39
# File 'lib/crypto_toolchain/srp/framework.rb', line 31

def event_loop
  begin
    loop do
      yield socket.readline.strip
    end
  rescue ShutdownSignal
    # Nothing
  end
end

#go!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/crypto_toolchain/srp/framework.rb', line 20

def go!
  event_loop do |event_string|
    event_type, *data = event_string.split(DELIMITER)
    puts "Received #{event_type} #{data}" if DEBUG
    if !EVENT_WHITELIST.include?(event_type)
      socket.puts("error|event #{event_type} unknown") and next
    end
    send("#{event_type}_received", *data)
  end
end

#initialize(n: CryptoToolchain::NIST_P, g: CryptoToolchain::NIST_G, k: 3, email: "[email protected]", password: "i<3porkchops", socket:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/crypto_toolchain/srp/framework.rb', line 7

def initialize(n: CryptoToolchain::NIST_P, g: CryptoToolchain::NIST_G,
              k: 3, email: "[email protected]", password: "i<3porkchops",
              socket: )
  @n        = n
  @g        = g
  @k        = k
  @email    = email
  @password = password
  @socket   = socket
  @privkey  = rand(1..0xffffffff) % n
end

#shutdown_received(*args) ⇒ Object

Raises:



41
42
43
# File 'lib/crypto_toolchain/srp/framework.rb', line 41

def shutdown_received(*args)
  raise ShutdownSignal
end

#write_message(*args) ⇒ Object



45
46
47
# File 'lib/crypto_toolchain/srp/framework.rb', line 45

def write_message(*args)
  socket.puts args.join(DELIMITER)
end