【问题标题】:Implementing TLS 1.2 on .NET Framework 3.5 while connecting to payment gateway在连接到支付网关时在 .NET Framework 3.5 上实施 TLS 1.2
【发布时间】:2018-08-14 06:24:06
【问题描述】:

结束更新 正如我在下面的评论中宣布的那样,我决定停止解决这个问题,因为我很确定我无法修复它,因为无法访问该网站的源代码。我已经假设我面临的大多数问题都是由不正常的反编译过程引起的,所以我没有找到任何理由至少现在继续处理它。 非常感谢所有阅读、思考或试图帮助我的人。 我没有找到解决这个问题的方法,可能是因为我作为“新”用户缺乏特权,所以如果有特权的人阅读了这篇文章并可以帮助关闭它,我们将不胜感激:-)

早上好。由于这是我在这里的第一篇文章,我想开始感谢你们所有人的耐心、同理心和无价的帮助。 现在让我们尽可能清楚地解释我的情况:与其他许多人一样,我正在遭受由 TLS 1.2 标准引起的问题:现在我无法连接到我们的支付网关(Realex Payments,以防它产生任何影响)因为他们拒绝所有非 TLS 1.2 连接。 我已经“继承”了一个完整的网站,其中包含大量 C# .NET 部署代码(老实说,我绝对不掌握),所以我的第一个动作是从服务器下载所有这些代码并反编译 dll 文件使用 .NET 反射器 9.0。 该系统是在 .NET 3.5 框架下开发的,我保证我在这里、Microsoft 支持站点和整个 Web 上阅读了很多关于它的信息。我能找到的最佳解决方案来自这里的 2 个帖子:

.NET Framework 3.5 and TLS 1.2

How to implement Security Protocols TLS 1.2 in .Net 3.5 framework

与 D_Bester 的答案基本相同。

我发现的问题是,当我尝试粘贴此 C# 代码时:

    public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
    public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
    ServicePointManager.SecurityProtocol = Tls12

在作者指出的我的 httpwebrequest 之前,VS 2015 在第三句话中显示了一个错误

"The name 'ServicePointManager.SecurityProtocol' does not exist in the current context.

The name 'SecurityProtocol' does not exist in the current context." 

如果有帮助,请提供更多信息: 我无法应用补丁或编辑注册表,因为整个网站都托管在在线托管中,但是当我们第一次遇到这个问题时,我们要求他们将我们的内容迁移到支持 .Net framework 4.5 的新服务器上。

尝试遵循找到的代码和其他解决方案,我编辑了我的 SslProtocols.cs 文件,手动将较新的协议添加到枚举中,如下所示:

    namespace System.Security.Authentication
    {
        using System;

        [Flags]
        public enum SslProtocols
        {
            Default = 240,
            None = 0,
            Ssl2 = 12,
            Ssl3 = 48,
            Tls = 192,
            Tls11 = 768,
            Tls12 = 3072
                }
    }

但 ServicePointManager.cs 似乎无法识别我的更新,因为在它用作参数“SslProtocols.Tls12”的一种方法中,它不接受 Tls12,只接受原始的(默认、无、Ssl2、Ssl3 和Tls)所以我可能不得不在任何地方更新它。我还尝试将 Tls12 添加到 SecurityProtocolType.cs 枚举和 SecurityProtocolTypeExtensions.cs,所有这些都来自我现在无法找到的来源的指示(我发誓我已经添加了书签,但显然我没有)。

如果有帮助,我会编辑以添加我的导入列表:

    using System;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Globalization;
    using System.IO;
    using System.Net;
    using System.Net.Cache;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Authentication;
    using System.Security.Permissions;
    using System.Text;
    using System.Threading;

有什么想法吗?或者我是否需要提供任何其他信息?

【问题讨论】:

  • 你添加了using System.Net;吗?
  • 感谢您的回答。我确实这样做了,如果有帮助,我会用我的导入编辑我的第一篇文章。
  • 我无法在面向 .Net 3.5 的项目中重现该问题。
  • 我想我必须在其他任何地方“定义”Tls12,我的意思是,在另一个文件或配置中,但我不知道在哪里。无论如何感谢您的尝试;-)

标签: c# .net-3.5 tls1.2 realex-payments-api


【解决方案1】:

达鲁尼翁,

正如您所提到的,注册表项和服务包不是一个选项,您剩下的唯一解决方案是迁移到 .NET 框架的 4.0 或更高版本。 “SecurityProtocolType.Tls12”在 .NET framework 4.5 版本中可用。

【讨论】:

  • 但在我提到的链接中,他们说可以在 3.5 框架下强制 Tls12。是我错了还是我误解了什么?
  • 是的,但是你必须部署一些补丁。因此,3.5 中没有可用的枚举
【解决方案2】:

假设您只需要定义Tls12 并访问ServicePointManager

  1. Tls12:

您可以将 Microsoft 支持链接中提到的覆盖定义为

https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-net-framework

namespace System.Security.Authentication
{
    public static class SslProtocolsExtensions
    {
        public const SslProtocols Tls12 = (SslProtocols)0x00000C00;
        public const SslProtocols Tls11 = (SslProtocols)0x00000300;
    }
} 

namespace System.Net
{
    using System.Security.Authentication;
    public static class SecurityProtocolTypeExtensions
    {
        public const SecurityProtocolType Tls12 = (SecurityProtocolType)SslProtocolsExtensions.Tls12;
        public const SecurityProtocolType Tls11 = (SecurityProtocolType)SslProtocolsExtensions.Tls11;
        public const SecurityProtocolType SystemDefault = (SecurityProtocolType)0;
    }
} 
  1. 服务点管理器

您可能已经尝试过,为 System.Net 加上前缀,因此它看起来像:

System.Net.ServicePointManager.SecurityProtocol = Tls12

【讨论】:

  • 非常感谢您的回答,Jigar。我已经尝试过您指出的内容,并且看起来不错……直到我尝试重新编译整个解决方案并且许多其他错误仍然存​​在。我确信我的所有问题都来自一个糟糕的反编译过程,所以在这个过程之后几乎没有什么效果很好。由于我无法以任何方式访问源代码,因此我认为这超出了我的能力范围。这就是为什么我现在决定搁置这个问题(至少从现在起很长一段时间,呵呵),如果我发现如何,我会关闭这个话题,以防止任何其他人浪费他们的时间试图帮助我喜欢你和其他一些人做到了。
  • @daruniom,您可以分享编译时出现的主要错误,可能有一个快速的解决方法可以一次解决所有错误。
猜你喜欢
  • 2018-12-26
  • 2016-11-11
  • 2023-04-07
  • 2012-05-27
  • 2020-05-14
  • 2017-08-31
  • 2020-04-05
  • 2011-12-31
  • 2016-12-06
相关资源
最近更新 更多