.NET 1.1 と WSE 2.0 で、署名と暗号化の両方に x509 証明書を使用する WS-Security を使用する Web サービスがあります。このサービスに接続するように WCF クライアントを構成しようとしていますが、予想以上に難しいことがわかりました。
カスタム バインドを使用することで、バージョン管理の問題のほとんどを解決しましたが、最後の 1 つの点で行き詰まっています。Web サービスには、応答 SOAP エンベロープに 2 つの BinarySecurityToken 要素が含まれています。1 つは暗号化証明書用で、もう 1 つは署名証明書用です。
問題は、WCF が 2 番目のトークンで窒息していることです。これはエラーメッセージです:
「'System.IdentityModel.Tokens.X509SecurityToken' トークン タイプのトークン認証子が見つかりません。現在のセキュリティ設定に従って、そのタイプのトークンを受け入れることはできません。」
私が抱えている正確な問題を説明するこの会話を MSDNで見つけました。残念ながら、それは良い解決策を提供しません。エンベロープを WCF が処理できるものにハックするメッセージ エンコーダーを作成することは、私には間違っているように思えます。WSE 2.0 はインライン セキュリティ トークンを問題なく処理できます。WCF に同じ処理を強制する方法が必要です。
元の WSE 2.0 サービスの完全なソースはありますが、現時点ではセキュリティの処理方法を変更することはできません。
私が現在使用しているセキュリティバインディング要素は次のとおりです。
Dim lSBE As New System.ServiceModel.Channels.AsymmetricSecurityBindingElement()
Dim lInitiatorTokenParameters As New System.ServiceModel.Security.Tokens.X509SecurityTokenParameters
lInitiatorTokenParameters.InclusionMode = System.ServiceModel.Security.Tokens.SecurityTokenInclusionMode.AlwaysToRecipient
lInitiatorTokenParameters.X509ReferenceStyle = System.ServiceModel.Security.Tokens.X509KeyIdentifierClauseType.RawDataKeyIdentifier
lInitiatorTokenParameters.RequireDerivedKeys = False
lSBE.InitiatorTokenParameters = lInitiatorTokenParameters
Dim lRecipientTokenParameters As New System.ServiceModel.Security.Tokens.X509SecurityTokenParameters
lRecipientTokenParameters.InclusionMode = System.ServiceModel.Security.Tokens.SecurityTokenInclusionMode.AlwaysToRecipient
lRecipientTokenParameters.X509ReferenceStyle = System.ServiceModel.Security.Tokens.X509KeyIdentifierClauseType.RawDataKeyIdentifier
lRecipientTokenParameters.RequireDerivedKeys = False
lSBE.RecipientTokenParameters = lRecipientTokenParameters
lSBE.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10
lSBE.DefaultAlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Basic128Rsa15
lSBE.SetKeyDerivation(False)
lSBE.IncludeTimestamp = True
lSBE.AllowSerializedSigningTokenOnReply = True
lSBE.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt