【问题标题】:Using SSL3 from Azure Functions to Call External API使用 Azure Functions 中的 SSL3 调用外部 API
【发布时间】:2017-08-08 05:40:42
【问题描述】:

我们有一个 .NET 应用程序需要与严格要求 SSL3 才能工作的 API 进行交互,但是我们不希望我们的整个网站都在该安全协议中运行。

为了在 .NET 框架中实现这一点,我们使用了AppDomain and, therefore, remoting。但是,我们正在将我们的应用程序移植到 .NET Core 2.0,我们不再可以使用该功能。

我们提出的解决方案是使用 Azure Functions 拥有一个无服务器函数,该函数可以联系 API 并返回交互结果,因此充当代理。

这是我们在函数中设置的一些代码:

// set the protocol to SSL3 app wide
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
// ignore any SSL errors
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

但是运行它会给我们以下错误:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm
   at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String package, CredentialUse intent, SecureCredential scc)
   at System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse credUsage, SecureCredential& secureCredential)
   at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
   at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)
   at System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.TlsStream.CallProcessAuthentication(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at Submission#0.<Run>d__1.MoveNext() in :line 15

是否可以让 Azure Functions 执行我们正在尝试执行的操作,或者我们尝试设置的设置在沙盒环境中没有得到遵守?

【问题讨论】:

    标签: c# azure ssl azure-functions


    【解决方案1】:

    Azure Functions 运行在 Windows 工作者之上,就像 Web 应用一样,因为它们都是应用服务的一部分。下面是同一个沙箱。

    如果您在 Kudu 中使用 PowerShell your way around the registry,您会发现 SSL 3.0 在系统范围内被禁用,这是任何现代服务所期望的。

    来自 Ivan Ristić 的优秀Bulletproof SSL 和 TLS 书:

    DisabledByDefault — 此设置适用于未明确配置启用协议但使用系统默认值的应用程序。如果该条目不存在或值为 0,则默认启用该协议。 如果值为 1,则默认禁用该协议。通常情况下,Windows 将禁用 SSL 2 并保持所有其他协议处于启用状态。

    在过去 10 年中,运行仅限 SSL 3.0 的 API 的人请了太多假期。对那些人讲一些道理。 SSL 3.0 容易受到 BEAST 攻击,微软的实现中没有 AES,不支持 GCM、SHA256 和 SHA384 套件,也没有椭圆曲线加密,因此没有前向保密。

    如果您依赖 SSL 3.0 在晚上睡觉没有问题,您将不得不使用 .NET/Windows(System.Security 和 SCHANNEL)提供的different TLS library。 OpenSSL、BoringSSL、GnuTLS、LibreSSL 如果您找到 C# 包装器或者您有足够的时间自己动手,它们都是选项。

    这里真正的解决方案是通过虚拟机代理所有请求。你控制操作系统,你控制 TLS 堆栈。然后,您可以对您的遥控器使用 SSL 3.0。我不敢相信我会这么说 - 给我他们的电话号码!

    更新:您现在可以使用(更多)轻量级容器实例来代理 SSL 3.0 流量。见https://docs.microsoft.com/en-us/azure/container-instances/container-instances-overview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 2016-08-14
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多