Class: WinRM::HTTP::HttpNegotiate

Inherits:
HttpTransport show all
Defined in:
lib/winrm/http/transport.rb

Overview

NTLM/Negotiate, secure, HTTP transport

Instance Attribute Summary

Attributes inherited from HttpTransport

#endpoint

Instance Method Summary collapse

Methods inherited from HttpTransport

#basic_auth_only!, #no_ssl_peer_verification!, #no_sspi_auth!, #ssl_peer_fingerprint_verification!, #verify_ssl_fingerprint, #with_untrusted_ssl_connection

Constructor Details

#initialize(endpoint, user, pass, opts) ⇒ HttpNegotiate

Returns a new instance of HttpNegotiate.



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/winrm/http/transport.rb', line 148

def initialize(endpoint, user, pass, opts)
  super(endpoint, opts)
  require 'rubyntlm'
  no_sspi_auth!

  user_parts = user.split('\\')
  if user_parts.length > 1
    opts[:domain] = user_parts[0]
    user = user_parts[1]
  end

  @ntlmcli = Net::NTLM::Client.new(user, pass, opts)
  @retryable = true
  no_ssl_peer_verification! if opts[:no_ssl_peer_verification]
  @ssl_peer_fingerprint = opts[:ssl_peer_fingerprint]
  @httpcli.ssl_config.set_trust_ca(opts[:ca_trust_path]) if opts[:ca_trust_path]
end

Instance Method Details

#send_request(message) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/winrm/http/transport.rb', line 166

def send_request(message)
  ssl_peer_fingerprint_verification!
  init_auth if @ntlmcli.session.nil?
  log_soap_message(message)

  hdr = {
    'Content-Type' => 'multipart/encrypted;'\
      'protocol="application/HTTP-SPNEGO-session-encrypted";boundary="Encrypted Boundary"'
  }

  resp = @httpcli.post(@endpoint, body(seal(message), message.bytesize), hdr)
  verify_ssl_fingerprint(resp.peer_cert)
  if resp.status == 401 && @retryable
    @retryable = false
    init_auth
    send_request(message)
  else
    @retryable = true
    decrypted_body = winrm_decrypt(resp)
    log_soap_message(decrypted_body)
    WinRM::ResponseHandler.new(decrypted_body, resp.status).parse_to_xml
  end
end