savonrb / akami

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

Timestamp must precede username token for many systems. #24

Closed aeberlin closed 9 months ago

aeberlin commented 9 years ago

We encountered a problem when trying to authenticate to a vendor's SOAP API where the timestamp must precede the username token in order for the request to be verified and authenticated. Otherwise, the follow error is thrown:

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:InvalidSecurity</faultcode>
      <faultstring>An error was discovered processing the &lt;wsse:Security&gt; header</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

I feel that reversing the order is unlikely to break other implementations, but I would like some feedback on whether this is a change we can/should make. Another, probably less intrusive, option would be to set up a pathway to pass a configuration option through savon client instantiation to enforce an order in the WSSE header that akami generates.

Thanks, cheers.

aeberlin commented 9 years ago

Related issue: https://github.com/savonrb/akami/issues/23

kelmerp commented 9 years ago

:+1:

aeberlin commented 9 years ago

Easy monkey patch for anybody that wants it:

require 'akami'

module AkamiWSSEHeaderFix
  def to_xml
    if signature? and signature.have_document?
      Gyoku.xml wsse_signature.merge!(hash)
    elsif username_token? && timestamp?
      Gyoku.xml wsu_timestamp.merge!(wsse_username_token) {
        |key, v1, v2| v1.merge!(v2) {
          |key, v1, v2| v1.merge!(v2)
        }
      }
    elsif username_token?
      Gyoku.xml wsse_username_token.merge!(hash)
    elsif timestamp?
      Gyoku.xml wsu_timestamp.merge!(hash)
    else
      ""
    end
  end
end

Akami::WSSE.send(:prepend, AkamiWSSEHeaderFix)
aeberlin commented 8 years ago

@rubiii Could we please get a merge, or feedback if it can't be merged? TY!

pcai commented 9 months ago

Hi - thanks for your patience. Doing some cleanup in this codebase and I'm going to default to merge contributions like this one, since it seems better than letting them stagnate.