c# - WCF 服务器接受 TLS 1.0 连接

标签 c# wcf ssl tls1.2

我有一个非常“简单”的问题。我有一个应该只接受 TLS 1.2 连接的 WCF 服务器。但每次我通过 firefox 或任何使用 TLS 1.0 的浏览器连接到它时。

.NET Framework-Version 是 4.6.1 所以它应该支持 TLS 1.2。 这是我的 app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="WCFServer.Properties.Settings.ConnectionString" connectionString="SomeConnectionString" />
  </connectionStrings>
  <system.serviceModel>
    <bindings>          
  <netTcpBinding>
    <binding name="TestNetTcpBinding">
      <reliableSession enabled="true" />
      <security>
        <message clientCredentialType="Windows" algorithmSuite="Basic256Sha256Rsa15" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="MyCustomAttributeBehavior">
      <Validator />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpsGetEnabled="true" httpsGetUrl="mex" policyVersion="Default" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<extensions>
  <behaviorExtensions>
    <add name="Validator" type="WCFServer.RightAttribute.MyBehaviorSection, WCFServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </behaviorExtensions>
</extensions>
<services>
  <service behaviorConfiguration="DefaultBehavior" name="WCFServer.Services.Implementations.BusinessService">
    <endpoint address="ProductService" behaviorConfiguration="MyCustomAttributeBehavior"
      binding="netTcpBinding" bindingConfiguration="TestNetTcpBinding"
      contract="WCFServer.Services.Interfaces.IProductService" />
    <endpoint address="UserService" behaviorConfiguration="MyCustomAttributeBehavior"
      binding="netTcpBinding" bindingConfiguration="TestNetTcpBinding"
      contract="WCFServer.Services.Interfaces.IUserService" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://SomeHost/WCFService/Service" />
        <add baseAddress="https://SomeHost/WCFService/Service" />
      </baseAddresses>
    </host>
  </service>
</services>
  </system.serviceModel>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.0.4000" newVersion="4.1.0.4000" />
  </dependentAssembly>
</assemblyBinding>
  </runtime>
</configuration>

我希望我没有把 XML 的格式设置得太糟糕。对不起。 我把它放在控制台应用程序中进行测试。 这是我的主要方法(我尝试将 SecurityProtocol 设置为仅 TLS 1.2)

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var host = new ServiceHost(typeof(BusinessService));
host.Open();    
Console.WriteLine("Services Ready");
Console.WriteLine("Press any button to close services.");
Console.Read();
host.Close();
Environment.Exit(0);

我的类 BusinessService 实现了 IUserServiceIProductService

您可以忽略 MyCustomAttributeBehavior。只是一些“拦截器”的东西,这应该无关紧要。

编辑:证书没问题。 firefox 也这么说。 证书是否必须满足任何特殊要求?我不这么认为,但我不确定。

我已经尝试在 host.Open() 之前和之后设置 SecurityProtocol。两者都不起作用。

感谢任何帮助。

谢谢!

最佳答案

ServicePointManager.SecurityProtocol 仅用于打开连接,不用于接收连接。如果您使用基于 HTTP 的绑定(bind)(例如 BasicHttpsBinding),则使用的 SSL/TLS 版本将取决于 HTTP.SYS 配置(自托管或在 IIS 中),而后者又取决于全局 SCHANNEL 设置机器。

在这种情况下,您使用的是 NetTcp,最后我记得它根本不使用 SSL/TLS。

关于c# - WCF 服务器接受 TLS 1.0 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42442749/

相关文章:

c# - Unity 让玩家棋子在掷骰子后轮流移动

c# - 自动实现属性的代码契约(Contract)

wcf - 如何替换 Web Api 堆栈中的 DataContractResolver?

c# - WCF 模拟的目的

wcf - C# ConcurrentQueue - Enqueue 发生时引发事件?

c# - 如何基于除平等以外的其他谓词进行 GroupJoin?

c# - 如何测试两个日期时间是否相同?

authentication - 通过代理身份验证的 FTPS

ssl - 带有自签名证书的 TLS

Android WebView setCertificate 问题 SSL 问题