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

Problem verifying integrity of signature from simplesamlphp #11

Closed
brendon opened this issue Jun 11, 2011 · 2 comments
Closed

Problem verifying integrity of signature from simplesamlphp #11

brendon opened this issue Jun 11, 2011 · 2 comments

Comments

@brendon
Copy link
Contributor

brendon commented Jun 11, 2011

Hi there,

I'm getting mis-matched hashes when trying to verify a signature generated with a simplesamlphp server that we're trying to integrate with. We have no access to that server, so can't debug from that end. Essentially the hashes don't match up at the end of the code segment below. I've checked and the incoming XML specify's that their hash was generated with SHA1. I'm wondering if anyone could give me some pointers on how to troubleshoot this kind of problem? Obviously there must be a difference in the canonicalised markup on each side.

  REXML::XPath.each(sig_element, "//ds:Reference", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}) do | ref |

    uri                   = ref.attributes.get_attribute("URI").value
    hashed_element        = REXML::XPath.first(self, "//[@ID='#{uri[1,uri.size]}']")
    canoner               = XML::Util::XmlCanonicalizer.new(false, true)
    canon_hashed_element  = canoner.canonicalize(hashed_element)
    hash                  = Base64.encode64(Digest::SHA1.digest(canon_hashed_element)).chomp
    digest_value          = REXML::XPath.first(ref, "//ds:DigestValue", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}).text

    valid_flag            = hash == digest_value

    return valid_flag if !valid_flag
  end
@brendon
Copy link
Contributor Author

brendon commented Jun 13, 2011

It turns out that the cause of the incorrect hashing is a bug in the xmlcanonicalizer gem that you rely on.

A patch has already been submitted that fixes the problem, but the maintainer of the gem doesn't seem to have applied it. I have tested the patch and it does indeed work:

andrewferk/xmlcanonicalizer#1

I'll leave this open and monitor the progress with getting the patch accepted.

@brendon
Copy link
Contributor Author

brendon commented Jun 16, 2011

Will open a new ticket regarding shifting the dependency on what seems like an abandoned gem.

@brendon brendon closed this as completed Jun 16, 2011
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

No branches or pull requests

1 participant