Let me put you into the context of a task. We're working in iOS/Mac environment using pure C/C++/Objective C code, without any additional libraries. Recently we've been tasked with imitating WCF ADFS web requests.
Our task is simple - use two-step process to obtain token for Web services usage. Two-step is required for federation. Our first step is obtaining a token from a usernamemixed endpoint on one adfs 2.0 server, and the second is taking that token to a issuedtokenmixedsymmetricbasic256 endpoint on the second adfs 2.0 server to retrieve the converted token. We snooped on SSL traffic that comes from WCF working sample and right now we're trying to imitate it, but we have several probably simple questions.
They are as follows:
1. First request is simple usernamemixed call, without any signatures, hashes, etc. We set all fields like in WCF request and receive a correct reply.
In reply we receive such a blob:
<EncryptedAssertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
</e:EncryptionMethod>
<KeyInfo>
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=ADFS Encryption - test.contoso2.com</ds:X509IssuerName>
<ds:X509SerialNumber>65021098975359647747588300292680011971</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</KeyInfo>
<e:CipherData>
<e:CipherValue> .... </e:CipherValue>
</e:CipherData>
</e:EncryptedKey>
</KeyInfo>
<xenc:CipherData>
<xenc:CipherValue> ....
What's this blob? Is it SAMLv2 XML encrypted with AES256 key? Can we decrypt this blob? And more important - should we do this? If we are to decrypt what key should we use?
2. Another section
<trust:RequestedProofToken>
<trust:BinarySecret>4807Tm7b5pV+yuDJrE/VxlQMF5qEZ9ofXiaW192eVWM=</trust:BinarySecret>
</trust:RequestedProofToken>
What's this? We've checked quite a number of specs including Microsoft ones and this is supposed to be a session key. But for what?
3. <trust:RequestedAttachedReference>
<SecurityTokenReference b:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:b="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.sd">
<KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID">_c3161df2-c407-467f-a38a-a9e0f4c40329</KeyIdentifier>
</SecurityTokenReference>
</trust:RequestedAttachedReference>
What is _c3161df2-c407-467f-a38a-a9e0f4c40329? Is it something inside SAML XML? This ID is only mentioned in trust:RequestedAttachedReference/RequestedUnattachedReference, never in other places
Now we need to create second request (symmetricbasic256) . Thanks to Microsoft lightweight web protocol spec we know that we need to put Timestamp into it and sign it.
Here's the blob from WCF request
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
<Reference URI="#_0">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>PrL4HWUJyslYSkLlnfVywRtGkY8=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>r/77++h17Gls9C048czu4y0A4fs=</SignatureValue>
<KeyInfo>
<o:SecurityTokenReference b:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0" xmlns:b="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
<o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID">_c3161df2-c407-467f-a38a-a9e0f4c40329</o:KeyIdentifier>
</o:SecurityTokenReference>
</KeyInfo>
</Signature>
We know how to calculate digests and how to canonicalize XML but we don't understand what should be the key for HMAC-SHA1 function. We see KeyIndentifier but where is this key?