
require 'vagrant/util/subprocess'
require "vagrant-rekey-ssh/helpers"

module VagrantPlugins
  module RekeySSH
    class ActionSSHInfo
      
      def initialize(app, env)
        @app = app
        @env = env
        @machine = env[:machine]
      end
      
      def call(env)
        
        if @machine.config.rekey_ssh.enable
        
          # ensure we have a key
          generate_ssh_key
          
          # if the user's config hasn't specified a key, then set our key
          # in here. We also specify the insecure key too so that it works
          # in case we haven't replaced the key yet.
          # -> TODO: only specify the insecure key when we haven't set the
          #    less insecure key on the box.
          
          if @machine.config.ssh.private_key_path.nil?
            
            if ::File.exists?(rekey_sentinel_file)
              if Vagrant::VERSION < "1.4.0"
                @machine.config.ssh.private_key_path = ssh_key_path
              else
                @machine.config.ssh.private_key_path = [ssh_key_path]
              end
            end
            
            # Vagrant < 1.4 only supports a single ssh key, do this differently
            #if Vagrant::VERSION <= "1.4.0"
            #else
            #  @machine.config.ssh.private_key_path = [ssh_key_path, @machine.env.default_private_key_path]
            #end
          end
          
        end
        
        @app.call(env)
        
      end
      
      protected
      
      include VagrantPlugins::RekeySSH::Helpers
      
    end
  end
end


require 'vagrant/util/subprocess'
require "vagrant-rekey-ssh/helpers"

module VagrantPlugins
  module RekeySSH
    class ActionSSHInfo
      
      def initialize(app, env)
        @app = app
        @env = env
        @machine = env[:machine]
      end
      
      def call(env)
        
        if @machine.config.rekey_ssh.enable
        
          # ensure we have a key
          generate_ssh_key
          
          # if the user's config hasn't specified a key, then set our key
          # in here. We also specify the insecure key too so that it works
          # in case we haven't replaced the key yet.
          # -> TODO: only specify the insecure key when we haven't set the
          #    less insecure key on the box.
          
          if @machine.config.ssh.private_key_path.nil?
            
            if ::File.exists?(rekey_sentinel_file)
              if Vagrant::VERSION < "1.4.0"
                @machine.config.ssh.private_key_path = ssh_key_path
              else
                @machine.config.ssh.private_key_path = [ssh_key_path, @machine.env.default_private_key_path]
              end
            end
            
            # Vagrant < 1.4 only supports a single ssh key, do this differently
            #if Vagrant::VERSION <= "1.4.0"
            #else
            #  @machine.config.ssh.private_key_path = [ssh_key_path, @machine.env.default_private_key_path]
            #end
          end
          
        end
        
        @app.call(env)
        
      end
      
      protected
      
      include VagrantPlugins::RekeySSH::Helpers
      
    end
  end
end

Fix problems transitioning from insecure_private_key to less_insecure_private_key (Vagrant >= 1.4.0)
Fix problems transitioning from insecure_private_key to less_insecure_private_key (Vagrant >= 1.4.0)

This doesn't fix Vagrant < 1.4.0.

Without this, `vagrant reload` after installing the plugin just hangs
forever waiting for the VM to boot, with output similar to the
following:

    ==> default: Less insecure SSH key not found, generating key
    ==> default: Less insecure SSH key generated and stored at /Users/dlitz/.vagrant.d/less_insecure_private_key
    ==> default: Attempting graceful shutdown of VM...
        default: Guest communication could not be established! This is usually because
        default: SSH is not running, the authentication information was changed,
        default: or some other networking issue. Vagrant will force halt, if
        default: capable.
    ==> default: Stopping the VMware VM...
    ==> default: Verifying vmnet devices are healthy...
    ==> default: Preparing network adapters...
    ==> default: Starting the VMware VM...
    ==> default: Waiting for the VM to finish booting...
