Soap4r, ssl and certificates problem

Hi

I'm trying to consume a SOAP service that is on an ssl endpoint. The
security is public/private key.

What I have so far:

I have the wsdl for the service, together with the CA certificate and a
.pfx file which I believe contains everything I need. I have client ruby
classes which have been generated using the wsdl2ruby command line tool.
I have the soap4r gem 1.5.8 installed.

This is my code (forgive the clunkyness - it's for testing :wink:

···

------------------------------------------------
require 'rubygems'
gem 'soap4r'
require 'defaultDriver.rb'

class WS

  def initialize
    @context = CommonServiceContext.new(<various setup variables>)
    @param = SearchCompanyByEHId.new('2272357', @context)
    @driver = CompanySearchServiceV5.new
    @driver.loadproperty('ssl.properties')
  end

  def do
    begin
      @driver.searchCompanyByEHId(@param)
    rescue Exception => e
      return e
    end
  end
end
------------------------------------------------

This is what my 'ssl.properties' file looks like:

------------------------------------------------
protocol.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER
protocol.http.ssl_config.ca_file = ca.cer
protocol.http.ssl_config.client_cert = usercert.pem
protocol.http.ssl_config.client_key = userkey.pem
protocol.http.ssl_config.ciphers = ALL
protocol.http.ssl_config.verify_depth = 1
------------------------------------------------

I tried using openssl to extract my key and certificate from the pfx
file, using these commands:

openssl pkcs12 -nocerts -in my_pfx.pfx -out userkey.key
openssl pkcs12 -clcerts -nokeys -in my_pfx.pfx -out usercert.cert

I don't get any errors so I assume that it's all ok at this point.

When I run my class, I get the following error:

OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key:: nested asn1
error
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:134:in
`initialize'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:134:in
`new'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:134:in
`key_from_file'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:90:in
`set_ssl_config'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:140:in
`each'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:139:in
`each'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:81:in
`set_ssl_config'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/httpconfigloader.rb:36:in
`set_options'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:115:in
`call'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:115:in
`[]='
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:114:in
`each'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:114:in
`[]='
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:84:in
`load'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/rpc/driver.rb:232:in
`each_with_index'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:73:in
`each'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:73:in
`each_with_index'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:73:in
`load'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:309:in
`loadpropertyfile'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:308:in
`open'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:308:in
`loadpropertyfile'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/property.rb:95:in
`loadproperty'
  from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.8/lib/soap/rpc/driver.rb:120:in
`loadproperty'
  from ./ws.rb:21:in `initialize'
  from (irb):8:in `new'

Has anyone managed to get this kind of thing working. I'm struggling to
find any detailed examples or explanations (beyond the usual
basic_http_auth stuff) that have helped me.

Any help or pointers would be greatly appreciated.
Thanks.
--
Posted via http://www.ruby-forum.com/.

Further to this, when I use the following openssl commands to extract
the certificate and key I get a different error:

<SOAP::FaultError: Internal Error>

Inspecting that object gives me the following:

--- !ruby/exception:SOAP::FaultError
message: Internal Error
cause:
detail: ""
faultactor:
faultcode: &id003 !ruby/object:SOAP::SOAPElement
  array: []

  data: []

  definedtype:
  elename: !ruby/object:XSD::QName
    name: faultcode
    namespace:
    source:
  encodingstyle: http://xml.apache.org/xml-soap/literalxml
  extraattr: {}

  id:
  parent: &id001 !ruby/object:SOAP::SOAPFault
    array:
    - faultcode
    - faultstring
    data:
    - *id003
    - &id004 !ruby/object:SOAP::SOAPElement
      array: []

      data: []

      definedtype:
      elename: !ruby/object:XSD::QName
        name: faultstring
        namespace:
        source:
      encodingstyle: http://xml.apache.org/xml-soap/literalxml
      extraattr: {}

      id:
      parent: *id001
      position:
      precedents: []

      qualified:
      root: false
      text: Internal Error
      type:
    definedtype:
    elename: !ruby/object:XSD::QName
      name: fault
      namespace: http://schemas.xmlsoap.org/soap/envelope/
      source:
    encodingstyle: http://schemas.xmlsoap.org/soap/encoding/
    extraattr: {}

    id:
    parent: &id002 !ruby/object:SOAP::SOAPBody
      array:
      - fault
      data:
      - *id001
      definedtype:
      elename: !ruby/object:XSD::QName
        name: Body
        namespace: http://schemas.xmlsoap.org/soap/envelope/
        source:
      encodingstyle:
      extraattr: {}

      id:
      is_fault: true
      parent: !ruby/object:SOAP::SOAPEnvelope
        body: *id002
        definedtype:
        elename: !ruby/object:XSD::QName
          name: Envelope
          namespace: http://schemas.xmlsoap.org/soap/envelope/
          source:
        encodingstyle:
        external_content: {}

        extraattr: {}

        header:
        id:
        parent:
        position:
        precedents: []

        qualified:
        root: false
        type:
      position:
      precedents: []

      qualified:
      root: false
      type: !ruby/object:XSD::QName
        name:
        namespace:
        source:
    position:
    precedents: []

    qualified:
    root: false
    type: !ruby/object:XSD::QName
      name: Fault
      namespace: http://schemas.xmlsoap.org/soap/envelope/
      source:
  position:
  precedents: []

  qualified:
  root: false
  text: General
  type:
faultstring: *id004
original_backtrace:

Confused...

···

--
Posted via http://www.ruby-forum.com/.

bump.

···

--
Posted via http://www.ruby-forum.com/.