diff options
author | Florian Wininger <fw.centrale@gmail.com> | 2021-10-25 15:25:57 +0200 |
---|---|---|
committer | Florian Wininger <fw.centrale@gmail.com> | 2021-10-25 15:55:44 +0200 |
commit | f79ed49dc068317fb280bd2fb554ecb0ce13a7e1 (patch) | |
tree | 32fbf2392f8225905d6cf77412f0f01dbbf82097 /lib | |
parent | cf1b4da0d56e6b0598f9d5fbc3c335011f42bc26 (diff) | |
download | net-ssh-f79ed49dc068317fb280bd2fb554ecb0ce13a7e1.tar.gz |
Fix rubocop coding style.
Lot of spacing issues :)
Diffstat (limited to 'lib')
53 files changed, 211 insertions, 211 deletions
diff --git a/lib/net/ssh.rb b/lib/net/ssh.rb index bbae909..b72ab7f 100644 --- a/lib/net/ssh.rb +++ b/lib/net/ssh.rb @@ -214,7 +214,7 @@ module Net # * :fingerprint_hash => 'MD5' or 'SHA256', defaults to 'SHA256' # If +user+ parameter is nil it defaults to USER from ssh_config, or # local username - def self.start(host, user=nil, options={}, &block) + def self.start(host, user = nil, options = {}, &block) invalid_options = options.keys - VALID_OPTIONS if invalid_options.any? raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}" @@ -301,9 +301,9 @@ module Net end def self._sanitize_options(options) - invalid_option_values = [nil,[nil]] + invalid_option_values = [nil, [nil]] unless (options.values & invalid_option_values).empty? - nil_options = options.select { |_k,v| invalid_option_values.include?(v) }.map(&:first) + nil_options = options.select { |_k, v| invalid_option_values.include?(v) }.map(&:first) Kernel.warn "#{caller_locations(2, 1)[0]}: Passing nil, or [nil] to Net::SSH.start is deprecated for keys: #{nil_options.join(', ')}" end end diff --git a/lib/net/ssh/authentication/agent.rb b/lib/net/ssh/authentication/agent.rb index f521e55..ab6dce9 100644 --- a/lib/net/ssh/authentication/agent.rb +++ b/lib/net/ssh/authentication/agent.rb @@ -65,7 +65,7 @@ module Net # Instantiates a new agent object, connects to a running SSH agent, # negotiates the agent protocol version, and returns the agent object. - def self.connect(logger=nil, agent_socket_factory = nil, identity_agent = nil) + def self.connect(logger = nil, agent_socket_factory = nil, identity_agent = nil) agent = new(logger) agent.connect!(agent_socket_factory, identity_agent) agent.negotiate! @@ -74,7 +74,7 @@ module Net # Creates a new Agent object, using the optional logger instance to # report status. - def initialize(logger=nil) + def initialize(logger = nil) self.logger = logger end @@ -177,7 +177,7 @@ module Net req_type = constraints.empty? ? SSH2_AGENT_ADD_IDENTITY : SSH2_AGENT_ADD_ID_CONSTRAINED type, = send_and_wait(req_type, :string, priv_key.ssh_type, :raw, blob_for_add(priv_key), - :string, comment, :raw, constraints) + :string, comment, :raw, constraints) raise AgentError, "could not add identity to agent" if type != SSH_AGENT_SUCCESS end @@ -251,31 +251,31 @@ module Net case priv_key.ssh_type when /^ssh-dss$/ Net::SSH::Buffer.from(:bignum, priv_key.p, :bignum, priv_key.q, :bignum, priv_key.g, - :bignum, priv_key.pub_key, :bignum, priv_key.priv_key).to_s + :bignum, priv_key.pub_key, :bignum, priv_key.priv_key).to_s when /^ssh-dss-cert-v01@openssh\.com$/ Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.priv_key).to_s when /^ecdsa\-sha2\-(\w*)$/ curve_name = OpenSSL::PKey::EC::CurveNameAliasInv[priv_key.group.curve_name] Net::SSH::Buffer.from(:string, curve_name, :mstring, priv_key.public_key.to_bn.to_s(2), - :bignum, priv_key.private_key).to_s + :bignum, priv_key.private_key).to_s when /^ecdsa\-sha2\-(\w*)-cert-v01@openssh\.com$/ Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.private_key).to_s when /^ssh-ed25519$/ Net::SSH::Buffer.from(:string, priv_key.public_key.verify_key.to_bytes, - :string, priv_key.sign_key.keypair).to_s + :string, priv_key.sign_key.keypair).to_s when /^ssh-ed25519-cert-v01@openssh\.com$/ # Unlike the other certificate types, the public key is included after the certifiate. Net::SSH::Buffer.from(:string, priv_key.to_blob, - :string, priv_key.key.public_key.verify_key.to_bytes, - :string, priv_key.key.sign_key.keypair).to_s + :string, priv_key.key.public_key.verify_key.to_bytes, + :string, priv_key.key.sign_key.keypair).to_s when /^ssh-rsa$/ # `n` and `e` are reversed compared to the ordering in `OpenSSL::PKey::RSA#to_blob`. Net::SSH::Buffer.from(:bignum, priv_key.n, :bignum, priv_key.e, :bignum, priv_key.d, - :bignum, priv_key.iqmp, :bignum, priv_key.p, :bignum, priv_key.q).to_s + :bignum, priv_key.iqmp, :bignum, priv_key.p, :bignum, priv_key.q).to_s when /^ssh-rsa-cert-v01@openssh\.com$/ Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.d, - :bignum, priv_key.key.iqmp, :bignum, priv_key.key.p, - :bignum, priv_key.key.q).to_s + :bignum, priv_key.key.iqmp, :bignum, priv_key.key.p, + :bignum, priv_key.key.q).to_s end end end diff --git a/lib/net/ssh/authentication/certificate.rb b/lib/net/ssh/authentication/certificate.rb index deeb71d..c9619fa 100644 --- a/lib/net/ssh/authentication/certificate.rb +++ b/lib/net/ssh/authentication/certificate.rb @@ -83,7 +83,7 @@ module Net end # Signs the certificate with key. - def sign!(key, sign_nonce=nil) + def sign!(key, sign_nonce = nil) # ssh-keygen uses 32 bytes of nonce. self.nonce = sign_nonce || SecureRandom.random_bytes(32) self.signature_key = key @@ -94,7 +94,7 @@ module Net self end - def sign(key, sign_nonce=nil) + def sign(key, sign_nonce = nil) cert = clone cert.sign!(key, sign_nonce) end diff --git a/lib/net/ssh/authentication/ed25519.rb b/lib/net/ssh/authentication/ed25519.rb index 0c5bdf2..c2a117a 100644 --- a/lib/net/ssh/authentication/ed25519.rb +++ b/lib/net/ssh/authentication/ed25519.rb @@ -14,7 +14,7 @@ module Net module Authentication module ED25519 class SigningKeyFromFile < SimpleDelegator - def initialize(pk,sk) + def initialize(pk, sk) key = ::Ed25519::SigningKey.from_keypair(sk) raise ArgumentError, "pk does not match sk" unless pk == key.verify_key.to_bytes @@ -116,7 +116,7 @@ module Net end def to_blob - Net::SSH::Buffer.from(:mstring,"ssh-ed25519".dup,:string,@verify_key.to_bytes).to_s + Net::SSH::Buffer.from(:mstring, "ssh-ed25519".dup, :string, @verify_key.to_bytes).to_s end def ssh_type @@ -128,7 +128,7 @@ module Net end def ssh_do_verify(sig, data, options = {}) - @verify_key.verify(sig,data) + @verify_key.verify(sig, data) end def to_pem @@ -152,7 +152,7 @@ module Net _comment = buffer.read_string @pk = pk - @sign_key = SigningKeyFromFile.new(pk,sk) + @sign_key = SigningKeyFromFile.new(pk, sk) end def to_blob diff --git a/lib/net/ssh/authentication/key_manager.rb b/lib/net/ssh/authentication/key_manager.rb index d41eed8..ac86cc8 100644 --- a/lib/net/ssh/authentication/key_manager.rb +++ b/lib/net/ssh/authentication/key_manager.rb @@ -41,7 +41,7 @@ module Net # Create a new KeyManager. By default, the manager will # use the ssh-agent if it is running and the `:use_agent` option # is not false. - def initialize(logger, options={}) + def initialize(logger, options = {}) self.logger = logger @key_files = [] @key_data = [] @@ -171,7 +171,7 @@ module Net if info[:key] return Net::SSH::Buffer.from(:string, identity.ssh_signature_type, - :mstring, info[:key].ssh_do_sign(data.to_s)).to_s + :mstring, info[:key].ssh_do_sign(data.to_s)).to_s end if info[:from] == :agent diff --git a/lib/net/ssh/authentication/methods/abstract.rb b/lib/net/ssh/authentication/methods/abstract.rb index ec35043..07aa5f3 100644 --- a/lib/net/ssh/authentication/methods/abstract.rb +++ b/lib/net/ssh/authentication/methods/abstract.rb @@ -21,7 +21,7 @@ module Net attr_reader :key_manager # Instantiates a new authentication method. - def initialize(session, options={}) + def initialize(session, options = {}) @session = session @key_manager = options[:key_manager] @options = options @@ -46,7 +46,7 @@ module Net # of the packet. The new packet is returned, ready for sending. def userauth_request(username, next_service, auth_method, *others) buffer = Net::SSH::Buffer.from(:byte, USERAUTH_REQUEST, - :string, username, :string, next_service, :string, auth_method) + :string, username, :string, next_service, :string, auth_method) others.each do |value| case value diff --git a/lib/net/ssh/authentication/methods/hostbased.rb b/lib/net/ssh/authentication/methods/hostbased.rb index c4cd4cb..6c92ef4 100644 --- a/lib/net/ssh/authentication/methods/hostbased.rb +++ b/lib/net/ssh/authentication/methods/hostbased.rb @@ -10,12 +10,12 @@ module Net # Attempts to perform host-based authorization of the user by trying # all known keys. - def authenticate(next_service, username, password=nil) + def authenticate(next_service, username, password = nil) return false unless key_manager key_manager.each_identity do |identity| return true if authenticate_with(identity, next_service, - username, key_manager) + username, key_manager) end return false @@ -63,7 +63,7 @@ module Net # Build the "core" hostbased request string. def build_request(identity, next_service, username, hostname, client_username) userauth_request(username, next_service, "hostbased", identity.ssh_type, - Buffer.from(:key, identity).to_s, hostname, client_username).to_s + Buffer.from(:key, identity).to_s, hostname, client_username).to_s end end end diff --git a/lib/net/ssh/authentication/methods/keyboard_interactive.rb b/lib/net/ssh/authentication/methods/keyboard_interactive.rb index c241eda..db195d9 100644 --- a/lib/net/ssh/authentication/methods/keyboard_interactive.rb +++ b/lib/net/ssh/authentication/methods/keyboard_interactive.rb @@ -11,7 +11,7 @@ module Net USERAUTH_INFO_RESPONSE = 61 # Attempt to authenticate the given user for the given service. - def authenticate(next_service, username, password=nil) + def authenticate(next_service, username, password = nil) debug { "trying keyboard-interactive" } send_message(userauth_request(username, next_service, "keyboard-interactive", "", "")) diff --git a/lib/net/ssh/authentication/methods/none.rb b/lib/net/ssh/authentication/methods/none.rb index 09fdac8..d38e877 100644 --- a/lib/net/ssh/authentication/methods/none.rb +++ b/lib/net/ssh/authentication/methods/none.rb @@ -8,7 +8,7 @@ module Net # Implements the "none" SSH authentication method. class None < Abstract # Attempt to authenticate as "none" - def authenticate(next_service, user="", password="") + def authenticate(next_service, user = "", password = "") send_message(userauth_request(user, next_service, "none")) message = session.next_message diff --git a/lib/net/ssh/authentication/methods/password.rb b/lib/net/ssh/authentication/methods/password.rb index 9cb1828..ffb881c 100644 --- a/lib/net/ssh/authentication/methods/password.rb +++ b/lib/net/ssh/authentication/methods/password.rb @@ -10,7 +10,7 @@ module Net class Password < Abstract # Attempt to authenticate the given user for the given service. If # the password parameter is nil, this will ask for password - def authenticate(next_service, username, password=nil) + def authenticate(next_service, username, password = nil) clear_prompter! retries = 0 max_retries = get_max_retries diff --git a/lib/net/ssh/authentication/methods/publickey.rb b/lib/net/ssh/authentication/methods/publickey.rb index 65e5dca..eb4d740 100644 --- a/lib/net/ssh/authentication/methods/publickey.rb +++ b/lib/net/ssh/authentication/methods/publickey.rb @@ -12,7 +12,7 @@ module Net # username, trying each identity known to the key manager. If any of # them succeed, returns +true+, otherwise returns +false+. This # requires the presence of a key manager. - def authenticate(next_service, username, password=nil) + def authenticate(next_service, username, password = nil) return false unless key_manager key_manager.each_identity do |identity| @@ -31,12 +31,12 @@ module Net blob.write_key pub_key userauth_request(username, next_service, "publickey", has_sig, - pub_key.ssh_type, blob.to_s) + pub_key.ssh_type, blob.to_s) end # Builds and sends a request formatted for a public-key # authentication request. - def send_request(pub_key, username, next_service, signature=nil) + def send_request(pub_key, username, next_service, signature = nil) msg = build_request(pub_key, username, next_service, !signature.nil?) msg.write_string(signature) if signature send_message(msg) @@ -76,7 +76,7 @@ module Net return false else raise Net::SSH::Exception, - "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})" + "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})" end when USERAUTH_FAILURE diff --git a/lib/net/ssh/authentication/pageant.rb b/lib/net/ssh/authentication/pageant.rb index 9c44c19..a186c17 100644 --- a/lib/net/ssh/authentication/pageant.rb +++ b/lib/net/ssh/authentication/pageant.rb @@ -50,13 +50,13 @@ module Net SIZEOF_DWORD = DL.sizeof('L') elsif RUBY_VERSION < "2.1" extend DL::Importer - dlload 'user32.dll','kernel32.dll', 'advapi32.dll' + dlload 'user32.dll', 'kernel32.dll', 'advapi32.dll' include DL::Win32Types SIZEOF_DWORD = DL::SIZEOF_LONG else extend Fiddle::Importer - dlload 'user32.dll','kernel32.dll', 'advapi32.dll' + dlload 'user32.dll', 'kernel32.dll', 'advapi32.dll' include Fiddle::Win32Types SIZEOF_DWORD = Fiddle::SIZEOF_LONG end @@ -240,7 +240,7 @@ module Net end def self.set_ptr_data(ptr, data) - DL::CPtr.new(ptr)[0,data.size] = data + DL::CPtr.new(ptr)[0, data.size] = data end end @@ -281,7 +281,7 @@ module Net def self.ptr_to_dword(ptr) first = ptr.ptr.to_i - second = ptr_to_s(ptr,Win::SIZEOF_DWORD).unpack('L')[0] + second = ptr_to_s(ptr, Win::SIZEOF_DWORD).unpack('L')[0] raise "Error" unless first == second first @@ -296,7 +296,7 @@ module Net end def self.get_sid(user) - ptr_to_s(user.to_ptr.ptr,Win::SIZEOF_DWORD).unpack('L')[0] + ptr_to_s(user.to_ptr.ptr, Win::SIZEOF_DWORD).unpack('L')[0] end def self.get_sid_ptr(user) @@ -332,7 +332,7 @@ module Net token_handle = open_process_token(Win.GetCurrentProcess, Win::TOKEN_QUERY) token_user = get_token_information(token_handle, - Win::TOKEN_USER_INFORMATION_CLASS) + Win::TOKEN_USER_INFORMATION_CLASS) return token_user end @@ -404,7 +404,7 @@ module Net if @win.to_i == 0 raise Net::SSH::Exception, - "pageant process not running" + "pageant process not running" end @input_buffer = Net::SSH::Buffer.new @@ -458,7 +458,7 @@ module Net if filemap == 0 || filemap == Win::INVALID_HANDLE_VALUE raise Net::SSH::Exception, - "Creation of file mapping failed with error: #{Win.GetLastError}" + "Creation of file mapping failed with error: #{Win.GetLastError}" end ptr = Win.MapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0, diff --git a/lib/net/ssh/authentication/pub_key_fingerprint.rb b/lib/net/ssh/authentication/pub_key_fingerprint.rb index a776006..42f2f16 100644 --- a/lib/net/ssh/authentication/pub_key_fingerprint.rb +++ b/lib/net/ssh/authentication/pub_key_fingerprint.rb @@ -22,12 +22,12 @@ module Net # returned by OpenSSH's <tt>`ssh-add -l -E SHA256`</tt>, i.e., # trailing base64 padding '=' characters are stripped and the # literal string +SHA256:+ is prepended. - def fingerprint(algorithm='MD5') + def fingerprint(algorithm = 'MD5') @fingerprint ||= {} @fingerprint[algorithm] ||= PubKeyFingerprint.fingerprint(to_blob, algorithm) end - def self.fingerprint(blob, algorithm='MD5') + def self.fingerprint(blob, algorithm = 'MD5') case algorithm.to_s.upcase when 'MD5' OpenSSL::Digest.hexdigest(algorithm, blob).scan(/../).join(":") diff --git a/lib/net/ssh/authentication/session.rb b/lib/net/ssh/authentication/session.rb index 4451cde..e4fc648 100644 --- a/lib/net/ssh/authentication/session.rb +++ b/lib/net/ssh/authentication/session.rb @@ -41,7 +41,7 @@ module Net # Instantiates a new Authentication::Session object over the given # transport layer abstraction. - def initialize(transport, options={}) + def initialize(transport, options = {}) self.logger = transport.logger @transport = transport @@ -54,7 +54,7 @@ module Net # Attempts to authenticate the given user, in preparation for the next # service request. Returns true if an authentication method succeeds in # authenticating the user, and false otherwise. - def authenticate(next_service, username, password=nil) + def authenticate(next_service, username, password = nil) debug { "beginning authentication of `#{username}'" } transport.send_message(transport.service_request("ssh-userauth")) diff --git a/lib/net/ssh/buffer.rb b/lib/net/ssh/buffer.rb index 3934ae7..b68d656 100644 --- a/lib/net/ssh/buffer.rb +++ b/lib/net/ssh/buffer.rb @@ -70,7 +70,7 @@ module Net # Creates a new buffer, initialized to the given content. The position # is initialized to the beginning of the buffer. - def initialize(content=String.new) + def initialize(content = String.new) @content = content.to_s @position = 0 end @@ -128,7 +128,7 @@ module Net # would otherwise tend to grow without bound. # # Returns the buffer object itself. - def consume!(n=position) + def consume!(n = position) if n >= length # optimize for a fairly common case clear! @@ -171,7 +171,7 @@ module Net # Reads and returns the next +count+ bytes from the buffer, starting from # the read position. If +count+ is +nil+, this will return all remaining # text in the buffer. This method will increment the pointer. - def read(count=nil) + def read(count = nil) count ||= length count = length - @position if @position + count > length @position += count @@ -180,7 +180,7 @@ module Net # Reads (as #read) and returns the given number of bytes from the buffer, # and then consumes (as #consume!) all data up to the new read position. - def read!(count=nil) + def read!(count = nil) data = read(count) consume! data diff --git a/lib/net/ssh/buffered_io.rb b/lib/net/ssh/buffered_io.rb index 464ba4c..c2d34e2 100644 --- a/lib/net/ssh/buffered_io.rb +++ b/lib/net/ssh/buffered_io.rb @@ -51,7 +51,7 @@ module Net # Called when the #extend is called on an object, with this module as the # argument. It ensures that the modules instance variables are all properly # initialized. - def self.extended(object) #:nodoc: + def self.extended(object) # :nodoc: # need to use __send__ because #send is overridden in Socket object.__send__(:initialize_buffered_io) end @@ -59,7 +59,7 @@ module Net # Tries to read up to +n+ bytes of data from the remote end, and appends # the data to the input buffer. It returns the number of bytes read, or 0 # if no data was available to be read. - def fill(n=8192) + def fill(n = 8192) input.consume! data = recv(n) debug { "read #{data.length} bytes" } @@ -72,7 +72,7 @@ module Net # Read up to +length+ bytes from the input buffer. If +length+ is nil, # all available data is read from the buffer. (See #available.) - def read_available(length=nil) + def read_available(length = nil) input.read(length || available) end @@ -121,11 +121,11 @@ module Net public # these methods are primarily for use in tests - def write_buffer #:nodoc: + def write_buffer # :nodoc: output.to_s end - def read_buffer #:nodoc: + def read_buffer # :nodoc: input.to_s end @@ -166,7 +166,7 @@ module Net # http://github.com/net-ssh/net-ssh/tree/portfwfix # module ForwardedBufferedIo - def fill(n=8192) + def fill(n = 8192) begin super(n) rescue Errno::ECONNRESET => e diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index 6f0f4da..86c75f5 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -65,7 +65,7 @@ module Net # given +files+ (defaulting to the list of files returned by # #default_files), translates the resulting hash into the options # recognized by Net::SSH, and returns them. - def for(host, files=expandable_default_files) + def for(host, files = expandable_default_files) translate(files.inject({}) { |settings, file| load(file, host, settings) }) @@ -77,7 +77,7 @@ module Net # ones. Returns a hash containing the OpenSSH options. (See # #translate for how to convert the OpenSSH options into Net::SSH # options.) - def load(path, host, settings={}, base_dir = nil) + def load(path, host, settings = {}, base_dir = nil) file = File.expand_path(path) base_dir ||= File.dirname(file) return settings unless File.readable?(file) @@ -317,7 +317,7 @@ module Net tail = pattern prefix = String.new while !tail.empty? do - head,sep,tail = tail.partition(/[\*\?]/) + head, sep, tail = tail.partition(/[\*\?]/) prefix = prefix + Regexp.quote(head) case sep when '*' @@ -371,7 +371,7 @@ module Net conditions = conditions.each_slice(2) condition_matches = [] - conditions.each do |(kind,exprs)| + conditions.each do |(kind, exprs)| exprs = unquote(exprs) case kind.downcase diff --git a/lib/net/ssh/connection/channel.rb b/lib/net/ssh/connection/channel.rb index b169679..6fcf790 100644 --- a/lib/net/ssh/connection/channel.rb +++ b/lib/net/ssh/connection/channel.rb @@ -96,12 +96,12 @@ module Net # The output buffer for this channel. Data written to the channel is # enqueued here, to be written as CHANNEL_DATA packets during each pass of # the event loop. See Connection::Session#process and #enqueue_pending_output. - attr_reader :output #:nodoc: + attr_reader :output # :nodoc: # The list of pending requests. Each time a request is sent which requires # a reply, the corresponding callback is pushed onto this queue. As responses # arrive, they are shifted off the front and handled. - attr_reader :pending_requests #:nodoc: + attr_reader :pending_requests # :nodoc: # Instantiates a new channel on the given connection, of the given type, # and with the given id. If a block is given, it will be remembered until @@ -217,7 +217,7 @@ module Net # puts "could not obtain pty" # end # end - def request_pty(opts={}, &block) + def request_pty(opts = {}, &block) extra = opts.keys - VALID_PTY_OPTIONS.keys raise ArgumentError, "invalid option(s) to request_pty: #{extra.inspect}" if extra.any? @@ -230,9 +230,9 @@ module Net modes.write_byte(0) send_channel_request("pty-req", :string, opts[:term], - :long, opts[:chars_wide], :long, opts[:chars_high], - :long, opts[:pixels_wide], :long, opts[:pixels_high], - :string, modes.to_s, &block) + :long, opts[:chars_wide], :long, opts[:chars_high], + :long, opts[:pixels_wide], :long, opts[:pixels_high], + :string, modes.to_s, &block) end # Sends data to the channel's remote endpoint. This usually has the @@ -490,8 +490,8 @@ module Net fail "Channel open not yet confirmed, please call send_channel_request(or exec) from block of open_channel" unless remote_id msg = Buffer.from(:byte, CHANNEL_REQUEST, - :long, remote_id, :string, request_name, - :bool, !callback.nil?, *data) + :long, remote_id, :string, request_name, + :bool, !callback.nil?, *data) connection.send_message(msg) pending_requests << callback if callback end @@ -503,7 +503,7 @@ module Net # #do_open_confirmation). This is called automatically by #process, which # is called from the event loop (Connection::Session#process). You will # generally not need to invoke it directly. - def enqueue_pending_output #:nodoc: + def enqueue_pending_output # :nodoc: return unless remote_id while output.length > 0 @@ -527,7 +527,7 @@ module Net # packet sizes, respectively. If an open-confirmation callback was # given when the channel was created, it is invoked at this time with # the channel itself as the sole argument. - def do_open_confirmation(remote_id, max_window, max_packet) #:nodoc: + def do_open_confirmation(remote_id, max_window, max_packet) # :nodoc: @remote_id = remote_id @remote_window_size = @remote_maximum_window_size = max_window @remote_maximum_packet_size = max_packet @@ -553,7 +553,7 @@ module Net # causes the remote window size to be adjusted upwards by the given # number of bytes. This has the effect of allowing more data to be sent # from the local end to the remote end of the channel. - def do_window_adjust(bytes) #:nodoc: + def do_window_adjust(bytes) # :nodoc: @remote_maximum_window_size += bytes @remote_window_size += bytes end @@ -566,7 +566,7 @@ module Net # CHANNEL_SUCCESS, unless the callback raised ChannelRequestFailed. The # callback should accept the channel as the first argument, and the # request-specific data as the second. - def do_request(request, want_reply, data) #:nodoc: + def do_request(request, want_reply, data) # :nodoc: result = true begin @@ -587,7 +587,7 @@ module Net # but does not actually throttle requests that come in illegally when # the window size is too small. The callback is invoked with the channel # as the first argument, and the data as the second. - def do_data(data) #:nodoc: + def do_data(data) # :nodoc: update_local_window_size(data.length) @on_data.call(self, data) if @on_data end diff --git a/lib/net/ssh/connection/event_loop.rb b/lib/net/ssh/connection/event_loop.rb index 869e38f..5aac78c 100644 --- a/lib/net/ssh/connection/event_loop.rb +++ b/lib/net/ssh/connection/event_loop.rb @@ -12,7 +12,7 @@ module Net class EventLoop include Loggable - def initialize(logger=nil) + def initialize(logger = nil) self.logger = logger @sessions = [] end @@ -60,7 +60,7 @@ module Net w = [] minwait = nil @sessions.each do |session| - sr,sw,actwait = session.ev_do_calculate_rw_wait(wait) + sr, sw, actwait = session.ev_do_calculate_rw_wait(wait) minwait = actwait if actwait && (minwait.nil? || actwait < minwait) r.push(*sr) w.push(*sw) @@ -75,18 +75,18 @@ module Net if readers readers.each do |reader| session = owners[reader] - (fired_sessions[session] ||= { r: [],w: [] })[:r] << reader + (fired_sessions[session] ||= { r: [], w: [] })[:r] << reader end end if writers writers.each do |writer| session = owners[writer] - (fired_sessions[session] ||= { r: [],w: [] })[:w] << writer + (fired_sessions[session] ||= { r: [], w: [] })[:w] << writer end end - fired_sessions.each do |s,rw| - s.ev_do_handle_events(rw[:r],rw[:w]) + fired_sessions.each do |s, rw| + s.ev_do_handle_events(rw[:r], rw[:w]) end @sessions.each { |s| s.ev_do_postprocess(fired_sessions.key?(s)) } @@ -111,10 +111,10 @@ module Net raise "Only one session expected" unless @sessions.count == 1 session = @sessions.first - sr,sw,actwait = session.ev_do_calculate_rw_wait(wait) + sr, sw, actwait = session.ev_do_calculate_rw_wait(wait) readers, writers, = IO.select(sr, sw, nil, actwait) - session.ev_do_handle_events(readers,writers) + session.ev_do_handle_events(readers, writers) session.ev_do_postprocess(!((readers.nil? || readers.empty?) && (writers.nil? || writers.empty?))) end end diff --git a/lib/net/ssh/connection/session.rb b/lib/net/ssh/connection/session.rb index 4f09fc8..fbfc017 100644 --- a/lib/net/ssh/connection/session.rb +++ b/lib/net/ssh/connection/session.rb @@ -41,17 +41,17 @@ module Net attr_reader :properties # The map of channels, each key being the local-id for the channel. - attr_reader :channels #:nodoc: + attr_reader :channels # :nodoc: # The map of listeners that the event loop knows about. See #listen_to. - attr_reader :listeners #:nodoc: + attr_reader :listeners # :nodoc: # The map of specialized handlers for opening specific channel types. See # #on_open_channel. - attr_reader :channel_open_handlers #:nodoc: + attr_reader :channel_open_handlers # :nodoc: # The list of callbacks for pending requests. See #send_global_request. - attr_reader :pending_requests #:nodoc: + attr_reader :pending_requests # :nodoc: class NilChannel def initialize(session) @@ -65,7 +65,7 @@ module Net # Create a new connection service instance atop the given transport # layer. Initializes the listeners to be only the underlying socket object. - def initialize(transport, options={}) + def initialize(transport, options = {}) self.logger = transport.logger @transport = transport @@ -149,7 +149,7 @@ module Net # to be run. # # ssh.loop { ssh.busy? } - def busy?(include_invisible=false) + def busy?(include_invisible = false) if include_invisible channels.any? else @@ -174,7 +174,7 @@ module Net # int_pressed = false # trap("INT") { int_pressed = true } # ssh.loop(0.1) { not int_pressed } - def loop(wait=nil, &block) + def loop(wait = nil, &block) running = block || Proc.new { busy? } loop_forever { break unless process(wait, &running) } begin @@ -222,7 +222,7 @@ module Net # connections.delete_if { |ssh| !ssh.process(0.1, &condition) } # break if connections.empty? # end - def process(wait=nil, &block) + def process(wait = nil, &block) @event_loop.process(wait, &block) rescue StandardError force_channel_cleanup_on_close if closed? @@ -255,7 +255,7 @@ module Net def ev_do_calculate_rw_wait(wait) r = listeners.keys w = r.select { |w2| w2.respond_to?(:pending_write?) && w2.pending_write? } - [r,w,io_select_wait(wait)] + [r, w, io_select_wait(wait)] end # This is called internally as part of #process. @@ -335,13 +335,13 @@ module Net # end # # channel.wait - def open_channel(type="session", *extra, &on_confirm) + def open_channel(type = "session", *extra, &on_confirm) local_id = get_next_channel_id channel = Channel.new(self, type, local_id, @max_pkt_size, @max_win_size, &on_confirm) msg = Buffer.from(:byte, CHANNEL_OPEN, :string, type, :long, local_id, - :long, channel.local_maximum_window_size, - :long, channel.local_maximum_packet_size, *extra) + :long, channel.local_maximum_window_size, + :long, channel.local_maximum_packet_size, *extra) send_message(msg) channels[local_id] = channel @@ -382,7 +382,7 @@ module Net raise "could not execute command: #{command.inspect}" unless success if status - channel.on_request("exit-status") do |ch2,data| + channel.on_request("exit-status") do |ch2, data| status[:exit_code] = data.read_long end diff --git a/lib/net/ssh/errors.rb b/lib/net/ssh/errors.rb index c445459..7455fed 100644 --- a/lib/net/ssh/errors.rb +++ b/lib/net/ssh/errors.rb @@ -45,10 +45,10 @@ module Net # the remember_host! method on the exception, and then retry. class HostKeyError < Net::SSH::Exception # the callback to use when #remember_host! is called - attr_writer :callback #:nodoc: + attr_writer :callback # :nodoc: # situation-specific data describing the host (see #host, #port, etc.) - attr_writer :data #:nodoc: + attr_writer :data # :nodoc: # An accessor for getting at the data that was used to look up the host # (see also #fingerprint, #host, #port, #ip, and #key). diff --git a/lib/net/ssh/key_factory.rb b/lib/net/ssh/key_factory.rb index c8df306..5d5cfbf 100644 --- a/lib/net/ssh/key_factory.rb +++ b/lib/net/ssh/key_factory.rb @@ -17,14 +17,14 @@ module Net class KeyFactory # Specifies the mapping of SSH names to OpenSSL key classes. MAP = { - 'dh' => OpenSSL::PKey::DH, - 'rsa' => OpenSSL::PKey::RSA, - 'dsa' => OpenSSL::PKey::DSA, + 'dh' => OpenSSL::PKey::DH, + 'rsa' => OpenSSL::PKey::RSA, + 'dsa' => OpenSSL::PKey::DSA, 'ecdsa' => OpenSSL::PKey::EC } MAP["ed25519"] = Net::SSH::Authentication::ED25519::PrivKey if defined? Net::SSH::Authentication::ED25519 - class <<self + class << self # Fetch an OpenSSL key instance by its SSH name. It will be a new, # empty key of the given type. def get(name) @@ -36,7 +36,7 @@ module Net # appropriately. The new key is returned. If the key itself is # encrypted (requiring a passphrase to use), the user will be # prompted to enter their password unless passphrase works. - def load_private_key(filename, passphrase=nil, ask_passphrase=true, prompt=Prompt.default) + def load_private_key(filename, passphrase = nil, ask_passphrase = true, prompt = Prompt.default) data = File.read(File.expand_path(filename)) load_data_private_key(data, passphrase, ask_passphrase, filename, prompt) end @@ -46,7 +46,7 @@ module Net # appropriately. The new key is returned. If the key itself is # encrypted (requiring a passphrase to use), the user will be # prompted to enter their password unless passphrase works. - def load_data_private_key(data, passphrase=nil, ask_passphrase=true, filename="", prompt=Prompt.default) + def load_data_private_key(data, passphrase = nil, ask_passphrase = true, filename = "", prompt = Prompt.default) key_type = classify_key(data, filename) encrypted_key = nil @@ -86,7 +86,7 @@ module Net # Loads a public key. It will correctly determine whether # the file describes an RSA or DSA key, and will load it # appropriately. The new public key is returned. - def load_data_public_key(data, filename="") + def load_data_public_key(data, filename = "") fields = data.split(/ /) blob = nil diff --git a/lib/net/ssh/known_hosts.rb b/lib/net/ssh/known_hosts.rb index eb7d7a7..eeb8635 100644 --- a/lib/net/ssh/known_hosts.rb +++ b/lib/net/ssh/known_hosts.rb @@ -105,10 +105,10 @@ module Net SUPPORTED_TYPE.push('ssh-ed25519') if Net::SSH::Authentication::ED25519Loader::LOADED - class <<self + class << self # Searches all known host files (see KnownHosts.hostfiles) for all keys # of the given host. Returns an enumerable of keys found. - def search_for(host, options={}) + def search_for(host, options = {}) HostKeys.new(search_in(hostfiles(options), host, options), host, self, options) end @@ -127,7 +127,7 @@ module Net # # If you only want the user known host files, you can pass :user as # the second option. - def hostfiles(options, which=:all) + def hostfiles(options, which = :all) files = [] files += Array(options[:user_known_hosts_file] || %w[~/.ssh/known_hosts ~/.ssh/known_hosts2]) if which == :all || which == :user @@ -142,7 +142,7 @@ module Net # Looks in all user known host files (see KnownHosts.hostfiles) and tries to # add an entry for the given host and key to the first file it is able # to. - def add(host, key, options={}) + def add(host, key, options = {}) hostfiles(options, :user).each do |file| KnownHosts.new(file).add(host, key) return diff --git a/lib/net/ssh/prompt.rb b/lib/net/ssh/prompt.rb index e47d71e..a52463f 100644 --- a/lib/net/ssh/prompt.rb +++ b/lib/net/ssh/prompt.rb @@ -38,7 +38,7 @@ module Net # ask input from user, a prompter might ask for multiple inputs # (like user and password) in a single session. - def ask(prompt, echo=true) + def ask(prompt, echo = true) $stdout.print(prompt) $stdout.flush ret = $stdin.noecho(&:gets).chomp diff --git a/lib/net/ssh/proxy/http.rb b/lib/net/ssh/proxy/http.rb index e7dc3d0..fd9958e 100644 --- a/lib/net/ssh/proxy/http.rb +++ b/lib/net/ssh/proxy/http.rb @@ -40,7 +40,7 @@ module Net # # * :user => the user name to use when authenticating to the proxy # * :password => the password to use when authenticating - def initialize(proxy_host, proxy_port=80, options={}) + def initialize(proxy_host, proxy_port = 80, options = {}) @proxy_host = proxy_host @proxy_port = proxy_port @options = options diff --git a/lib/net/ssh/proxy/https.rb b/lib/net/ssh/proxy/https.rb index 4f4fdb2..2e12017 100644 --- a/lib/net/ssh/proxy/https.rb +++ b/lib/net/ssh/proxy/https.rb @@ -16,7 +16,7 @@ module Net # taken by Net::SSH::Proxy::HTTP it supports: # # * :ssl_context => the SSL configuration to use for the connection - def initialize(proxy_host, proxy_port=80, options={}) + def initialize(proxy_host, proxy_port = 80, options = {}) @ssl_context = options.delete(:ssl_context) || OpenSSL::SSL::SSLContext.new super(proxy_host, proxy_port, options) @@ -27,7 +27,7 @@ module Net # Shim to make OpenSSL::SSL::SSLSocket behave like a regular TCPSocket # for all intents and purposes of Net::SSH::BufferedIo module SSLSocketCompatibility - def self.extended(object) #:nodoc: + def self.extended(object) # :nodoc: object.define_singleton_method(:recv, object.method(:sysread)) object.sync_close = true end diff --git a/lib/net/ssh/proxy/socks4.rb b/lib/net/ssh/proxy/socks4.rb index a964d1e..9f4476a 100644 --- a/lib/net/ssh/proxy/socks4.rb +++ b/lib/net/ssh/proxy/socks4.rb @@ -37,7 +37,7 @@ module Net # Create a new proxy connection to the given proxy host and port. # Optionally, a :user key may be given to identify the username # with which to authenticate. - def initialize(proxy_host, proxy_port=1080, options={}) + def initialize(proxy_host, proxy_port = 1080, options = {}) @proxy_host = proxy_host @proxy_port = proxy_port @options = options diff --git a/lib/net/ssh/proxy/socks5.rb b/lib/net/ssh/proxy/socks5.rb index 8a0ae91..1e66318 100644 --- a/lib/net/ssh/proxy/socks5.rb +++ b/lib/net/ssh/proxy/socks5.rb @@ -52,7 +52,7 @@ module Net # Create a new proxy connection to the given proxy host and port. # Optionally, :user and :password options may be given to # identify the username and password with which to authenticate. - def initialize(proxy_host, proxy_port=1080, options={}) + def initialize(proxy_host, proxy_port = 1080, options = {}) @proxy_host = proxy_host @proxy_port = proxy_port @options = options diff --git a/lib/net/ssh/service/forward.rb b/lib/net/ssh/service/forward.rb index 0edfaa7..8b2f0f9 100644 --- a/lib/net/ssh/service/forward.rb +++ b/lib/net/ssh/service/forward.rb @@ -17,7 +17,7 @@ module Net attr_reader :session # A simple class for representing a requested remote forwarded port. - Remote = Struct.new(:host, :port) #:nodoc: + Remote = Struct.new(:host, :port) # :nodoc: # Instantiates a new Forward service instance atop the given connection # service session. This will register new channel open handlers to handle @@ -105,7 +105,7 @@ module Net # # ssh.forward.cancel_local(1234) # ssh.forward.cancel_local(1234, "0.0.0.0") - def cancel_local(port, bind_address="127.0.0.1") + def cancel_local(port, bind_address = "127.0.0.1") socket = @local_forwarded_ports.delete([port, bind_address]) socket.shutdown rescue nil socket.close rescue nil @@ -214,7 +214,7 @@ module Net # raise Net::SSH::Exception, "remote forwarding request failed" # end # - def remote(port, host, remote_port, remote_host="127.0.0.1") + def remote(port, host, remote_port, remote_host = "127.0.0.1") session.send_global_request("tcpip-forward", :string, remote_host, :long, remote_port) do |success, response| if success remote_port = response.read_long if remote_port == 0 @@ -248,7 +248,7 @@ module Net # # ssh.forward.cancel_remote(1234, "0.0.0.0") # ssh.loop { ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) } - def cancel_remote(port, host="127.0.0.1") + def cancel_remote(port, host = "127.0.0.1") session.send_global_request("cancel-tcpip-forward", :string, host, :long, port) do |success, response| if success @remote_forwarded_ports.delete([port, host]) diff --git a/lib/net/ssh/test.rb b/lib/net/ssh/test.rb index d97eebf..cb727ba 100644 --- a/lib/net/ssh/test.rb +++ b/lib/net/ssh/test.rb @@ -56,21 +56,21 @@ module Net # Returns the test socket instance to use for these tests (see # Net::SSH::Test::Socket). - def socket(options={}) + def socket(options = {}) @socket ||= Net::SSH::Test::Socket.new end # Returns the connection session (Net::SSH::Connection::Session) for use # in these tests. It is a fully functional SSH session, operating over # a mock socket (#socket). - def connection(options={}) + def connection(options = {}) @connection ||= Net::SSH::Connection::Session.new(transport(options), options) end # Returns the transport session (Net::SSH::Transport::Session) for use # in these tests. It is a fully functional SSH transport session, operating # over a mock socket (#socket). - def transport(options={}) + def transport(options = {}) @transport ||= Net::SSH::Transport::Session.new( options[:host] || "localhost", options.merge(kex: "test", host_key: "ssh-rsa", append_all_supported_algorithms: true, verify_host_key: :never, proxy: socket(options)) diff --git a/lib/net/ssh/test/channel.rb b/lib/net/ssh/test/channel.rb index 3ee56e2..c3baa90 100644 --- a/lib/net/ssh/test/channel.rb +++ b/lib/net/ssh/test/channel.rb @@ -65,7 +65,7 @@ module Net # be scripted. # # channel.sends_exec "ls -l" - def sends_exec(command, reply=true, success=true) + def sends_exec(command, reply = true, success = true) script.sends_channel_request(self, "exec", reply, command, success) end @@ -74,7 +74,7 @@ module Net # and +success+ arguments. # # channel.sends_subsystem "sftp" - def sends_subsystem(subsystem, reply=true, success=true) + def sends_subsystem(subsystem, reply = true, success = true) script.sends_channel_request(self, "subsystem", reply, subsystem, success) end @@ -124,7 +124,7 @@ module Net # Scripts the reception of an "exit-status" channel request packet. # # channel.gets_exit_status(127) - def gets_exit_status(status=0) + def gets_exit_status(status = 0) script.gets_channel_request(self, "exit-status", false, status) end diff --git a/lib/net/ssh/test/extensions.rb b/lib/net/ssh/test/extensions.rb index 527c88b..733a531 100644 --- a/lib/net/ssh/test/extensions.rb +++ b/lib/net/ssh/test/extensions.rb @@ -38,7 +38,7 @@ module Net module PacketStream include BufferedIo # make sure we get the extensions here, too - def self.included(base) #:nodoc: + def self.included(base) # :nodoc: base.send :alias_method, :real_available_for_read?, :available_for_read? base.send :alias_method, :available_for_read?, :test_available_for_read? @@ -93,7 +93,7 @@ module Net # An extension to Net::SSH::Connection::Channel. Facilitates unit testing. module Channel - def self.included(base) #:nodoc: + def self.included(base) # :nodoc: base.send :alias_method, :send_data_for_real, :send_data base.send :alias_method, :send_data, :send_data_for_test end @@ -111,7 +111,7 @@ module Net # An extension to the built-in ::IO class. Simply redefines IO.select # so that it can be scripted in Net::SSH unit tests. module IO - def self.included(base) #:nodoc: + def self.included(base) # :nodoc: base.extend(ClassMethods) end @@ -132,8 +132,8 @@ module Net end module ClassMethods - def self.extended(obj) #:nodoc: - class <<obj + def self.extended(obj) # :nodoc: + class << obj alias_method :select_for_real, :select alias_method :select, :select_for_test end @@ -142,7 +142,7 @@ module Net # The testing version of ::IO.select. Assumes that all readers, # writers, and errors arrays are either nil, or contain only objects # that mix in Net::SSH::Test::Extensions::BufferedIo. - def select_for_test(readers=nil, writers=nil, errors=nil, wait=nil) + def select_for_test(readers = nil, writers = nil, errors = nil, wait = nil) return select_for_real(readers, writers, errors, wait) unless Net::SSH::Test::Extensions::IO.extension_enabled? ready_readers = Array(readers).select { |r| r.select_for_read? } diff --git a/lib/net/ssh/test/packet.rb b/lib/net/ssh/test/packet.rb index e604b98..da5a986 100644 --- a/lib/net/ssh/test/packet.rb +++ b/lib/net/ssh/test/packet.rb @@ -82,7 +82,7 @@ module Net when CHANNEL_REQUEST parts = %i[long string bool] case @data[1] - when "exec", "subsystem","shell" then parts << :string + when "exec", "subsystem", "shell" then parts << :string when "exit-status" then parts << :long when "pty-req" then parts.concat(%i[string long long long long string]) when "env" then parts.contact(%i[string string]) diff --git a/lib/net/ssh/test/script.rb b/lib/net/ssh/test/script.rb index 7879ad7..7eee90a 100644 --- a/lib/net/ssh/test/script.rb +++ b/lib/net/ssh/test/script.rb @@ -33,7 +33,7 @@ module Net # # A new Net::SSH::Test::Channel instance is returned, which can be used # to script additional channel operations. - def opens_channel(confirm=true) + def opens_channel(confirm = true) channel = Channel.new(self) channel.remote_id = 5555 @@ -70,7 +70,7 @@ module Net # # This will typically be called via Net::SSH::Test::Channel#sends_exec or # Net::SSH::Test::Channel#sends_subsystem. - def sends_channel_request(channel, request, reply, data, success=true) + def sends_channel_request(channel, request, reply, data, success = true) if data.is_a? Array events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, *data) else @@ -163,7 +163,7 @@ module Net # # # peek at the next event # event = script.next(:first) - def next(mode=:shift) + def next(mode = :shift) events.send(mode) end diff --git a/lib/net/ssh/test/socket.rb b/lib/net/ssh/test/socket.rb index 42ece27..543a536 100644 --- a/lib/net/ssh/test/socket.rb +++ b/lib/net/ssh/test/socket.rb @@ -40,7 +40,7 @@ module Net # Allows the socket to also mimic a socket factory, simply returning # +self+. - def open(host, port, options={}) + def open(host, port, options = {}) @host, @port = host, port self end diff --git a/lib/net/ssh/transport/algorithms.rb b/lib/net/ssh/transport/algorithms.rb index f0d8d15..cc12d95 100644 --- a/lib/net/ssh/transport/algorithms.rb +++ b/lib/net/ssh/transport/algorithms.rb @@ -146,7 +146,7 @@ module Net # Instantiates a new Algorithms object, and prepares the hash of preferred # algorithms based on the options parameter and the ALGORITHMS constant. - def initialize(session, options={}) + def initialize(session, options = {}) @session = session @logger = session.logger @options = options @@ -369,10 +369,10 @@ module Net language = algorithms[:language].join(",") Net::SSH::Buffer.from(:byte, KEXINIT, - :long, [rand(0xFFFFFFFF), rand(0xFFFFFFFF), rand(0xFFFFFFFF), rand(0xFFFFFFFF)], - :mstring, [kex, host_key, encryption, encryption, hmac, hmac], - :mstring, [compression, compression, language, language], - :bool, false, :long, 0) + :long, [rand(0xFFFFFFFF), rand(0xFFFFFFFF), rand(0xFFFFFFFF), rand(0xFFFFFFFF)], + :mstring, [kex, host_key, encryption, encryption, hmac, hmac], + :mstring, [compression, compression, language, language], + :bool, false, :long, 0) end # Given the parsed server KEX packet, and the client's preferred algorithm @@ -438,13 +438,13 @@ module Net debug { "exchanging keys" } algorithm = Kex::MAP[kex].new(self, session, - client_version_string: Net::SSH::Transport::ServerVersion::PROTO_VERSION, - server_version_string: session.server_version.version, - server_algorithm_packet: @server_packet, - client_algorithm_packet: @client_packet, - need_bytes: kex_byte_requirement, - minimum_dh_bits: options[:minimum_dh_bits], - logger: logger) + client_version_string: Net::SSH::Transport::ServerVersion::PROTO_VERSION, + server_version_string: session.server_version.version, + server_algorithm_packet: @server_packet, + client_algorithm_packet: @client_packet, + need_bytes: kex_byte_requirement, + minimum_dh_bits: options[:minimum_dh_bits], + logger: logger) result = algorithm.exchange_keys secret = result[:shared_secret].to_ssh diff --git a/lib/net/ssh/transport/cipher_factory.rb b/lib/net/ssh/transport/cipher_factory.rb index bedf1ea..4dde239 100644 --- a/lib/net/ssh/transport/cipher_factory.rb +++ b/lib/net/ssh/transport/cipher_factory.rb @@ -10,23 +10,23 @@ module Net class CipherFactory # Maps the SSH name of a cipher to it's corresponding OpenSSL name SSH_TO_OSSL = { - "3des-cbc" => "des-ede3-cbc", - "blowfish-cbc" => "bf-cbc", - "aes256-cbc" => "aes-256-cbc", - "aes192-cbc" => "aes-192-cbc", - "aes128-cbc" => "aes-128-cbc", - "idea-cbc" => "idea-cbc", - "cast128-cbc" => "cast-cbc", + "3des-cbc" => "des-ede3-cbc", + "blowfish-cbc" => "bf-cbc", + "aes256-cbc" => "aes-256-cbc", + "aes192-cbc" => "aes-192-cbc", + "aes128-cbc" => "aes-128-cbc", + "idea-cbc" => "idea-cbc", + "cast128-cbc" => "cast-cbc", "rijndael-cbc@lysator.liu.se" => "aes-256-cbc", - "3des-ctr" => "des-ede3", - "blowfish-ctr" => "bf-ecb", + "3des-ctr" => "des-ede3", + "blowfish-ctr" => "bf-ecb", - "aes256-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-256-ctr") ? "aes-256-ctr" : "aes-256-ecb", - "aes192-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-192-ctr") ? "aes-192-ctr" : "aes-192-ecb", - "aes128-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-128-ctr") ? "aes-128-ctr" : "aes-128-ecb", - 'cast128-ctr' => 'cast5-ecb', + "aes256-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-256-ctr") ? "aes-256-ctr" : "aes-256-ecb", + "aes192-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-192-ctr") ? "aes-192-ctr" : "aes-192-ecb", + "aes128-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-128-ctr") ? "aes-128-ctr" : "aes-128-ecb", + 'cast128-ctr' => 'cast5-ecb', - 'none' => 'none' + 'none' => 'none' } # Returns true if the underlying OpenSSL library supports the given cipher, @@ -43,7 +43,7 @@ module Net # iv, key, shared, hash and digester values. Additionally, the # cipher will be put into encryption or decryption mode, based on the # value of the +encrypt+ parameter. - def self.get(name, options={}) + def self.get(name, options = {}) ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'" return IdentityCipher if ossl_name == "none" diff --git a/lib/net/ssh/transport/ctr.rb b/lib/net/ssh/transport/ctr.rb index 9c67aff..a1397f4 100644 --- a/lib/net/ssh/transport/ctr.rb +++ b/lib/net/ssh/transport/ctr.rb @@ -2,7 +2,7 @@ require 'openssl' require 'delegate' module Net::SSH::Transport - #:nodoc: + # :nodoc: class OpenSSLAESCTR < SimpleDelegator def initialize(original) super @@ -26,7 +26,7 @@ module Net::SSH::Transport end end - #:nodoc: + # :nodoc: # Pure-Ruby implementation of Stateful Decryption Counter(SDCTR) Mode # for Block Ciphers. See RFC4344 for detail. module CTR @@ -95,7 +95,7 @@ module Net::SSH::Transport def xor!(s1, s2) s = [] - s1.unpack('Q*').zip(s2.unpack('Q*')) {|a,b| s.push(a ^ b) } + s1.unpack('Q*').zip(s2.unpack('Q*')) {|a, b| s.push(a ^ b) } s.pack('Q*') end singleton_class.send(:private, :xor!) diff --git a/lib/net/ssh/transport/hmac.rb b/lib/net/ssh/transport/hmac.rb index 0905050..0742236 100644 --- a/lib/net/ssh/transport/hmac.rb +++ b/lib/net/ssh/transport/hmac.rb @@ -17,24 +17,24 @@ require 'net/ssh/transport/hmac/none' module Net::SSH::Transport::HMAC # The mapping of SSH hmac algorithms to their implementations MAP = { - 'hmac-md5' => MD5, - 'hmac-md5-96' => MD5_96, - 'hmac-sha1' => SHA1, - 'hmac-sha1-96' => SHA1_96, - 'hmac-sha2-256' => SHA2_256, - 'hmac-sha2-256-96' => SHA2_256_96, - 'hmac-sha2-512' => SHA2_512, - 'hmac-sha2-512-96' => SHA2_512_96, + 'hmac-md5' => MD5, + 'hmac-md5-96' => MD5_96, + 'hmac-sha1' => SHA1, + 'hmac-sha1-96' => SHA1_96, + 'hmac-sha2-256' => SHA2_256, + 'hmac-sha2-256-96' => SHA2_256_96, + 'hmac-sha2-512' => SHA2_512, + 'hmac-sha2-512-96' => SHA2_512_96, 'hmac-sha2-256-etm@openssh.com' => SHA2_256_Etm, 'hmac-sha2-512-etm@openssh.com' => SHA2_512_Etm, - 'hmac-ripemd160' => RIPEMD160, - 'hmac-ripemd160@openssh.com' => RIPEMD160, - 'none' => None + 'hmac-ripemd160' => RIPEMD160, + 'hmac-ripemd160@openssh.com' => RIPEMD160, + 'none' => None } # Retrieves a new hmac instance of the given SSH type (+name+). If +key+ is # given, the new instance will be initialized with that key. - def self.get(name, key="", parameters = {}) + def self.get(name, key = "", parameters = {}) impl = MAP[name] or raise ArgumentError, "hmac not found: #{name.inspect}" impl.new(Net::SSH::Transport::KeyExpander.expand_key(impl.key_length, key, parameters)) end diff --git a/lib/net/ssh/transport/hmac/abstract.rb b/lib/net/ssh/transport/hmac/abstract.rb index 575b03b..8bc2a56 100644 --- a/lib/net/ssh/transport/hmac/abstract.rb +++ b/lib/net/ssh/transport/hmac/abstract.rb @@ -7,7 +7,7 @@ module Net module HMAC # The base class of all OpenSSL-based HMAC algorithm wrappers. class Abstract - class <<self + class << self def etm(*v) @etm = false if !defined?(@etm) if v.empty? @@ -76,19 +76,19 @@ module Net # The key in use for this instance. attr_reader :key - def initialize(key=nil) + def initialize(key = nil) self.key = key end # Sets the key to the given value, truncating it so that it is the correct # length. def key=(value) - @key = value ? value.to_s[0,key_length] : nil + @key = value ? value.to_s[0, key_length] : nil end # Compute the HMAC digest for the given data string. def digest(data) - OpenSSL::HMAC.digest(digest_class.new, key, data)[0,mac_length] + OpenSSL::HMAC.digest(digest_class.new, key, data)[0, mac_length] end end end diff --git a/lib/net/ssh/transport/identity_cipher.rb b/lib/net/ssh/transport/identity_cipher.rb index b8a90bc..ad1a764 100644 --- a/lib/net/ssh/transport/identity_cipher.rb +++ b/lib/net/ssh/transport/identity_cipher.rb @@ -5,7 +5,7 @@ module Net # keeps things in the code nice and clean when a cipher has not yet been # determined (i.e., during key exchange). class IdentityCipher - class <<self + class << self # A default block size of 8 is required by the SSH2 protocol. def block_size 8 diff --git a/lib/net/ssh/transport/kex.rb b/lib/net/ssh/transport/kex.rb index a43d713..cf21107 100644 --- a/lib/net/ssh/transport/kex.rb +++ b/lib/net/ssh/transport/kex.rb @@ -13,14 +13,14 @@ module Net::SSH::Transport # Maps the supported key-exchange algorithms as named by the SSH protocol # to their corresponding implementors. MAP = { - 'diffie-hellman-group1-sha1' => DiffieHellmanGroup1SHA1, - 'diffie-hellman-group14-sha1' => DiffieHellmanGroup14SHA1, - 'diffie-hellman-group14-sha256' => DiffieHellmanGroup14SHA256, - 'diffie-hellman-group-exchange-sha1' => DiffieHellmanGroupExchangeSHA1, + 'diffie-hellman-group1-sha1' => DiffieHellmanGroup1SHA1, + 'diffie-hellman-group14-sha1' => DiffieHellmanGroup14SHA1, + 'diffie-hellman-group14-sha256' => DiffieHellmanGroup14SHA256, + 'diffie-hellman-group-exchange-sha1' => DiffieHellmanGroupExchangeSHA1, 'diffie-hellman-group-exchange-sha256' => DiffieHellmanGroupExchangeSHA256, - 'ecdh-sha2-nistp256' => EcdhSHA2NistP256, - 'ecdh-sha2-nistp384' => EcdhSHA2NistP384, - 'ecdh-sha2-nistp521' => EcdhSHA2NistP521 + 'ecdh-sha2-nistp256' => EcdhSHA2NistP256, + 'ecdh-sha2-nistp384' => EcdhSHA2NistP384, + 'ecdh-sha2-nistp521' => EcdhSHA2NistP521 } if Net::SSH::Transport::Kex::Curve25519Sha256Loader::LOADED diff --git a/lib/net/ssh/transport/kex/abstract.rb b/lib/net/ssh/transport/kex/abstract.rb index 3fd8c3c..27d2613 100644 --- a/lib/net/ssh/transport/kex/abstract.rb +++ b/lib/net/ssh/transport/kex/abstract.rb @@ -72,7 +72,7 @@ module Net # Verify that the given key is of the expected type, and that it # really is the key for the session's host. Raise Net::SSH::Exception # if it is not. - def verify_server_key(key) #:nodoc: + def verify_server_key(key) # :nodoc: unless matching?(key.ssh_type, algorithms.host_key) raise Net::SSH::Exception, "host key algorithm mismatch '#{key.ssh_type}' != '#{algorithms.host_key}'" end @@ -97,7 +97,7 @@ module Net # Verify the signature that was received. Raise Net::SSH::Exception # if the signature could not be verified. Otherwise, return the new # session-id. - def verify_signature(result) #:nodoc: + def verify_signature(result) # :nodoc: response = build_signature_buffer(result) hash = digester.digest(response.to_s) @@ -113,7 +113,7 @@ module Net # Send the NEWKEYS message, and expect the NEWKEYS message in # reply. - def confirm_newkeys #:nodoc: + def confirm_newkeys # :nodoc: # send own NEWKEYS message first (the wodSSHServer won't send first) response = Net::SSH::Buffer.new response.write_byte(NEWKEYS) diff --git a/lib/net/ssh/transport/kex/abstract5656.rb b/lib/net/ssh/transport/kex/abstract5656.rb index 06c874d..5f8d133 100644 --- a/lib/net/ssh/transport/kex/abstract5656.rb +++ b/lib/net/ssh/transport/kex/abstract5656.rb @@ -32,7 +32,7 @@ module Net response end - def send_kexinit #:nodoc: + def send_kexinit # :nodoc: init, reply = get_message_types # send the KEXECDH_INIT message diff --git a/lib/net/ssh/transport/kex/curve25519_sha256.rb b/lib/net/ssh/transport/kex/curve25519_sha256.rb index a9ce16c..e942846 100644 --- a/lib/net/ssh/transport/kex/curve25519_sha256.rb +++ b/lib/net/ssh/transport/kex/curve25519_sha256.rb @@ -18,7 +18,7 @@ module Net private - def generate_key #:nodoc: + def generate_key # :nodoc: ::X25519::Scalar.generate end diff --git a/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb b/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb index 34af18b..9abab2c 100644 --- a/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +++ b/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb @@ -59,7 +59,7 @@ module Net # Generate a DH key with a private key consisting of the given # number of bytes. - def generate_key #:nodoc: + def generate_key # :nodoc: dh = OpenSSL::PKey::DH.new if dh.respond_to?(:set_pqg) @@ -86,7 +86,7 @@ module Net # # Parse the buffer from a KEXDH_REPLY message, returning a hash of # the extracted values. - def send_kexinit #:nodoc: + def send_kexinit # :nodoc: init, reply = get_message_types # send the KEXDH_INIT message @@ -108,8 +108,8 @@ module Net 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}'" + "host key algorithm mismatch for signature " + + "'#{sig_type}' != '#{algorithms.host_key_format}'" end result[:server_sig] = sig_buffer.read_string diff --git a/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb b/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb index e081669..22178e2 100644 --- a/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +++ b/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb @@ -34,7 +34,7 @@ module Net::SSH::Transport::Kex # request the DH key parameters for the given number of bits. buffer = Net::SSH::Buffer.from(:byte, KEXDH_GEX_REQUEST, :long, data[:minimum_dh_bits], - :long, data[:need_bits], :long, MAXIMUM_BITS) + :long, data[:need_bits], :long, MAXIMUM_BITS) connection.send_message(buffer) buffer = connection.next_message diff --git a/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb b/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb index 84d0e4a..a0c911d 100644 --- a/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +++ b/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb @@ -17,7 +17,7 @@ module Net private - def generate_key #:nodoc: + def generate_key # :nodoc: OpenSSL::PKey::EC.new(curve_name).generate_key end diff --git a/lib/net/ssh/transport/key_expander.rb b/lib/net/ssh/transport/key_expander.rb index 93fbaf1..8cff7e9 100644 --- a/lib/net/ssh/transport/key_expander.rb +++ b/lib/net/ssh/transport/key_expander.rb @@ -4,7 +4,7 @@ module Net module KeyExpander # Generate a key value in accordance with the SSH2 specification. # (RFC4253 7.2. "Output from Key Exchange") - def self.expand_key(bytes, start, options={}) + def self.expand_key(bytes, start, options = {}) if bytes == 0 return "" end diff --git a/lib/net/ssh/transport/openssl.rb b/lib/net/ssh/transport/openssl.rb index af0a0cc..4ff58cf 100644 --- a/lib/net/ssh/transport/openssl.rb +++ b/lib/net/ssh/transport/openssl.rb @@ -94,13 +94,13 @@ module OpenSSL # Converts the key to a blob, according to the SSH2 protocol. def to_blob @blob ||= Net::SSH::Buffer.from(:string, ssh_type, - :bignum, p, :bignum, q, :bignum, g, :bignum, pub_key).to_s + :bignum, p, :bignum, q, :bignum, g, :bignum, pub_key).to_s end # Verifies the given signature matches the given data. def ssh_do_verify(sig, data, options = {}) - sig_r = sig[0,20].unpack("H*")[0].to_i(16) - sig_s = sig[20,20].unpack("H*")[0].to_i(16) + sig_r = sig[0, 20].unpack("H*")[0].to_i(16) + sig_s = sig[20, 20].unpack("H*")[0].to_i(16) a1sig = OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::Integer(sig_r), OpenSSL::ASN1::Integer(sig_s) diff --git a/lib/net/ssh/transport/packet_stream.rb b/lib/net/ssh/transport/packet_stream.rb index fc07ea1..a4120d4 100644 --- a/lib/net/ssh/transport/packet_stream.rb +++ b/lib/net/ssh/transport/packet_stream.rb @@ -80,7 +80,7 @@ module Net # available or not, and will return nil if there is no packet ready to be # returned. If the mode parameter is :block, then this method will block # until a packet is available or timeout seconds have passed. - def next_packet(mode=:nonblock, timeout=nil) + def next_packet(mode = :nonblock, timeout = nil) case mode when :nonblock then packet = poll_next_packet diff --git a/lib/net/ssh/transport/session.rb b/lib/net/ssh/transport/session.rb index 261e5c2..fb41c16 100644 --- a/lib/net/ssh/transport/session.rb +++ b/lib/net/ssh/transport/session.rb @@ -55,7 +55,7 @@ module Net # Instantiates a new transport layer abstraction. This will block until # the initial key exchange completes, leaving you with a ready-to-use # transport session. - def initialize(host, options={}) + def initialize(host, options = {}) self.logger = options[:logger] @host = host @@ -186,7 +186,7 @@ module Net # received, it will be enqueued and otherwise ignored. When a key-exchange # is not in process, and consume_queue is true, packets will be first # read from the queue before the socket is queried. - def poll_message(mode=:nonblock, consume_queue=true) + def poll_message(mode = :nonblock, consume_queue = true) loop do return @queue.shift if consume_queue && @queue.any? && algorithms.allow?(@queue.first) @@ -252,27 +252,27 @@ module Net # Configure's the packet stream's client state with the given set of # options. This is typically used to define the cipher, compression, and # hmac algorithms to use when sending packets to the server. - def configure_client(options={}) + def configure_client(options = {}) socket.client.set(options) end # Configure's the packet stream's server state with the given set of # options. This is typically used to define the cipher, compression, and # hmac algorithms to use when reading packets from the server. - def configure_server(options={}) + def configure_server(options = {}) socket.server.set(options) end # Sets a new hint for the packet stream, which the packet stream may use # to change its behavior. (See PacketStream#hints). - def hint(which, value=true) + def hint(which, value = true) socket.hints[which] = value end public # this method is primarily for use in tests - attr_reader :queue #:nodoc: + attr_reader :queue # :nodoc: private diff --git a/lib/net/ssh/transport/state.rb b/lib/net/ssh/transport/state.rb index b472191..1af6b86 100644 --- a/lib/net/ssh/transport/state.rb +++ b/lib/net/ssh/transport/state.rb @@ -191,7 +191,7 @@ module Net private - def update_next_iv(data, reset=false) + def update_next_iv(data, reset = false) @next_iv << data @next_iv = @next_iv[@next_iv.size - cipher.iv_len..-1] |