【问题标题】:Google Analytics Access Token - TLS 1.1+谷歌分析访问令牌 - TLS 1.1+
【发布时间】:2016-05-09 03:01:58
【问题描述】:

我正在使用 C# 从 Google 请求访问令牌:

string serviceAccountEmail = ConfigurationManager.AppSettings["analyticsServiceAccountEmail"].ToString();
      string securityKey = ConfigurationManager.AppSettings["analyticsSecurityKeyLocation"].ToString();
      string password = ConfigurationManager.AppSettings["analyticsSecurityPassword"].ToString();

      var certificate = new X509Certificate2(securityKey, password, X509KeyStorageFlags.Exportable);

      var scopes = new List<string> { "https://www.googleapis.com/auth/analytics.readonly", "https://www.googleapis.com/auth/analytics" };

      ServiceAccountCredential credential = new ServiceAccountCredential(
         new ServiceAccountCredential.Initializer(serviceAccountEmail)
         {
           Scopes = scopes
         }.FromCertificate(certificate));

      Task<bool> task = credential.RequestAccessTokenAsync(CancellationToken.None);

      task.Wait();

      if (!task.Result || credential.Token == null || string.IsNullOrEmpty(credential.Token.AccessToken))
      {
        throw new Exception("Failed to get token from Google");
      }

      return credential.Token.AccessToken;

为了符合 PCI 规定,我不得不禁用 TLS 1.0。既然我已经这样做了,这段代码就会出现以下错误:

发生了一个或多个错误。:发送 请求。:底层连接已关闭:意外错误 接收时发生。:客户端和服务器无法通信, 因为他们没有共同的算法

关于如何使用 TLS 1.1+ 拨打电话的任何建议?

【问题讨论】:

  • 看看这个link。它对此有很好的信息。

标签: google-analytics access-token tls1.2


【解决方案1】:

必须通过 Global.asax 在 Application_start 中完成:

请在进行更改之前阅读此内容:How do I disable SSL fallback and use only TLS for outbound connections in .NET? (Poodle mitigation)

方法是:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12

这将打开对 SSL3 的通信支持,并在适用时回退到 TLS 1.1 或 TLS 1.2。

【讨论】:

  • SSL 3.0 的安全性不比 TLS 1.1 低吗?无论如何,我只想要 TLS 1.1+。当我这样做时,对 Google Analytics 的调用失败。仅当我启用 TLS 1.0 时它才有效。
猜你喜欢
  • 2019-07-07
  • 2017-09-15
  • 2014-10-17
  • 2017-11-13
  • 1970-01-01
  • 2016-06-16
  • 2012-05-10
  • 2016-04-19
相关资源
最近更新 更多