DotNetOpenAuth:邮件签名不正确

Sha*_*ler 10 openid yahoo asp.net-mvc dotnetopenauth

尝试使用MyOpenID和Yahoo进行身份验证时,我收到"消息签名不正确"异常.

我几乎使用了DotNetOpenAuth 3.4.2附带的ASP.NET MVC示例代码

public ActionResult Authenticate(string openid)
{
    var openIdRelyingParty = new OpenIdRelyingParty();
    var authenticationResponse = openIdRelyingParty.GetResponse();

    if (authenticationResponse == null)
    {
        // Stage 2: User submitting identifier
        Identifier identifier;

        if (Identifier.TryParse(openid, out identifier))
        {
            var realm = new Realm(Request.Url.Root() + "openid");
            var authenticationRequest = openIdRelyingParty.CreateRequest(openid, realm);
            authenticationRequest.RedirectToProvider();
        }
        else
        {
            return RedirectToAction("login", "home");
        }
    }
    else
    {
        // Stage 3: OpenID provider sending assertion response
        switch (authenticationResponse.Status)
        {
            case AuthenticationStatus.Authenticated:
            {
                // TODO
            }
            case AuthenticationStatus.Failed:
            {
                throw authenticationResponse.Exception;
            }
        }
    }

    return new EmptyResult();
}
Run Code Online (Sandbox Code Playgroud)

与Google,AOL和其他人合作正常.但是,Yahoo和MyOpenID属于AuthenticationStatus.Failed案例,但有以下异常:

DotNetOpenAuth.Messaging.Bindings.InvalidSignatureException: Message signature was incorrect.
   at DotNetOpenAuth.OpenId.ChannelElements.SigningBindingElement.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\ChannelElements\SigningBindingElement.cs:line 139
   at DotNetOpenAuth.Messaging.Channel.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\Messaging\Channel.cs:line 992
   at DotNetOpenAuth.OpenId.ChannelElements.OpenIdChannel.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\ChannelElements\OpenIdChannel.cs:line 172
   at DotNetOpenAuth.Messaging.Channel.ReadFromRequest(HttpRequestInfo httpRequest) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\Messaging\Channel.cs:line 386
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponse(HttpRequestInfo httpRequestInfo) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 540
Run Code Online (Sandbox Code Playgroud)

看来其他人有同样的问题:http://trac.dotnetopenauth.net : 8000/ticket/172

有没有人有解决方法?

Sha*_*ler 6

事实证明,这是在Web场环境中使用DotNetOpenAuth的问题.

在创建OpenIdRelyingParty时,请确保在构造函数中传递null.

这会使您的网站进入OpenID无状态或"哑"模式.用户登录时速度稍慢(如果您注意到的话)但是您必须编写IRelyingPartyApplicationStore以允许DotNetOpenAuth在您的服务器场中工作;

var openIdRelyingParty = new OpenIdRelyingParty(null);
Run Code Online (Sandbox Code Playgroud)

  • 我怀疑这可能会引入安全漏洞.有人可以证实吗? (2认同)

小智 5

所有这些讨论围绕以下问题展开:

依赖方(RP)如何确保包含身份验证令牌的请求来自他将用户请求转发给的OP(OpenId Provider)?

以下步骤说明了它的发生方式

  1. 在我们的案例中,用户请求来自答复方(RP),我们的网站
  2. 应用程序在本地签名存储(LSS)中存储与此用户对应的唯一签名,然后将此签名嵌入到消息中并将此消息转发给OpenId Provider(OP)
  3. 用户键入他的凭据并且OP对其消息进行身份验证,然后将此消息(其中仍然嵌入了签名)转发回RP
  4. RP将嵌入在Message中的签名与LSS中的签名进行比较,如果它们匹配,则RP对用户进行身份验证

如果LSS在消息从OP返回之前消失(某种程度上),则RP没有任何内容可以比较签名,因此无法对用户进行身份验证并抛出错误:消息签名不正确.

LSS如何消失:

  1. ASP.net刷新应用程序池
  2. IIS重新启动
  3. 在Web场中,Message由托管在不同服务器上的应用程序提供服务

这个问题的两个解决方案:

  1. RP以哑模式运行

    一个.它不在本地存储和签名,因此不使用签名比较来确保消息来自他转发给用户进行身份验证的OP

    相反,一旦RP从OP接收到认证消息,它就将消息发送回OP并要求他检查他是否是认证该用户并且是消息的发起者的人.如果OP回答是,我是此消息的发起人,我创建了此消息,然后用户通过RP进行身份验证

  2. 实现你自己的持久性存储,它不会消失,无论ASP.net对进程做什么,就像使用SQL存储会话状态一样.