WCF 或 WSE 编辑安全标头

2024-03-15

我一直在尝试使用 WCF 或 WSE 更改肥皂安全元素。

  1. WCF:实现消息检查器并在 Beforerequestsent 中添加自定义代码。在后面的代码中设置以下自定义绑定后,我在参考 System.ServiceModel.Channels.Message request` 中没有看到安全元素。有一个信封和标头、正文,但标头中缺少安全元素。

    AsymmetricSecurityBindingElement secBE = AsymmetricSecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
    X509SecurityTokenParameters x509ProtectionParameters = new X509SecurityTokenParameters();
    x509ProtectionParameters.RequireDerivedKeys = false;
    x509ProtectionParameters.X509ReferenceStyle = X509KeyIdentifierClauseType.SubjectKeyIdentifier;
    x509ProtectionParameters.ReferenceStyle = SecurityTokenReferenceStyle.Internal;
    x509ProtectionParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
    

    这就是 ref 变量请求的样子

    <s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">  <s:Header>    <a:Action s:mustUnderstand="1" />    <a:MessageID>urn:uuid:4e929e4c-882b-40dc-9794-e54b71c47148</a:MessageID>    <a:ReplyTo>      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>    
    </a:ReplyTo>    
        <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo9rzFi9T6thDniQ9lRMdE0sAAAAA1RxuI+tGxUi69I44BS9+QcTNP3q82D9HmHmB8kuqWioACQAA</VsDebuggerCausalityData> 
     </s:Header> 
     <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <getEligibility xmlns="http://org/emedny/mhs/">      <input>        <transData</transData>      </input>  
      </getEligibility> 
      </s:Body>
    </s:Envelope>
    

    虽然 fiddler 显示传出安全标头,但我无法访问请求发送之前方法中的安全元素

  2. WSE:他们建议使用肥皂过滤器并覆盖一些方法 我在代码后面有所有令牌

        ProxyGenerationWSDL.MHService MHs = new MHService();
        X509Certificate2 cert = GetCertificateFromStore("User");
        X509SecurityToken x5091 = new X509SecurityToken(cert);
        MHs.SetClientCredential(x5091);
        X509Certificate2 cert2 = GetCertificateFromStore("Server");
        X509SecurityToken x5092 = new X509SecurityToken(cert2);
        MHs.SetServiceCredential(x5092);
        UsernameToken tkuser = new UsernameToken("User1", "Pwd", PasswordOption.SendPlainText);
        MHs.RequestSoapContext.Security.Tokens.Add(x5091);
        MHs.RequestSoapContext.Security.Tokens.Add(x5092);
        MHs.RequestSoapContext.Security.Tokens.Add(tkuser);
        Microsoft.Web.Services3.Security.EncryptedData data = new Microsoft.Web.Services3.Security.EncryptedData(x5092);
        MHs.RequestSoapContext.Security.Elements.Add(new MessageSignature(x5091));
    

    现在创建了一个自定义策略,策略断言,我将覆盖以下内容

    public class ClientOutputFilter : SoapFilter
    {
        public ClientOutputFilter()
            : base()
        { }
    
        public override SoapFilterResult ProcessMessage(SoapEnvelope envelope)
        {    
                XmlDocument document = new XmlDocument();
                string s = envelope.InnerXml;
                document.LoadXml(envelope.InnerXml);  //loading soap message as string 
                string path = "/*:Envelope/*:Header/*:Security/*:TimeStamp";
                XmlNodeList ndlist =
                document.SelectNodes(path);
    //then remove the timestamp element from the security header
    

    但即使如此,信封也没有安全元件。

请建议。为了编辑安全标头需要重写哪些方法

编辑:现在出现的请求

        <o:BinarySecurityToken u:Id="uuid-993b00fe-4c5c-43e8-9882-c59c1e5d1179-7" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">--Removed--
        </o:BinarySecurityToken>
     <o:BinarySecurityToken u:Id="uuid-993b00fe-4c5c-43e8-9882-c59c1e5d1179-7" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">--Removed--
        </o:BinarySecurityToken>
    <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">PWD</o:Password>
</o:UsernameToken>

需要出现什么

<o:BinarySecurityToken u:Id="uuid-993b00fe-4c5c-43e8-9882-c59c1e5d1179-7" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">--Removed--
  </o:BinarySecurityToken>
  <o:BinarySecurityToken u:Id="uuid-993b00fe-4c5c-43e8-9882-c59c1e5d1179-7" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">--Removed--
  </o:BinarySecurityToken>
  <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">PWD</o:Password>
    <o:Nonce>XXXX</o:Nonce>
    <o:Created>TTT</o:Created>
 </o:UsernameToken>

编辑显示 完成 Soap 请求以显示签名和加密详细信息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mhs="http://org/emedny/mhs/" xmlns:urn="urn:hl7-org:v3">
<soapenv:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-e00c8062-83d2-4f04-88fc-996218e7bb3d">MIICeDCC....(eMedNY signed user MLS cert).......</wsse:BinarySecurityToken>
    <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685">MIIDFj.....( eMedNY MLS web-service end-point public cert)........</wsse:BinarySecurityToken>
    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-970e9a80-00cc-4c86-8ec4-3ba16e029a5b">
    <wsse:Username>....your_username.....</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">.....your_plaintext_password....</wsse:Password>
    <wsse:Nonce>KNyu6MsXCkTg4DDyvwvEiw==</wsse:Nonce>
    <wsu:Created>2010-09-15T18:00:30Z</wsu:Created>
    </wsse:UsernameToken>
    <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
    <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <wsse:SecurityTokenReference>
    <wsse:Reference URI="#SecurityToken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
    </KeyInfo>
    <xenc:CipherData>
    <xenc:CipherValue>gpBAWt91pdwhKva............</xenc:CipherValue>
    </xenc:CipherData>
    <xenc:ReferenceList>
    <xenc:DataReference URI="#Enc-0641b860-b16d-4941-91c0-d60bece67794"/>
    </xenc:ReferenceList>
    </xenc:EncryptedKey>
    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
    SAMP L E R EQUE ST W I T H WS S E CURI T Y
    eMedNY Meds History Service User Guide Page 13 of 48 February 16, 2012
    Version 1.1
    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <Reference URI="#Id-f10674fd-b999-47c9-9568-c11fa5e5405b">
    <Transforms>
    <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    </Transforms>
    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <DigestValue>wRUq.........</DigestValue>
    </Reference>
    </SignedInfo>
    <SignatureValue>tBSsaZi........</SignatureValue>
    <KeyInfo>
    <wsse:SecurityTokenReference>
    <wsse:Reference URI="#SecurityToken-e00c8062-83d2-4f04-88fc-996218e7bb3d" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
    </KeyInfo>
    </Signature>
    </wsse:Security>
    </soapenv:Header>
    <soapenv:Body wsu:Id="Id-f10674fd-b999-47c9-9568-c11fa5e5405b" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <xenc:EncryptedData Id="Enc-0641b860-b16d-4941-91c0-d60bece67794" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
    <xenc:CipherData>
    <xenc:CipherValue>SQsTCAK6ZaVhojB8+Y.........</xenc:CipherValue>
    </xenc:CipherData>
    </xenc:EncryptedData>
    </soapenv:Body>

在 WCF 中,您需要使用自定义消息编码器 http://msdn.microsoft.com/en-us/library/ms751486.aspx。检查员被叫来改变安全措施为时过早。如果您愿意分享有关您想要进行的具体更改的更多详细信息,也许我们可以提供更好的帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WCF 或 WSE 编辑安全标头 的相关文章

  • REST 服务上的错误请求错误 使用 POST(json 数据)调用方法?

    您好 我是 RESTful WCF 的新手 我正在尝试使用 POST 对 Web 服务方法进行简单调用 这是我的代码 Service Interface code ServiceContract public interface IJson
  • 具有多个绑定的ServiceHostFactory

    如何使用具有多个绑定的 ServiceHostFactory 这是我尝试过的方法 但我不断遇到问题 一个又一个错误 using System using System Collections Generic using System Lin
  • SQL CLR 内的 WCF 客户端

    我知道它不受支持 而且我知道这甚至不是一个好主意 但是 我希望在 SQL 表值函数中拥有一个 WCF 客户端 我 看似 注册了正确的程序集 但在运行我的客户端时 我收到 WCF 错误 Msg 6522 Level 16 State 1 Li
  • 表达式树序列化器

    我想在客户端使用 Linq 表达式 序列化它们并在服务器端执行它们 为此我想使用 http expresstree codeplex com http expressiontree codeplex com 但我想针对自己的 WCF 调用执
  • iPhone / .NET WCF 互操作性

    我正在构建一个 NET Web 服务 和一个将使用这些服务的 iPhone 应用程序 我很好奇是否有任何构建两者之间交换数据的协议的最佳实践 对于我来说 基于 SOAP 的 Web 服务对于 iPhone 应用程序来说太沉重了 也许可以用
  • 世界CF。服务通用方法

    如何在 wcf 服务中使用通用方法 我写了这段代码 OperationContract void AddItem
  • WCF服务契约上的数据注释

    我有一个 WCF 服务 其中定义了一个 DataContract 类 每个属性都有 DataMember 属性 并且我已向其中几个属性添加了几个数据注释属性 Required 和 StringLength 然后 我在 ASP NET MVC
  • 是否可以从 VS2010 插件刷新 WCF 服务引用?

    我想在 VS2010 插件中 模拟 右键单击 更新服务引用命令 我有一个对包含 Silverlight 项目的引用 我知道服务引用的名称和服务的 url 我发现了这个 http dedjo blogspot com 2007 03 addi
  • 将文件附加到 WCF REST 服务响应

    我有一个看起来像这样的资源 users id summary format format When format是 xml 或 json 我用一个由 WCF 自动编码的用户摘要对象进行响应 到目前为止还不错 但当format等于 pdf 我
  • 是否可以将 WPF Combobox.SelectedValue 绑定到多个 ObjectDataProvider?

    尝试确定是否可以使用 XAMAL 绑定将 ComboBox 的 SelectedValue 绑定到多个 ObjectDataProvider 的输入 我查看了 MultiBinding 但这似乎将多个控件组合在一起 这并不完全是我今天想要的
  • WCF:Per-Call 和 Per-Session 服务...需要说服 Per-Call 是值得的

    我们目前正在审查 WCF 服务设计 困扰我的一件事是 Per Call 和 Per Session 服务之间的决定 我相信我理解两者背后的概念 但我并没有真正看到按呼叫服务的优势 我知道使用 Per Call 服务的动机是 WCF 服务仅在
  • 如何研究.NET 中的非托管内存泄漏?

    我有一个通过 MSMQ 运行的 WCF 服务 内存随着时间的推移逐渐增加 表明存在某种内存泄漏 我在本地运行该服务并使用 PerfMon 监视一些计数器 CLR 内存托管堆字节总数保持相对恒定 而进程的私有字节随着时间的推移而增加 这让我相
  • WCF 数据契约/序列化

    我创建了一个简单的 WCF 应用程序 它公开一个操作 此操作采用复合数据类型作为参数 我没有用 DataContract 属性修饰这个复合数据类型 但这是有效的 我可以在 WSDL 中看到它的架构 现在我的理解是 这个新的自定义类型应该用
  • 优雅地终止 WCF 服务 - 完成所有打开的会话并限制新会话

    我有一个我编写的 WCF 服务 它托管在 Windows 服务中 它以 PerSession 模式运行 该服务允许客户端通过该服务远程打开文件 更改文件以及关闭文件 到目前为止一切工作都非常顺利 当 Windows 服务停止时 我希望能够让
  • 如何添加重试以调用 Web 服务?

    我有一个应用程序调用使用 wsHttpBinding 的 Web 服务 我需要在连接超时等情况下对 Web 服务调用实现某种重试功能 执行此操作的最佳方法是什么 我已经阅读过有关 WS ReliableMessaging 的内容 但这不是
  • 从事务范围调用 WCF 服务方法

    我有这样的代码 using TransactionScope scope TransactionScopeFactory CreateTransactionScope some methodes calls for which scope
  • WCF:在 ServiceModel 客户端配置部分中找不到引用协定“IService”的默认端点元素。当托管在 IIS 中时

    我有一个 WCF 服务托管在 IIS 中 我还有一个 WCF 客户端 控制台应用程序 我用过svcutil构建代理类和配置文件 然后将它们添加到我的客户端项目中 它建造得很好 但是当我尝试运行该程序时 它抛出以下异常 在 ServiceMo
  • WCF 服务已超出最大数组长度配额 (16384)

    我有一个 wsf 服务和一个客户端应用程序 在尝试与客户端和服务进行通信时 我收到以下消息 格式化程序在尝试反序列化消息时引发异常 尝试反序列化参数时出错http tempuri org blob http tempuri org blob
  • WPF 和 WCF 应用程序的用户身份验证/授权的“最佳实践”是什么?

    假设我有一个 NET 富客户端 WPF 应用程序 它将同时部署在 3 个不同的场景中 客户端和服务器代码在单个进程中运行 客户端代码在 Intranet 计算机上运行 并通过 WCF 与运行应用程序 域 基础设施代码的服务器计算机进行通信
  • 没有端点在 net.pipe://localhost/ 上监听

    我有两个 WCF 服务托管在 Windows Server 2003 计算机上的单个 Windows 服务中 如果 Windows 服务需要访问任一 WCF 服务 例如发生定时事件时 它将使用公开的五个命名管道端点之一 不同的服务协定 该服

随机推荐