开发者

SAML Response for Google apps

开发者 https://www.devze.com 2023-03-27 19:26 出处:网络
I am trying to get Google Apps SAML working, I am getting the: Google Apps - This account cannot be accessed because we could not parse the login request.

I am trying to get Google Apps SAML working, I am getting the: Google Apps - This account cannot be accessed because we could not parse the login request.

Here is my response verbatim:


<?xml version="1.0"?>

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="pfx9c11a3a9-13dc-ff78-7d18-12f795fab19d" Version="2.0" IssueInstant="2011-08-11T05:24:35Z" Destination="https://www.google.com/a/sparxlabs.com/acs" InResponseTo="idnffilcgaeeonionahcpciplkhhhkmlfedkpipl">

<saml:Issuer>http://saml.sparxlabs.com/</saml:Issuer>

<ds:Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

<ds:SignedInfo>

<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>

<ds:Reference URI="">

<ds:Transforms>

<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>

<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

</ds:Transforms>

<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/开发者_StackOverflow中文版xmldsig#sha1"/>

<ds:DigestValue>Y2E3ZWIyZGEwODFjYjdhZmJjMTZlYmI1NjA4N2IxYzYwMTM5YmEyMA==</ds:DigestValue>

</ds:Reference>

</ds:SignedInfo>

<ds:SignatureValue>Eno0HWCgNgxeUhCP0khdEGuLDP3etgzAoKBiK84ENs1ealpgBEOhFTDQQC8qODbAZVxTFYjQLTcW5A7OJ2n02S5tLmg57TeL4+VWyzhwaV9KQ9e1ZU7ZMhPV5aNL4Qm8EIvDyRbPx7mWW70wK1fO+IlPsmxZraL982neOJ8vucc=</ds:SignatureValue>

<ds:KeyInfo>

<ds:X509Data>

<ds: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lFBRGdZRUFzZkYwS0h2T0h6emFoRWd4Cit1NmJJUTRldkxYaXB4VnVYNlZ2RnYxd1BSTmtIRWZEWk9HdmJZc1p1ak5VUVFGdXFzRGR2M3lHelJLQXozRVAKd1RoY29pdEN1cWQrT2dlNGdTNkhpaHBCSzU3cmFaMlpad0NxWXpyQldMMjhaZnFhQW5zNy9KNkY3TEZIeEMvcQpnK25HSldINlVycGpZTGJqajJjMFN0VGVIVTg9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K</ds:X509Certificate>

</ds:X509Data>

</ds:KeyInfo>

</ds:Signature>

<samlp:Status>

<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>

</samlp:Status>

<saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" ID="pfx9c11a3a9-13dc-ff78-7d18-12f795fab19d" Version="2.0" IssueInstant="2011-08-11T05:24:35Z">

<saml:Issuer>http://saml.sparxlabs.com</saml:Issuer>

<ds:Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

<ds:SignedInfo>

<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>

<ds:Reference URI="">

<ds:Transforms>

<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>

<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

</ds:Transforms>

<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>

<ds:DigestValue>ZWRhZGEzYjE4NmZjNWU2ZWE0NDI1NjBkZTFkYzhmN2YzY2QwZGZiMA==</ds:DigestValue>

</ds:Reference>

</ds:SignedInfo>

<ds:SignatureValue>QueL4xlp3NOUJou7mIKERgtPRSJboeht9gFfDcOuhmYvh6uyDsk6UR2GLLb0smkuzuy7cgz0MwzjZ4QdhCyIozO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VkJBb1RHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpJSUpBS1hnS2NPLwp0RktuTUF3R0ExVWRFd1FGTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFBRGdZRUFzZkYwS0h2T0h6emFoRWd4Cit1NmJJUTRldkxYaXB4VnVYNlZ2RnYxd1BSTmtIRWZEWk9HdmJZc1p1ak5VUVFGdXFzRGR2M3lHelJLQXozRVAKd1RoY29pdEN1cWQrT2dlNGdTNkhpaHBCSzU3cmFaMlpad0NxWXpyQldMMjhaZnFhQW5zNy9KNkY3TEZIeEMvcQpnK25HSldINlVycGpZTGJqajJjMFN0VGVIVTg9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K</ds:X509Certificate>

