c# - 仅在高延迟网络上的 WCF/TLS 服务中的 SecurityNegotiationException

标签 c# wcf ssl networking latency

我试图让 WCF 网络服务在高延迟/低带宽网络上运行,但事情没有按计划运行。 WCF 服务在 Windows 服务中自托管,实现了这个接口(interface):

[OperationContract(Name = "send-file")]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
void SendFile(MyFileInfo myFile);

MyFileInfo 对象包含文件(作为字节数组)。该文件大约为 45 kB(千字节)。

正在使用 TLS,客户端和服务器身份验证(来自同一 CA 的证书,来自同一域的客户端和服务器)。

ServicePointManager.SecurityProtocol 在客户端和服务器上都设置为 SecurityProtocolType.Tls12,Expect100Continue 设置为 true,KeepAlive 在绑定(bind)传输元素上以编程方式设置为 true。

App.config 在这里(客户端和服务器相同):

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="MyHttpsBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
            sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" messageEncoding="Text"
            hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600"
            textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" proxyCredentialType="None" />
                    <message clientCredentialType="None" ></message>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>

    <services>
        <service 
        name="MyService" 
        behaviorConfiguration="MyHttpsBehavior">
            <endpoint binding="wsHttpBinding"
            bindingConfiguration="MyHttpsBinding" name="MyEndpoint"
            contract="IMyInterface">
            </endpoint>
        </service>
    </services>

    <behaviors>
        <serviceBehaviors>
            <behavior name="MyHttpsBehavior">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceCredentials>
                    <clientCertificate>
                        <authentication certificateValidationMode="ChainTrust"/>
                    </clientCertificate>
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

在标准本地网络(WLAN 或以太网,MTU 始终设置为 1248)上一切正常,但是当我切换到(模拟的)高延迟/低带宽网络时出现错误:

  • 800 毫秒延迟,入站和出站。这使得 1.6sc 来回 旅行。
  • 492 Kbps(千比特,不是字节)。
  • MTU = 1248

起初,我的 app.conf 超时设置设置为 1 分钟,客户端抛出一个可靠的 System.TimeoutException :“请求 channel 在 00:00:59.1535069 后等待回复时超时。增加传递给请求调用的超时值或增加绑定(bind)上的 SendTimeout 值。分配给此操作的时间可能是较长超时的一部分。---> System.TimeoutException:对“https://myserver:4444/”的 HTTP 请求已超过分配的超时 00:01:00。分配给此操作的时间可能是较长超时的一部分。”

服务器上没有错误。

如果我算一下,文件是 45 kb = 46080 b ~> 37 个数据包(MTU 和碎片)=> 37 * 1600(延迟)= 最少 1 分钟(加上 TLS,加上负载,加上...)

我将客户端和服务器上的超时设置更改为 5 分钟,弹出了一个新的客户端异常:“System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority '我的服务器:4444'"

客户端和服务器可以是 Windows 8 或 Windows 2008 R2,防火墙已关闭,如果我停止延迟模拟器 (Clumsy),一切都会恢复正常。

与 WCF 问题相比,我更能感觉到 TLS 问题,但我不是专家。也许你们中有人对这个问题有想法?

提前致谢!

打碟

编辑 我尝试了 Wireshark session (客户端 View ),结果如下:

2  26.958440 client -> server  TCP 66 64972 → 4444 [SYN] Seq=0 Win=8192 Len=0 MSS=1208 WS=256 SACK_PERM=1
3  26.958603  server -> client TCP 66 4444 → 64972 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
4  28.606141 client -> server  TCP 54 64972 → 4444 [ACK] Seq=1 Ack=1 Win=66304 Len=0
5  28.606359 client -> server  TCP 276 64972 → 4444 [PSH, ACK] Seq=1 Ack=1 Win=66304 Len=222
6  28.610326  server -> client TCP 1262 4444 → 64972 [ACK] Seq=1 Ack=223 Win=66304 Len=1208
7  28.610328  server -> client TCP 711 4444 → 64972 [PSH, ACK] Seq=1209 Ack=223 Win=66304 Len=657
8  30.277053 client -> server  TCP 54 64972 → 4444 [ACK] Seq=223 Ack=1866 Win=61440 Len=0
9  30.277177 client -> server  TCP 236 64972 → 4444 [PSH, ACK] Seq=223 Ack=1866 Win=61440 Len=182
10  30.279375  server -> client TCP 161 4444 → 64972 [PSH, ACK] Seq=1866 Ack=405 Win=66048 Len=107
11  31.920922 client -> server  TCP 331 64972 → 4444 [PSH, ACK] Seq=405 Ack=1973 Win=61440 Len=277
12  31.921599  server -> client TCP 139 4444 → 64972 [PSH, ACK] Seq=1973 Ack=682 Win=65792 Len=85
13  32.249867 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=682 Ack=1973 Win=61440 Len=1208
14  32.250099 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=1890 Ack=1973 Win=61440 Len=1208
15  32.250226  server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=3098 Win=66304 Len=0
16  32.250437 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=3098 Ack=1973 Win=61440 Len=1208
17  32.250699 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=4306 Ack=1973 Win=61440 Len=1208
18  32.250816  server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=5514 Win=66304 Len=0
19  33.623716 client -> server  TCP 54 64972 → 4444 [ACK] Seq=5514 Ack=2058 Win=61440 Len=0
... lots of similar packets ...
89  37.189910 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=61082 Ack=2058 Win=61440 Len=1208
90  37.190103 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=62290 Ack=2058 Win=61440 Len=1208
91  37.190260  server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=63498 Win=53760 Len=0
92  37.190303 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=63498 Ack=2058 Win=61440 Len=1208
93  37.190499 client -> server  TCP 1262 64972 → 4444 [ACK] Seq=64706 Ack=2058 Win=61440 Len=1208
94  37.190654  server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=65914 Win=51200 Len=0
95  37.190699 client -> server  TCP 1262 64972 → 4444 [PSH, ACK] Seq=65914 Ack=2058 Win=61440 Len=1208
96  37.190890 client -> server  TCP 865 64972 → 4444 [PSH, ACK] Seq=67122 Ack=2058 Win=61440 Len=811
97  37.191046  server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=67933 Win=49152 Len=0
98 160.241458  server -> client TCP 60 4444 → 64972 [RST, ACK] Seq=2058 Ack=67933 Win=0 Len=0

98 数据包 (RST ACK) 与我在客户端出现异常的时间完全相同。服务器上仍然没有错误。

最佳答案

我没有时间进一步调查,我仍然不知道为什么相互身份验证不起作用,但如果我禁用客户端证书,一切都会再次正常。问题(几乎)解决了...

关于c# - 仅在高延迟网络上的 WCF/TLS 服务中的 SecurityNegotiationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42114717/

相关文章:

wcf - 服务无法启动。无法注册网址

php - HTTPS 和 500 内部服务器错误

c# - 如何在 Windows 上获取区分大小写的路径?

c# - Visual Studio 2017 : <list> not showing correctly on hover (xml documentation)

c# - Windows 服务 - 它可以运行两个以不同时间间隔安排的独立任务吗

wcf - 是否有使用 MSMQ 的简单 WCF 在线示例?

c# - WCF 的非企业用途?

python - 从批处理文件启动时 "ImportError: DLL load failed while importing _ssl"

node.js - 如何为 Express v4.13 设置 SSL 证书?

c# - 带 UltraMaskedEdit 的时间选择器 (hh :MM tt) changes format to HH:MM when entering into edit mode