从消息时间戳删除秒数,直到发送签名的请求时

问题描述 投票:2回答:2

我有一个WCF自定义绑定,该绑定使用TransportSecurityBindingElement安全元素,但是在客户端和(第三方)服务器上的时间准确性都存在持续的问题。

如何删除秒数以使时间戳仅精确到分钟(有人告诉我服务器将接受此时间)。

我的替代主意是在每次请求之前更新系统时间,但是这(错误地)假设服务器时间是准确的。我也尝试过完全删除时间戳(可能不是必需的),但是我得到了System.InvalidOperationExceptionSigning without primary signature requires timestamp.

。Net代码以构建安全元素:

    Dim msgSecVer As System.ServiceModel.MessageSecurityVersion = ServiceModel.MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10

    Dim tsbe As TransportSecurityBindingElement = SecurityBindingElement.CreateCertificateOverTransportBindingElement(msgSecVer)
    tsbe.EnableUnsecuredResponse = True
    tsbe.SetKeyDerivation(False)
    tsbe.AllowInsecureTransport = True
    tsbe.IncludeTimestamp = True

    'adding clock skew doesn't seem to make any difference?
    Dim clockSkew As TimeSpan = TimeSpan.FromMinutes(1)
    tsbe.LocalClientSettings.MaxClockSkew = clockSkew
    tsbe.LocalServiceSettings.MaxClockSkew = clockSkew

    Return tsbe

消息标题,注意(可能是多余的)时间戳的准确性:

POST http://wwwqa.xxxx.com/services/
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: xxxx
SOAPAction: ""
Host: wwwqa.xxxx.com
Content-Length: 2400
Expect: 100-continue
Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <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>2013-12-04T10:53:13.568Z</u:Created>
                <u:Expires>2013-12-04T10:58:13.568Z</u:Expires>
            </u:Timestamp>
            <o:BinarySecurityToken u:Id="uuid-bc441202-xxxx-xxxx-a176-02f2a61a6002-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">....xxxx....</o:BinarySecurityToken>
            <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#rsa-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>xxxx</DigestValue>
                    </Reference>
                </SignedInfo>
                <SignatureValue>xxxx</SignatureValue>
                <KeyInfo>
                    <o:SecurityTokenReference><o:Reference URI="#uuid-bc441202-xxxx-xxxx-a176-02f2a61a6002-1"/></o:SecurityTokenReference>
                </KeyInfo>
            </Signature>
        </o:Security>
    </s:Header>
.net wcf httprequest wcf-client custom-binding
2个回答
2
投票

生成时间戳并将其推入SOAP(简单)。

    生成签名(硬)。参见here,GetSignature注释了我们的方法here。然后将其推送到SOAP。
  • 要操作SOAP,请执行编码器,并在您可以访问消息的WriteMessage方法中,将其加载到XmlDocument并进行操作(例如,添加标头)。

  • -1
    投票
    我记得,模块程序读取并读取了HTTPContext,允许您随意更改消息,甚至将新字段添加到标头和正文部分。

    但是,仅当您使用IIS来管理或管理Web服务时,此方法才有效。

    这里是链接:http://www.iis.net/learn/get-started/introduction-to-iis/iis-modules-overview#Querying

    © www.soinside.com 2019 - 2024. All rights reserved.