# Soap4r, ssl and certificates problem

**URL:** <https://www.ruby-forum.com/t/soap4r-ssl-and-certificates-problem/172258>\
**Category:** Ruby\
**Created:** [July 17, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/soap4r-ssl-and-certificates-problem/172258 "2009-07-17T18:00:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@soop](https://www.ruby-forum.com/u/soop)\
**Post date:** [July 17, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/soap4r-ssl-and-certificates-problem/172258/1 "2009-07-17T18:00:30Z")

</div>

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 😉

* * *

require ‘rubygems’  
gem ‘soap4r’  
require ‘defaultDriver.rb’

class WS

def initialize  
@context = CommonServiceContext.new()  
@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.

---

<div class="post-metadata">

**Author:** ![soop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@soop](https://www.ruby-forum.com/u/soop)\
**Post date:** [July 17, 2009, 6:14pm UTC](https://www.ruby-forum.com/t/soap4r-ssl-and-certificates-problem/172258/2 "2009-07-17T18:14:28Z")

</div>

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](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…

---

<div class="post-metadata">

**Author:** ![soop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@soop](https://www.ruby-forum.com/u/soop)\
**Post date:** [July 20, 2009, 11:30am UTC](https://www.ruby-forum.com/t/soap4r-ssl-and-certificates-problem/172258/3 "2009-07-20T11:30:30Z")

</div>

bump.
