2015-09-30 4 views
2

Pour un client, j'essaie d'obtenir un jeton de MicrosoftOnline (office 365) en utilisant ADFS OnPrem. En bref:WIF: "Le token XML générique de signature ... n'a pas de clé"

  1. Demander un jeton de OnPrem STS (ADFS)
  2. Envoyer le jeton reçu à la STS fédérée (MicrosoftOnline)

Maintenant, j'ai le code de travail qui envoie des messages de savon hardcoded à ADFS & MicrosoftOnline. J'essaie de refactoriser ce code pour utiliser WIF, mais j'ai du mal à faire marcher l'étape 2. Je peux gérer l'étape 1 bien, mais quand j'essaie d'appeler MicrosoftOnline j'obtiens l'erreur suivante:

An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

Additional information: The signing token Generic XML token:

validFrom: 09/30/2015 13:25:40

validTo: 09/30/2015 14:25:40

InternalTokenReference: SamlAssertionKeyIdentifierClause(AssertionId = '_622096af-9cb5-4b19-b69d-5d60639c16e3')

ExternalTokenReference: SamlAssertionKeyIdentifierClause(AssertionId = '_622096af-9cb5-4b19-b69d-5d60639c16e3')

Token Element: (Assertion, urn:oasis:names:tc:SAML:1.0:assertion)

has no keys. The security token is used in a context that requires it to perform cryptographic operations, but the token contains no cryptographic keys. Either the token type does not support cryptographic operations, or the particular token instance does not contain cryptographic keys. Check your configuration to ensure that cryptographically disabled token types (for example, UserNameSecurityToken) are not specified in a context that requires cryptographic operations (for example, an endorsing supporting token).

Voici le code que j'ai jusqu'à présent. L'erreur est renvoyée lors de l'appel au channel.issue.

public static SecurityToken GetRSTSToken(SecurityToken idpToken) 
{ 
    var binding = new IssuedTokenWSTrustBinding2(); 
    binding.SecurityMode = SecurityMode.TransportWithMessageCredential; 

    var factory = new WSTrustChannelFactory(
     binding, 
     "https://login.microsoftonline.com/RST2.srf"); 
    factory.TrustVersion = TrustVersion.WSTrust13; 
    factory.Credentials.SupportInteractive = false; 
    factory.Credentials.UseIdentityConfiguration = true; 

    var rst = new RequestSecurityToken 
    { 
     RequestType = RequestTypes.Issue, 
     AppliesTo = new EndpointReference("urn:crmemea:dynamics.com"), 
    }; 

    var channel = factory.CreateChannelWithIssuedToken(idpToken); 
    SecurityToken returnValue = channel.Issue(rst); 
    return returnValue; 
} 

L'appel à GetRSTSToken est précédé par un appel à la méthode GetToken. La sortie de GetToken est transmise à GetRSTSToken. J'ai utilisé Fiddler pour vérifier les messages de savon et ils sont presque identiques aux messages de savon que j'envoie dans mon code de travail actuel. La seule chose qui est différente sont les champs que vous attendez (ID, horodatages, etc).

public static SecurityToken GetToken(string username, string password) 
{ 
    // Windows authentication over transport security 
    var factory = new WSTrustChannelFactory(
     new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), 
     "https://sts.windesheim.nl/adfs/services/trust/13/usernamemixed"); 
    factory.TrustVersion = TrustVersion.WSTrust13; 
    factory.Credentials.UserName.UserName = username; 
    factory.Credentials.UserName.Password = password; 
    factory.Credentials.UseIdentityConfiguration = true; 

    var rst = new RequestSecurityToken 
    { 
     RequestType = RequestTypes.Issue, 
     AppliesTo = new EndpointReference("urn:federation:MicrosoftOnline"), 
     KeyType = KeyTypes.Bearer 
    }; 

    var channel = factory.CreateChannel(); 
    SecurityToken returnValue = channel.Issue(rst); 
    return returnValue; 
} 

