Skip to content

Commit

Permalink
Merge pull request #264 from genuitytech/certificate_signing
Browse files Browse the repository at this point in the history
Changes for certificate signing stuff in Akami.
  • Loading branch information
rubiii committed Jun 6, 2012
2 parents 4b95cc8 + 25f1c8d commit 1746fe5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/savon/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def request(*args, &block)

response = SOAP::Request.new(config, http, soap).response
set_cookie response.http.headers

if wsse.verify_response
WSSE::VerifySignature.new(response.http.body).verify!
end

response
end

Expand Down
15 changes: 14 additions & 1 deletion lib/savon/soap/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ def response
# Configures a given +http+ from the +soap+ object.
def configure(http)
http.url = soap.endpoint
http.body = soap.to_xml

if soap.signature?
# First generate the document so that Signature can digest sections
soap.wsse.signature.document = soap.to_xml(true)

# Then re-generate the document so that Signature can sign the digest
soap.wsse.signature.document = soap.to_xml(true)

# The third time we generate the document, we should have a signature
http.body = soap.to_xml(true)
else
http.body = soap.to_xml
end

http.headers["Content-Type"] = ContentType[soap.version]
http.headers["Content-Length"] = soap.to_xml.bytesize.to_s
http
Expand Down
20 changes: 17 additions & 3 deletions lib/savon/soap/xml.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "builder"
require "gyoku"
require "rexml/document"
require "nori"

require "savon/soap"
Expand Down Expand Up @@ -120,6 +121,10 @@ def namespace_identifier
# Accessor for the <tt>Savon::WSSE</tt> object.
attr_accessor :wsse

def signature?
wsse.respond_to?(:signature?) && wsse.signature?
end

# Returns the SOAP request encoding. Defaults to "UTF-8".
def encoding
@encoding ||= "UTF-8"
Expand Down Expand Up @@ -149,14 +154,23 @@ def xml(directive_tag = :xml, attrs = {})
attr_writer :xml

# Returns the XML for a SOAP request.
def to_xml
def to_xml(clear_cache = false)
if clear_cache
@xml = nil
@header_for_xml = nil
end

@xml ||= tag(builder, :Envelope, complete_namespaces) do |xml|
tag(xml, :Header) { xml << header_for_xml } unless header_for_xml.empty?

# TODO: Maybe there should be some sort of plugin architecture where
# classes like WSSE::Signature can hook into this process.
body_attributes = (signature? ? wsse.signature.body_attributes : {})

if input.nil?
tag(xml, :Body)
tag(xml, :Body, body_attributes)
else
tag(xml, :Body) { xml.tag!(*add_namespace_to_input) { xml << body_to_xml } }
tag(xml, :Body, body_attributes) { xml.tag!(*add_namespace_to_input) { xml << body_to_xml } }
end
end
end
Expand Down

0 comments on commit 1746fe5

Please sign in to comment.