Ruby XMLRPC传递密钥对

时间:2013-03-07 23:44:48

标签: ruby xml-rpc

我必须与使用密钥身份验证的XML-RPC服务器进行交互。在接受请求之前,服务器验证密钥对(ssl私钥和ssl证书)。我知道这很糟糕,但这是我必须要合作的。

我的问题是:是否有一种简单的方法可以在此请求中传递密钥和证书?我在Ruby中使用xmlrpc / Client,但文档似乎并未表明可以这样做。我目前的代码如下:

错误:

  

/usr/lib/ruby/1.8/net/http.rb:586:in connect': sslv3 alert handshake failure >(OpenSSL::SSL::SSLError) from /usr/lib/ruby/1.8/net/http.rb:586:in connect'          来自/usr/lib/ruby/1.8/net/http.rb:553:in do_start' from /usr/lib/ruby/1.8/net/http.rb:542:in开始'          来自/usr/lib/ruby/1.8/net/http.rb:1035:in request' from /usr/lib/ruby/1.8/net/http.rb:992:in post2'          来自/usr/lib/ruby/1.8/xmlrpc/client.rb:535:in do_rpc' from /usr/lib/ruby/1.8/xmlrpc/client.rb:420:in call2'          来自/usr/lib/ruby/1.8/xmlrpc/client.rb:410:in`call'

班级档案:

class RpcRequest

  require "xmlrpc/client"

  # Automatically create the connection
  def initialize(connection_params)
    @connection = XMLRPC::Client.new(connection_params['host'], connection_params['path'], connection_params['port'], connection_params['proxy_host'], connection_params['proxy_port'], connection_params['user'], connection_params['password'], connection_params['use_ssl'], connection_params['timeout'])
  end

  # Make the xml rpc call
    def make_call(method, request_params)
      @response = @connection.call(method, request_params)
    end

end

驱动程序文件:

require 'RpcRequest.rb'
require 'config.rb'
require 'openssl'

# Define parameters for the connection
connect_params = Hash.new
connect_params['host'] = $host
connect_params['path'] = $path
connect_params['port'] = $port
connect_params['proxy_host'] = $proxy_host
connect_params['proxy_port'] = $proxy_port
connect_params['user'] = $user
connect_params['password'] = $password
connect_params['use_ssl'] = $use_ssl
connect_params['timeout'] = $timeout

# Define parameters for the request
request_params = Hash.new
request_params['fname'] = 'Robert'
request_params['lname'] = 'Jones'

request = RpcRequest.new(connect_params)

puts request.inspect

request.make_call('test.hello', request_params)

1 个答案:

答案 0 :(得分:0)

您可以与客户端实例的.http属性进行交互。