</ds:X509Data>

</ds:KeyInfo>

</ds:Signature>

<saml:Subject>

<saml:NameID SPNameQualifier="google.com" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:email">admin</saml:NameID>

<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">

<saml:SubjectConfirmationData NotOnOrAfter="2011-08-11T06:24:35Z" Recipient="https://www.google.com/a/sparxlabs.com/acs" InResponseTo="idnffilcgaeeonionahcpciplkhhhkmlfedkpipl"/>

</saml:SubjectConfirmation>

</saml:Subject>

<saml:Conditions NotBefore="2011-08-11T05:24:35Z" NotOnOrAfter="2011-08-11T06:24:35Z">

<saml:AudienceRestriction>

<saml:Audience>google.com</saml:Audience>

</saml:AudienceRestriction>

</saml:Conditions>

<saml:AuthnStatement AuthnInstant="2011-08-11T05:24:35Z" SessionNotOnOrAfter="2011-08-11T06:24:35Z" SessionIndex="_e409f914997c09cfb1a4dbe461a660209eba5d94ec">

<saml:AuthnContext>

<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>

</saml:AuthnContext>

</saml:AuthnStatement>

</saml:Assertion>

</samlp:Response>

Some more info that is important:

1.. The X509Certificate I am getting as:


      cert = OpenSSL::PKey::RSA.new(File.read("dsacert.pem"))
      [cert.to_s].pack("m").gsub(/\n/, "") #Base64 encode

2.. The digest value:


 canonical = canonical_form(element)
 sha1 = Digest::SHA1.hexdigest(canonical)
 [sha1].pack("m").gsub(/\n/, "") #Base64 encode

3.. Finally the signature (digest_value I calculated above):


     p key = OpenSSL::PKey::RSA.new(File.read("rsaprivkey.pem"))
     sig = pkey.sign(OpenSSL::Digest::SHA1.new, digest_value)
     [sig].pack("m").gsub(/\n/, "") #Base64 encode

If I missed anything let me know in the comments I'll update.


Just taking a quick glance I do not believe Google supports signatures on both the Response & Assertion. I would simplify the setup by removing the signature from the Assertion and leave the Response signed as a first step. You may also want to double check the Audience value and see whether "google.com" or "www.google.com/a/sparxlabs.com" is the expected value.


I see some points that may be a problem:

  1. The two Reference ID in your signatures are empty. There is an ambiguity as implicitely this means that both signature cover the complete XML document, which is wrong.The SAML specification say that you should explicitely point to the ID of the signed element.
  2. The code you post seems to suggest that this a custom-made response. Generating a enveloped XML Digital signature is not that simple as it needs to be embedded at the exact moment you sign the document.
  3. You only apply the canonization. You should also apply the two transforms specified in the signature.
  4. As stated there, the Audience element should point to the EntityID of your ACS, like Ian suggested. It's also possible that "google.com" is accepted, but this is a violation of the SAML 2.0 specs.
  5. Your NameID attribute seems strange, it should be an email-address. The previous link gives an example of a valid NameID element.

If you want to generate a custom-made response, you should start from an unsigned template, and then apply the XML DSIG with the ad-hoc library, like XML::Sig. It should be sufficient to sign the Assertion or the Response.

Hope this helps..


all things sk_ pointed out are right, but also :

  • NEVER include the xml declaration in the samlResponse message
  • Your digest value is wrong, it should be the base64 of the BINARY digest, not the HEX form
  • I don't know ruby, but the signature is the same as the digest, b64(BINARY-RSA-SHA1(elem))
  • It's the canonical form of the whole you have to sign, not just the digest
  • don't forget to base64 encode the whole samlResponse before sending it over a post-binding
  • and don't touch a BIT from the relaystate param, just post it as is

Also you may verify yourself the xmldsig signature the (cool-and-life-saver) xmlsec1 tool

And never forget: Xml Sucks, c14n/xmldsig is MORONIC !

GooD Luck !

0

精彩评论

暂无评论...
验证码 换一张
取 消