savonrb / akami

Building Web Service Security
MIT License
36 stars 61 forks source link

Added ability to add signed timestamp to header #25

Open eiapopeia opened 8 years ago

eiapopeia commented 8 years ago

To do this you have to give the timestamp-option to the _wssesignature! Like so:

Savon.client({
  …
  wsse_signature:
    Akami::WSSE::Signature.new(
      Akami::WSSE::Certs.new(…),
      timestamp: true)
}

It is also possible to give created_at and/or expires_at like this

Savon.client({
  …
  wsse_signature:
    Akami::WSSE::Signature.new(
      Akami::WSSE::Certs.new(…),
      {timestamp: true,
      created_at: Time.now-10,
      expires_at: Time.now + 600})
}
lilith commented 8 years ago

This would be extremely useful!

lilith commented 8 years ago

Savon::Builder#build_document needs to create the headers 3 times instead of 2. I.e, replace "2.do" with "3.do" I do not yet know why. For some reason Signature#document needs to be mutated that many times.

lilith commented 8 years ago

One can call build_document an extra time before initiating the request, or add this to lib/savon/builder.rb:

def get_xml
  tag(builder, :Envelope, namespaces_with_globals) do |xml|
    tag(xml, :Header, header_attributes) { xml << header.to_s } unless header.empty?
    if @globals[:no_message_tag]
      tag(xml, :Body, body_attributes) { xml << message.to_s }
    else
      tag(xml, :Body, body_attributes) { xml.tag!(*namespaced_message_tag) { xml << message.to_s } }
    end
  end
end
def build_document
  return get_xml unless @signature

  # if we have a signature sign the document
  if @signature
    @signature.document = get_xml
    2.times do
      @header = nil
      @signature.document = get_xml
    end
    return @signature.document
  end
end