Class: T2Server::HttpsConnection

Inherits:
HttpConnection show all
Defined in:
lib/t2-server/net/connection.rb

Overview

A class representing a https connection to a Taverna Server. This class should only ever be created via the T2Server::Connection factory class.

Instance Attribute Summary

Attributes inherited from HttpConnection

#uri

Instance Method Summary collapse

Methods inherited from HttpConnection

#DELETE, #GET, #OPTIONS, #POST, #PUT

Constructor Details

#initialize(uri, params = nil) ⇒ HttpsConnection

Open a https connection to the Taverna Server at the uri supplied.



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/t2-server/net/connection.rb', line 302

def initialize(uri, params = nil)
  super(uri, params)

  if OpenSSL::SSL::SSLContext::METHODS.include? @params[:ssl_version]
    @http.ssl_version = @params[:ssl_version]
  end

  # Peer verification
  if @params[:verify_peer]
    if @params[:ca_file]
      @http.ca_file = @params[:ca_file]
    end

    if @params[:ca_path]
      store = OpenSSL::X509::Store.new
      store.set_default_paths
      if @params[:ca_path].is_a? Array
        @params[:ca_path].each { |path| store.add_path(path) }
      else
        store.add_path(@params[:ca_path])
      end

      @http.cert_store = store
    end

    @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  else
    @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  # Client authentication
  if @params[:client_certificate]
    pem = File.read(@params[:client_certificate])
    @http.certificate = OpenSSL::X509::Certificate.new(pem)
    @http.private_key = OpenSSL::PKey::RSA.new(pem,
      @params[:client_password])
  end
end