Class: Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1

Inherits:
Object
  • Object
show all
Includes:
Loggable, Constants
Defined in:
lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb

Overview

A key-exchange service implementing the “diffie-hellman-group1-sha1” key-exchange algorithm.

Direct Known Subclasses

DiffieHellmanGroupExchangeSHA1

Constant Summary collapse

P_s =

The value of ‘P’, as a string, in hexadecimal

"FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" +
"C4C6628B" "80DC1CD1" "29024E08" "8A67CC74" +
"020BBEA6" "3B139B22" "514A0879" "8E3404DD" +
"EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" +
"4FE1356D" "6D51C245" "E485B576" "625E7EC6" +
"F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED" +
"EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" +
"49286651" "ECE65381" "FFFFFFFF" "FFFFFFFF"
P_r =

The radix in which P_s represents the value of P

16
G =

The group constant

2

Constants included from Constants

Constants::DEBUG, Constants::DISCONNECT, Constants::IGNORE, Constants::KEXDH_INIT, Constants::KEXDH_REPLY, Constants::KEXINIT, Constants::NEWKEYS, Constants::SERVICE_ACCEPT, Constants::SERVICE_REQUEST, Constants::UNIMPLEMENTED

Instance Attribute Summary collapse

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

#initialize(algorithms, connection, data) ⇒ DiffieHellmanGroup1SHA1

Create a new instance of the DiffieHellmanGroup1SHA1 algorithm. The data is a Hash of symbols representing information required by this algorithm, which was acquired during earlier processing.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 42

def initialize(algorithms, connection, data)
  @p = OpenSSL::BN.new(P_s, P_r)
  @g = G

  @digester = OpenSSL::Digest::SHA1
  @algorithms = algorithms
  @connection = connection

  @data = data.dup
  @dh = generate_key
  @logger = @data.delete(:logger)
end

Instance Attribute Details

#algorithmsObject (readonly)

Returns the value of attribute algorithms.



33
34
35
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 33

def algorithms
  @algorithms
end

#connectionObject (readonly)

Returns the value of attribute connection.



34
35
36
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 34

def connection
  @connection
end

#dataObject (readonly)

Returns the value of attribute data.



35
36
37
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 35

def data
  @data
end

#dhObject (readonly)

Returns the value of attribute dh.



36
37
38
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 36

def dh
  @dh
end

#digesterObject (readonly)

Returns the value of attribute digester.



32
33
34
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 32

def digester
  @digester
end

#gObject (readonly)

Returns the value of attribute g.



31
32
33
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 31

def g
  @g
end

#pObject (readonly)

Returns the value of attribute p.



30
31
32
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 30

def p
  @p
end

Instance Method Details

#exchange_keysObject

Perform the key-exchange for the given session, with the given data. This method will return a hash consisting of the following keys:

  • :session_id

  • :server_key

  • :shared_secret

  • :hashing_algorithm

The caller is expected to be able to understand how to use these deliverables.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb', line 66

def exchange_keys
  result = send_kexinit
  verify_server_key(result[:server_key])
  session_id = verify_signature(result)
  confirm_newkeys

  return { :session_id        => session_id, 
           :server_key        => result[:server_key],
           :shared_secret     => result[:shared_secret],
           :hashing_algorithm => digester }
end