繁体   English   中英

在连接到支付网关时在.NET Framework 3.5上实现TLS 1.2

[英]Implementing TLS 1.2 on .NET Framework 3.5 while connecting to payment gateway

结束更新正如我在下面的评论中宣布的那样,由于无法访问网站的源代码,我非常确定无法解决此问题,因此我决定停止解决此问题。 我已经假设我面临的大多数问题是由于反编译工作不正常造成的,所以至少在目前,我没有任何理由继续处理它。 非常感谢阅读,考虑或尝试帮助过我的每个人。 我找不到解决此问题的方法,可能是由于我缺乏作为“新”用户的特权,因此,如果有特权的人阅读并可以帮助解决此问题,将不胜感激:-)

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

.NET Framework 3.5和TLS 1.2

如何在.Net 3.5框架中实现安全协议TLS 1.2

基本上与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;

有任何想法吗? 还是我需要提供其他信息?

达鲁尼翁,

正如您提到的,注册表项和Service Pack不是一个选择,唯一剩下的解决方案是迁移到4.0或更高版本的.NET Framework。 .NET框架的4.5版本中提供了“ SecurityProtocolType.Tls12”。

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

  1. Tls12:

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

https://support.microsoft.com/zh-CN/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. ServicePointManager

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

System.Net.ServicePointManager.SecurityProtocol = Tls12

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM