【问题标题】:Unable to decrypt claims cookie from .NET 4.5 to .NET 3.5无法将声明 cookie 从 .NET 4.5 解密到 .NET 3.5
【发布时间】:2014-03-12 07:48:21
【问题描述】:

我一直试图让以下场景工作大约一周,但没有运气。我有 2 个应用程序,一个已启用声明的 .NET 4.5 应用程序,它运行良好(与其他 .NET 4 及更高版本的应用程序一起使用);以及使用 WebForms .NET 3.5 构建的遗留 Intranet 系统。旧版应用程序无法升级到更高版本的 .NET(会容易得多)。

我想要发生的是,当我登录 .NET 4.5 应用程序时,我需要在访问 .NET 3.5 应用程序时进行身份验证。我已确保应用程序之间的 Cookie 名称相同,并且 web.config 中的 machineKey 值相同(我使用 MachineKeySessionSecurityTokenHandler 来确保加密的 cookie 值即使在 Web Farm 场景中也是相同的);但是发生的情况是,当我移至 .NET 3.5 应用程序时,我从 SymmetricEncryptionFormatter 类中收到以下错误:

ID0006:输入字符串参数为空或空。参数名称:值

我尝试将 MachineKey 密钥(decryptionkey/validationkey/validation/decryptiom)更改为各种不同的组合(确保它们在 2 个站点之间保持一致)。我可以看到,当我访问 2 个站点时,可以看到具有相同 cookie 值的相同 cookie。我认为这个问题可能与 .NET 3.5 和 .NET 4.5 之间的 Crytographic 更改有关(请参阅此处 [http://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographic-improvements- in-asp-net-4-5-pt-2.aspx])

有没有人知道是什么原因造成的?

来自 .NET 4.5 应用程序 Web.config 的关键条目:

<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />  
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>

<authentication mode="None" />

<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" name="TestName" />
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost:51318/" realm="http://localhost:57083/" persistentCookiesOnPassiveRedirects="true" requireHttps="false" />
</federationConfiguration>
</system.identityModel.services>

来自 .NET 3.5 应用程序 Web.config 的关键条目:

<authentication mode="None"/>

<machineKey decryptionKey="CC510DF4..." validationKey="BEAC835EEC..." />

<microsoft.identityModel>
<service>
  <securityTokenHandlers>
    <!-- Replace the SessionSecurityTokenHandler with our own. -->
    <remove type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add type="MachineKeySessionSecurityTokenHandler, App_Code"/>
  </securityTokenHandlers>
</service>
</microsoft.identityModel>

<microsoft.identityModel.services>
<federationConfiguration>
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost:51318/" realm="http://localhost:57083/" requireHttps="false"/>
<cookieHandler requireSsl="false" name="TestName"/>
</federationConfiguration>
</microsoft.identityModel.services>

【问题讨论】:

    标签: c# .net .net-3.5 .net-4.5 claims-based-identity


    【解决方案1】:

    cookie 的内部格式在 WIF 和 .NET 4.5 之间发生了变化。您不能在版本之间共享它们。

    而是将两个应用都指向同一个 STS,并让每个应用使用自己的会话 cookie。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-11
      • 2015-09-14
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      相关资源
      最近更新 更多