REMARQUE: UserNameWSTrustBinding et IssuedTokenWSTrustBinding sont de Thinktecture.IdentityModel (https://github.com/IdentityModel/Thinktecture.IdentityModel.45)

Pour référence, voici les messages soap -working-:

  1. To OnPrem STS

Demande de savon

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</a:Action> 
     <a:MessageID>urn:uuid:755c37dd-eee4-4e7e-a9e0-be3c6289b46a</a:MessageID> 
     <a:ReplyTo> 
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 
     </a:ReplyTo> 
     <a:To s:mustUnderstand="1">[sts_url]</a:To> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="_0"> 
       <u:Created>2015-06-10T08:21:44.804Z</u:Created> 
       <u:Expires>2015-06-10T08:26:44.804Z</u:Expires> 
      </u:Timestamp> 
      <o:UsernameToken u:Id="uuid-3e6d680b-4cb1-4c38-aff8-93c8fa8bd0c6-1"> 
       <o:Username>[username]</o:Username> 
       <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">[password]</o:Password> 
      </o:UsernameToken> 
     </o:Security> 
    </s:Header> 
    <s:Body> 
     <trust:RequestSecurityToken xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> 
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> 
       <a:EndpointReference> 
        <a:Address>urn:federation:MicrosoftOnline</a:Address> 
       </a:EndpointReference> 
      </wsp:AppliesTo> 
      <trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType> 
      <trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType> 
     </trust:RequestSecurityToken> 
    </s:Body> 
</s:Envelope> 

Réponse de savon

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTRC/IssueFinal</a:Action> 
     <a:RelatesTo>urn:uuid:755c37dd-eee4-4e7e-a9e0-be3c6289b46a</a:RelatesTo> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="_0"> 
       <u:Created>2015-06-10T08:21:45.097Z</u:Created> 
       <u:Expires>2015-06-10T08:26:45.097Z</u:Expires> 
      </u:Timestamp> 
     </o:Security> 
    </s:Header> 
    <s:Body> 
     <trust:RequestSecurityTokenResponseCollection xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> 
      <trust:RequestSecurityTokenResponse> 
       <trust:Lifetime> 
        <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-06-10T08:21:45.082Z</wsu:Created> 
        <wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-06-10T09:21:45.082Z</wsu:Expires> 
       </trust:Lifetime> 
       <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> 
        <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
         <wsa:Address>urn:federation:MicrosoftOnline</wsa:Address> 
        </wsa:EndpointReference> 
       </wsp:AppliesTo> 
       <trust:RequestedSecurityToken> 
        <saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_68133973-ed12-49d7-9f43-421bcfe43162" Issuer="http://windesheim.nl/adfs/services/trust/" IssueInstant="2015-06-10T08:21:45.097Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"> 
         <saml:Conditions NotBefore="2015-06-10T08:21:45.082Z" NotOnOrAfter="2015-06-10T09:21:45.082Z"> 
          <saml:AudienceRestrictionCondition> 
           <saml:Audience>urn:federation:MicrosoftOnline</saml:Audience> 
          </saml:AudienceRestrictionCondition> 
         </saml:Conditions> 
         <saml:AttributeStatement> 
          <saml:Subject> 
           <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">[..]saml:NameIdentifier> 
           <saml:SubjectConfirmation> 
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> 
           </saml:SubjectConfirmation> 
          </saml:Subject> 
          <saml:Attribute AttributeName="UPN" AttributeNamespace="http://schemas.xmlsoap.org/claims"> 
           <saml:AttributeValue>[username]</saml:AttributeValue> 
          </saml:Attribute> 
          <saml:Attribute AttributeName="ImmutableID" AttributeNamespace="http://schemas.microsoft.com/LiveID/Federation/2008/05"> 
           <saml:AttributeValue>[..]saml:AttributeValue> 
          </saml:Attribute> 
         </saml:AttributeStatement> 
         <saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2015-06-10T08:21:45.082Z"> 
          <saml:Subject> 
           <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">[..]</saml:NameIdentifier> 
           <saml:SubjectConfirmation> 
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> 
           </saml:SubjectConfirmation> 
          </saml:Subject> 
         </saml:AuthenticationStatement> 
         <ds:Signature xmlns:ds="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="#_68133973-ed12-49d7-9f43-421bcfe43162"> 
            <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[..]</ds:DigestValue> 
           </ds:Reference> 
          </ds:SignedInfo> 
          <ds:SignatureValue>[..]</ds:SignatureValue> 
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 
           <X509Data>[..]</X509Certificate> 
           </X509Data> 
          </KeyInfo> 
         </ds:Signature> 
        </saml:Assertion> 
       </trust:RequestedSecurityToken> 
       <trust:RequestedAttachedReference> 
        <o:SecurityTokenReference k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="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.0#SAMLAssertionID">[some_guid]</o:KeyIdentifier> 
        </o:SecurityTokenReference> 
       </trust:RequestedAttachedReference> 
       <trust:RequestedUnattachedReference> 
        <o:SecurityTokenReference k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="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.0#SAMLAssertionID[some_guid]</o:KeyIdentifier> 
        </o:SecurityTokenReference> 
       </trust:RequestedUnattachedReference> 
       <trust:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</trust:TokenType> 
       <trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType> 
       <trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType> 
      </trust:RequestSecurityTokenResponse> 
     </trust:RequestSecurityTokenResponseCollection> 
    </s:Body> 
</s:Envelope> 
  1. à Federated STS

Savon Demande

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action> 
     <a:MessageID>urn:uuid:0c1704ed-2ef3-4718-87fa-97734518b13f</a:MessageID> 
     <a:ReplyTo> 
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 
     </a:ReplyTo> 
     <a:To s:mustUnderstand="1">https://login.microsoftonline.com/RST2.srf</a:To> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="_0"> 
       <u:Created>2015-06-10T08:21:45.418Z</u:Created> 
       <u:Expires>2015-06-10T08:26:45.418Z</u:Expires> 
      </u:Timestamp> 
           <saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_68133973-ed12-49d7-9f43-421bcfe43162" Issuer="http://windesheim.nl/adfs/services/trust/" IssueInstant="2015-06-10T08:21:45.097Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"> 
         <saml:Conditions NotBefore="2015-06-10T08:21:45.082Z" NotOnOrAfter="2015-06-10T09:21:45.082Z"> 
          <saml:AudienceRestrictionCondition> 
           <saml:Audience>urn:federation:MicrosoftOnline</saml:Audience> 
          </saml:AudienceRestrictionCondition> 
         </saml:Conditions> 
         <saml:AttributeStatement> 
          <saml:Subject> 
           <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">[..]saml:NameIdentifier> 
           <saml:SubjectConfirmation> 
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> 
           </saml:SubjectConfirmation> 
          </saml:Subject> 
          <saml:Attribute AttributeName="UPN" AttributeNamespace="http://schemas.xmlsoap.org/claims"> 
           <saml:AttributeValue>[username]</saml:AttributeValue> 
          </saml:Attribute> 
          <saml:Attribute AttributeName="ImmutableID" AttributeNamespace="http://schemas.microsoft.com/LiveID/Federation/2008/05"> 
           <saml:AttributeValue>[..]saml:AttributeValue> 
          </saml:Attribute> 
         </saml:AttributeStatement> 
         <saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2015-06-10T08:21:45.082Z"> 
          <saml:Subject> 
           <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">[..]</saml:NameIdentifier> 
           <saml:SubjectConfirmation> 
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> 
           </saml:SubjectConfirmation> 
          </saml:Subject> 
         </saml:AuthenticationStatement> 
         <ds:Signature xmlns:ds="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="#_68133973-ed12-49d7-9f43-421bcfe43162"> 
            <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[..]</ds:DigestValue> 
           </ds:Reference> 
          </ds:SignedInfo> 
          <ds:SignatureValue>[..]</ds:SignatureValue> 
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 
           <X509Data>[..]</X509Certificate> 
           </X509Data> 
          </KeyInfo> 
         </ds:Signature> 
        </saml:Assertion> 
     </o:Security> 
    </s:Header> 
    <s:Body> 
     <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust"> 
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> 
       <a:EndpointReference> 
        <a:Address>urn:crmemea:dynamics.com</a:Address> 
       </a:EndpointReference> 
      </wsp:AppliesTo> 
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType> 
     </t:RequestSecurityToken> 
    </s:Body> 
</s:Envelope> 

Répondre

0

Pour les futurs Googlers, pas exactement l'OP :

J'avais créé un jeton de support SAML et essayait de l'échanger contre un JWT avec ADFS. Nécessaire pour définir la propriété KeyType pour éviter cette erreur:

var binding = new IssuedTokenWSTrustBinding(); 
binding.SecurityMode = SecurityMode.TransportWithMessageCredential; 
binding.KeyType = SecurityKeyType.BearerKey; 


// set up the ws-trust channel factory 
var factory = new WSTrustChannelFactory(binding, new EndpointAddress(options.AdfsIssuedTokenMixedEndpoint)) 
{ 
    TrustVersion = TrustVersion.WSTrust13 
};