Created
August 10, 2012 11:52
-
-
Save phaus/3313756 to your computer and use it in GitHub Desktop.
Patching SAVON to work with pk12 Certs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here is the patching to make the savon gem (https://github.com/rubiii/savon) work with pk12 certs | |
# if i found the time, i will create a patch and make a pull request :-) | |
module HTTPI | |
module Auth | |
# = HTTPI::Auth::SSL | |
# | |
# Provides SSL client authentication. | |
class SSL | |
@pkcs12 | |
# Returns whether SSL configuration is present. | |
def present? | |
(verify_mode == :none) || (cert && cert_key) | |
rescue TypeError, Errno::ENOENT | |
false | |
end | |
def plcs_file(certFile, certPass) | |
@pkcs12 = OpenSSL::PKCS12.new(File.read(certFile), certPass) | |
ca_cert_file = nil | |
end | |
# Returns an <tt>OpenSSL::X509::Certificate</tt> for the +cert_file+. | |
def cert | |
@cert ||= (@pkcs12.certificate if @pkcs12) | |
end | |
# Returns the cert type to validate SSL certificates PEM|DER. | |
def cert_type | |
@cert_type ||= :pem | |
end | |
# Returns an <tt>OpenSSL::PKey::RSA</tt> for the +cert_key_file+. | |
def cert_key | |
@cert_key ||= (@pkcs12.key if @pkcs12) | |
end | |
end | |
end | |
end | |
# And this is how you can use it: | |
HTTPI.log = false | |
uriString = "https://some-soap-uri.example.com/service" | |
certFile = "certfile.p12" | |
certPass = "pk12 password" | |
username = "some-auth-username" | |
password = "some-auth-password" | |
client = Savon.client(uriString+"?wsdl") | |
client.http.auth.ssl.plcs_file(certFile, certPass) | |
client.http.auth.ssl.verify_mode = :none | |
client.http.auth.basic(username, password) | |
client.http.read_timeout = 90 | |
client.http.open_timeout = 90 | |
client.http.headers = { "Accept-Encoding" => "gzip, deflate", "Connection" => "Keep-Alive" } | |
client.wsdl.document = uriString+"?wsdl" | |
p client.wsdl.soap_actions | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
4-space indentation? camel-case vars? Y?