Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to add signed timestamp to header #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eiapopeia
Copy link

To do this you have to give the timestamp-option to the wsse_signature!
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})
}

To do this you have to give the option to the *wsse_signature*!
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
Copy link

lilith commented Dec 17, 2015

This would be extremely useful!

@lilith
Copy link

lilith commented Dec 18, 2015

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
Copy link

lilith commented Dec 18, 2015

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

Copy link

@brent-clintel brent-clintel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When implementing this code, I came across two issues. I have suggested solutions in my comments based on what I did to get the code to work.

@@ -151,6 +193,12 @@ def body_digest
Base64.encode64(OpenSSL::Digest::SHA1.digest(body)).strip
end

def timestamp_digest
return nil unless timestamp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should tis be return nil unless self.timestamp. It seems that timestamp refers to the variable in the scope of the method due tot he assignment on the next line.

def timestamp_digest
return nil unless timestamp
timestamp = canonicalize(at_xpath(@document, "//Envelope/Header/Security/Timestamp"))
Base64.encode64(OpenSSL::Digest::SHA1.digest(timestamp)).strip

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if timestamp is nil, which it can be, an exception is raised. Should this line be ended with ... if timestamp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants