From a99d32f60af94073bf676808c1910756c4c61269 Mon Sep 17 00:00:00 2001 From: Peter Ericson Date: Tue, 3 Jun 2014 13:49:19 +1000 Subject: [PATCH] Add WinRM over SSL support --- Gemfile | 2 ++ plugins/communicators/winrm/communicator.rb | 1 + plugins/communicators/winrm/shell.rb | 10 +++++++--- vagrant.gemspec | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 15f245819..7820e506f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source "https://rubygems.org" gemspec +# f4ece43: Allow the user to disable SSL peer verification. +gem 'winrm', git: 'https://github.com/WinRb/WinRM.git', ref: 'f4ece4384df2768bc7756c3c5c336db65b05c674' if File.exist?(File.expand_path("../../vagrant-spec", __FILE__)) gem 'vagrant-spec', path: "../vagrant-spec" diff --git a/plugins/communicators/winrm/communicator.rb b/plugins/communicators/winrm/communicator.rb index 7609f16b3..29737f6ac 100644 --- a/plugins/communicators/winrm/communicator.rb +++ b/plugins/communicators/winrm/communicator.rb @@ -111,6 +111,7 @@ module VagrantPlugins port: winrm_info[:port], timeout_in_seconds: @machine.config.winrm.timeout, max_tries: @machine.config.winrm.max_tries, + ssl: @machine.config.winrm.ssl, ) end diff --git a/plugins/communicators/winrm/shell.rb b/plugins/communicators/winrm/shell.rb index 353c0e84d..c6d626448 100644 --- a/plugins/communicators/winrm/shell.rb +++ b/plugins/communicators/winrm/shell.rb @@ -38,17 +38,19 @@ module VagrantPlugins attr_reader :port attr_reader :timeout_in_seconds attr_reader :max_tries + attr_reader :ssl def initialize(host, username, password, options = {}) @logger = Log4r::Logger.new("vagrant::communication::winrmshell") @logger.debug("initializing WinRMShell") @host = host - @port = options[:port] || 5985 + @port = options[:port] || options[:ssl] ? 5986 : 5985 @username = username @password = password @timeout_in_seconds = options[:timeout_in_seconds] || 60 @max_tries = options[:max_tries] || 20 + @ssl = options[:ssl] || false end def powershell(command, &block) @@ -119,6 +121,7 @@ module VagrantPlugins @logger.info(" - Host: #{@host}") @logger.info(" - Port: #{@port}") @logger.info(" - Username: #{@username}") + @logger.info(" - SSL: #{@ssl}") client = ::WinRM::WinRMWebService.new(endpoint, :plaintext, endpoint_options) client.set_timeout(@timeout_in_seconds) @@ -131,7 +134,7 @@ module VagrantPlugins end def endpoint - "http://#{@host}:#{@port}/wsman" + "http#{@ssl ? 's' : ''}://#{@host}:#{@port}/wsman" end def endpoint_options @@ -140,7 +143,8 @@ module VagrantPlugins host: @host, port: @port, operation_timeout: @timeout_in_seconds, - basic_auth_only: true } + basic_auth_only: true, + no_ssl_peer_verification: true } end end #WinShell class end diff --git a/vagrant.gemspec b/vagrant.gemspec index 0afe7e766..4c4beebf6 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -28,7 +28,8 @@ Gem::Specification.new do |s| s.add_dependency "rb-kqueue", "~> 0.2.0" s.add_dependency "rest-client", ">= 1.6.0", "< 2.0" s.add_dependency "wdm", "~> 0.1.0" - s.add_dependency "winrm", "~> 1.1.3" + # 1.1.4 (Unreleased) + #s.add_dependency "winrm", "~> 1.1.3" # We lock this down to avoid compilation issues. s.add_dependency "nokogiri", "= 1.6.3.1"