2017-02-20 61 views
1

我嘗試以下操作:調用WCF服務發出的令牌

  • 一個WCF客戶端調用STS,並得到SAML斷言
  • 客戶端調用使用SAML斷言現在

服務我已將上述場景實施爲三個LinqPad腳本:client.linq,sts.linq(自託管的WCF服務)和service.linq(自託管的WCF服務)。他們都可以在https://github.com/codeape2/WCF_STS

我需要一些幫助得到這個工作。

使用client.linq下面的代碼,我可以打電話給我的STS,並得到一個SAML斷言:

SecurityToken GetToken() 
{ 
    var binding = new BasicHttpBinding(); 
    var factory = new WSTrustChannelFactory(binding, stsAddress); 
    factory.TrustVersion = TrustVersion.WSTrustFeb2005; 

    var rst = new RequestSecurityToken 
    { 
     RequestType = RequestTypes.Issue, 
     KeyType = KeyTypes.Symmetric, 
     AppliesTo = new EndpointReference(serviceAddress) 
    }; 
    return factory.CreateChannel().Issue(rst); 
} 

下一步,我用下面的代碼(嘗試)打電話給我服務與SAML斷言包括:

var binding = new WSFederationHttpBinding(WSFederationHttpSecurityMode.Message); 
binding.Security.Message.EstablishSecurityContext = false; 
var factory = new ChannelFactory<ICrossGatewayQueryITI38>(
    binding, 
    new EndpointAddress(new Uri(serviceAddress), new DnsEndpointIdentity("LocalSTS")) 
); 

factory.Credentials.SupportInteractive = false; 
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = 
    X509CertificateValidationMode.None; 

var proxy = factory.CreateChannelWithIssuedToken(token); 
var response = proxy.CrossGatewayQuery(
    Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "urn:ihe:iti:2007:CrossGatewayQuery", "Hello world") 
); 

接下來會發生什麼我完全不明白。我有提琴手運行,當我運行該腳本,這裏是我所看到的:

  1. 第一次請求/STS(預期)
  2. proxy.CrossGatewayQuery結果三次調用/Service

    2.1。帶有動作的SOAP調用http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue

    2.2。帶有動作的SOAP調用http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue

    2.3。最後的SOAP調用動作爲urn:ihe:iti:2007:CrossGatewayQuery。使用Fiddler,我注意到SOAP安全頭包含第一步中的SAML斷言。

最終調用導致從服務返回SOAP錯誤:消息中至少有一個安全令牌無法驗證。保存的提琴手請求/響應日誌是在這裏:https://drive.google.com/file/d/0B-UZlLvBjjB2S050TXRhVEo2Vmc/view?usp=sharing

如果有誰能夠告訴我關於下面,我將非常感激:

  • 爲什麼WCF客戶端發送RST/IssueRSTS/Issue請求到/Service (上述步驟2.1和2.2)?
  • 如何配置這些組件以完成我想要的操作,即向STS發送一個請求,然後向服務發送一個請求,傳遞從STS獲得的SAML斷言。

回答

1

第一個問題是重新協商服務憑證。

這種變化照顧的是:

binding.Security.Message.NegotiateServiceCredential = false 

然後,服務不得不啓用WIF配置:太

host.Credentials.UseIdentityConfiguration = true; 
host.Credentials.IdentityConfiguration = CreateIdentityConfig(); 

IdentityConfiguration CreateIdentityConfig() 
{ 
    IdentityConfiguration identityConfig = new IdentityConfiguration(false); 

    //AUDIENCE URI     
    //the token we receive contains this value, so if do not match we fail 
    identityConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri($"http://{Environment.MachineName}:8000/Service")); 

    //ISSUER NAME REGISTRY explicit the thumbprint of the accepted certificates, if the token coming in is not signed with any of these certificates then is considered invalid 
    var issuerNameRegistry = new ConfigurationBasedIssuerNameRegistry(); 
    issuerNameRegistry.AddTrustedIssuer("81 5b 06 b2 7f 5b 26 30 47 3b 8a b9 56 bb 9f 9f 8c 36 20 76", "signing certificate sts"); //STS signing certificate thumbprint 
    identityConfig.IssuerNameRegistry = issuerNameRegistry; 
    identityConfig.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 
    return identityConfig; 
} 

還有其他的變化,GitHub庫已更新的代碼,在工作master分支。

感謝MS支持誰走過我通過弄清楚這一點。