Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由于iOS 10中的nonce计数错误,HTTP摘要身份验证失败_Ios_Xcode_Http_Authentication_Nsurlsession - Fatal编程技术网

由于iOS 10中的nonce计数错误,HTTP摘要身份验证失败

由于iOS 10中的nonce计数错误,HTTP摘要身份验证失败,ios,xcode,http,authentication,nsurlsession,Ios,Xcode,Http,Authentication,Nsurlsession,由于NSURLSession生成的Authorization:digest头中的nonce计数错误,自iOS 10以来,HTTP摘要身份验证不再在我们的应用程序中工作 同样的代码在iOS 9中工作,但在iOS 10中无法进行身份验证 使用NSURLRequest创建POST请求 用nsursession启动它 在urlSession(\uuu0:didReceive:completionHandler:)中处理NSURLAuthenticationMethodHTTPDigestdelegate

由于NSURLSession生成的Authorization:digest头中的nonce计数错误,自iOS 10以来,HTTP摘要身份验证不再在我们的应用程序中工作

同样的代码在iOS 9中工作,但在iOS 10中无法进行身份验证

  • 使用NSURLRequest创建POST请求
  • 用nsursession启动它
  • urlSession(\uuu0:didReceive:completionHandler:)中处理NSURLAuthenticationMethodHTTPDigest
    delegate
  • 服务器按预期使用401和qop=“auth”字符串进行响应
  • 应用程序再次请求,并设置了Authorization:Digest标头

    根据:

    暂时计数

    如果发送qop指令(见上文),则必须指定此项,并且 如果服务器未在中发送qop指令,则不能指定 WWW验证标头字段。nc值为十六进制 请求数的计数(包括当前请求) 客户端已在此请求中使用nonce值发送的。对于 例如,在响应给定nonce而发送的第一个请求中 值时,客户端发送“nc=00000001”。目的 指令允许服务器通过 维护此计数的自身副本-如果相同的nc值 看到两次,则请求是重播。请参见说明 下面是请求摘要值的构造

    但是,即使对于iOS 10中的第一个请求,nonce计数也从“nc=00000002”开始,这会导致服务器拒绝它

  • 期望服务器响应200 OK

  • iOS 9及之前的版本:

    POST /Tunnel/Message.aspx HTTP/1.1
    Host: 172.18.70.12:3454
    Accept: */*
    Content-Type: application/xml
    User-Agent: iViewer/1 CFNetwork/758.5.3 Darwin/15.6.0
    Connection: keep-alive
    Cookie: 
    AuthType: digest
    Accept-Language: zh-tw
    Content-Length: 69
    Accept-Encoding: gzip, deflate
    Authorization: Digest username="admin", realm="ND8422P", 
    nonce="cc17a78cdd96d54e012eadefe7d13d82", uri="/Tunnel/Message.aspx", 
    response="51587db4bcf6eeece68c4ec21108f170", 
    cnonce="47b8df8a980f280038834b7817250e90", nc=00000001, qop="auth"
    <?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
    
    HTTP/1.0 200 OK
    Cache-Control: no-store, no-cache, must-revalidate
    Cache-Control: post-check=0, pre-check=0
    Pragma: no-cache
    Content-Type: text/xml
    Content-Length: 1127
    
    POST /Tunnel/Message.aspx HTTP/1.1
    Host: 172.18.70.12:3454
    Accept: */*
    Content-Type: application/xml
    User-Agent: iViewer/1 CFNetwork/808.0.2 Darwin/16.0.0
    Connection: keep-alive
    Cookie: 
    AuthType: digest
    Accept-Language: en-us
    Content-Length: 69
    Accept-Encoding: gzip, deflate
    Authorization: Digest username="admin", realm="ND8422P", 
    nonce="4b8bf8549da0c3010f031472e95f387d", uri="/Tunnel/Message.aspx", 
    response="91cf44bc0aadf2f743164d03b5c708c7", 
    cnonce="b5f9e6c69e19c1b396298d68f2aefe7e", nc=00000002, qop="auth"
    <?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
    
    HTTP/1.0 401 Unauthorized
    WWW-Authenticate: Digest qop="auth", realm="ND8422P", nonce="8e8b0538bb08876ac4d8203f1d14e9ac"
    CSeq: 0
    
    POST/Tunnel/Message.aspx HTTP/1.1
    主持人:172.18.70.12:3454
    接受:*/*
    内容类型:application/xml
    用户代理:iViewer/1 CFNetwork/758.5.3 Darwin/15.6.0
    连接:保持活力
    曲奇:
    AuthType:摘要
    接受语言:zh tw
    内容长度:69
    接受编码:gzip,deflate
    授权:摘要username=“admin”,realm=“ND8422P”,
    nonce=“cc17a78cdd96d54e012eadefe7d13d82”,uri=“/Tunnel/Message.aspx”,
    response=“51587db4bcf6eeece68c4ec21108f170”,
    cnonce=“47b8df8a980f28003834b7817250e90”,nc=00000001,qop=“auth”
    HTTP/1.0 200正常
    缓存控制:没有存储,没有缓存,必须重新验证
    缓存控制:后检查=0,预检查=0
    Pragma:没有缓存
    内容类型:text/xml
    内容长度:1127
    
    iOS 10:

    POST /Tunnel/Message.aspx HTTP/1.1
    Host: 172.18.70.12:3454
    Accept: */*
    Content-Type: application/xml
    User-Agent: iViewer/1 CFNetwork/758.5.3 Darwin/15.6.0
    Connection: keep-alive
    Cookie: 
    AuthType: digest
    Accept-Language: zh-tw
    Content-Length: 69
    Accept-Encoding: gzip, deflate
    Authorization: Digest username="admin", realm="ND8422P", 
    nonce="cc17a78cdd96d54e012eadefe7d13d82", uri="/Tunnel/Message.aspx", 
    response="51587db4bcf6eeece68c4ec21108f170", 
    cnonce="47b8df8a980f280038834b7817250e90", nc=00000001, qop="auth"
    <?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
    
    HTTP/1.0 200 OK
    Cache-Control: no-store, no-cache, must-revalidate
    Cache-Control: post-check=0, pre-check=0
    Pragma: no-cache
    Content-Type: text/xml
    Content-Length: 1127
    
    POST /Tunnel/Message.aspx HTTP/1.1
    Host: 172.18.70.12:3454
    Accept: */*
    Content-Type: application/xml
    User-Agent: iViewer/1 CFNetwork/808.0.2 Darwin/16.0.0
    Connection: keep-alive
    Cookie: 
    AuthType: digest
    Accept-Language: en-us
    Content-Length: 69
    Accept-Encoding: gzip, deflate
    Authorization: Digest username="admin", realm="ND8422P", 
    nonce="4b8bf8549da0c3010f031472e95f387d", uri="/Tunnel/Message.aspx", 
    response="91cf44bc0aadf2f743164d03b5c708c7", 
    cnonce="b5f9e6c69e19c1b396298d68f2aefe7e", nc=00000002, qop="auth"
    <?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
    
    HTTP/1.0 401 Unauthorized
    WWW-Authenticate: Digest qop="auth", realm="ND8422P", nonce="8e8b0538bb08876ac4d8203f1d14e9ac"
    CSeq: 0
    
    POST/Tunnel/Message.aspx HTTP/1.1
    主持人:172.18.70.12:3454
    接受:*/*
    内容类型:application/xml
    用户代理:iViewer/1 CFNetwork/808.0.2 Darwin/16.0.0
    连接:保持活力
    曲奇:
    AuthType:摘要
    接受语言:en us
    内容长度:69
    接受编码:gzip,deflate
    授权:摘要username=“admin”,realm=“ND8422P”,
    nonce=“4b8bf8549da0c3010f031472e95f387d”,uri=“/Tunnel/Message.aspx”,
    response=“91cf44bc0aadf2f743164d03b5c708c7”,
    cnonce=“b5f9e6c69e19c1b396298d68f2aefe7e”,nc=00000002,qop=“auth”
    HTTP/1.0 401未经授权
    WWW-Authenticate:Digest qop=“auth”,realm=“ND8422P”,nonce=“8e8b0538bb08876ac4d8203f1d14e9ac”
    CSeq:0
    
    有人面临同样的问题吗

    我能找到的唯一相关帖子是: ,但没有进一步的资料

    如何在不要求服务器端忽略错误的nonce计数的情况下修复它或在客户端应用程序端找到解决方法


    谢谢。

    很可能,操作系统首先发送HEAD请求,而您的服务器端代码没有收到它。我会试着运行Charles Proxy来验证这是怎么回事


    这就是说,跳过一个nonce计数本质上并不表示存在任何类型的攻击。即使在iOS 9中,如果请求以某种方式丢失(例如网络错误),也可能发生这种情况。重要的是确保计数不会倒退。因此,我认为您的服务器代码有缺陷,不应该一开始就拒绝使用。

    苹果开发人员技术支持确认这是iOS 10的缺陷。 希望很快能修好

    感谢您联系Apple开发者技术支持(DTS)。 我们认为这个问题是一个bug。请使用bug Reporter工具提交bug报告

    更新:
    苹果在iOS 10.2 Beta 3中解决了这个问题。我们公司也有同样的问题,如下所述:


    我们可以在iOS 10设备的应用程序和Safari浏览器中重现该问题。似乎没有简单的客户端解决方法。我们在苹果公司打开了一个Bug报告

    在我们的例子中,10.2 Beta版解决了这个问题

    你说得对。跳过当前计数是个坏主意。尽管iOS 10确实从nc=00000002发送了第一个auth请求start,但苹果工程师刚刚确认这是一个bug。我们发现我们的服务器代码可能会拒绝任何不是从nc=00000001开始的身份验证请求,这也可能是错误的。在iOS 10.2 Beta 3中看起来已修复