class Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
key-exchange algorithm.
A key-exchange service implementing the “diffie-hellman-group1-sha1”
def build_signature_buffer(result)
Build the signature buffer to use when verifying a signature from
def build_signature_buffer(result) response = Net::SSH::Buffer.new response.write_string data[:client_version_string], data[:server_version_string], data[:client_algorithm_packet], data[:server_algorithm_packet], result[:key_blob] response.write_bignum dh.pub_key, result[:server_dh_pubkey], result[:shared_secret] response end
def digester
def digester OpenSSL::Digest::SHA1 end
def generate_key # :nodoc:
number of bytes.
Generate a DH key with a private key consisting of the given
def generate_key # :nodoc: p, g = get_parameters asn1 = OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::Integer(p), OpenSSL::ASN1::Integer(g) ] ) dh_params = OpenSSL::PKey::DH.new(asn1.to_der) # XXX No private key size check! In theory the latter call should work but fails on OpenSSL 3.0 as # dh_paramgen_subprime_len is now reserved for DHX algorithm # key = OpenSSL::PKey.generate_key(dh_params, "dh_paramgen_subprime_len" => data[:need_bytes]/8) if OpenSSL::PKey.respond_to?(:generate_key) OpenSSL::PKey.generate_key(dh_params) else dh_params.generate_key! dh_params end end
def get_message_types
def get_message_types [KEXDH_INIT, KEXDH_REPLY] end
def get_parameters
def get_parameters [ OpenSSL::BN.new(self.class::P_s, self.class::P_r), self.class::G ] end
def send_kexinit # :nodoc:
the extracted values.
Parse the buffer from a KEXDH_REPLY message, returning a hash of
resulting buffer.
Send the KEXDH_INIT message, and expect the KEXDH_REPLY. Return the
def send_kexinit # :nodoc: init, reply = get_message_types # send the KEXDH_INIT message buffer = Net::SSH::Buffer.from(:byte, init, :bignum, dh.pub_key) connection.send_message(buffer) # expect the KEXDH_REPLY message buffer = connection.next_message raise Net::SSH::Exception, "expected REPLY" unless buffer.type == reply result = Hash.new result[:key_blob] = buffer.read_string result[:server_key] = Net::SSH::Buffer.new(result[:key_blob]).read_key result[:server_dh_pubkey] = buffer.read_bignum result[:shared_secret] = OpenSSL::BN.new(dh.compute_key(result[:server_dh_pubkey]), 2) sig_buffer = Net::SSH::Buffer.new(buffer.read_string) sig_type = sig_buffer.read_string if sig_type != algorithms.host_key_format raise Net::SSH::Exception, "host key algorithm mismatch for signature " + "'#{sig_type}' != '#{algorithms.host_key_format}'" end result[:server_sig] = sig_buffer.read_string return result end