菜鸟教程小白 发表于 2022-12-12 12:07:14

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


                                            <p><p>自 iOS 10 起,HTTP 摘要身份验证在我们的应用程序中不再有效,原因是 Authorization: Digest header generated by NSURLSession 中的 nonce-count 错误。</p>

<p>相同的代码在 iOS 9 中有效,但在 iOS 10 中无法验证</p>

<ol>
<li>使用 NSURLRequest 创建 POST 请求</li>
<li>使用 NSURLSession 触发它</li>
<li>在<code>urlSession(_:didReceive:completionHandler:)中处理NSURLAuthenticationMethodHTTPDigest</code>委托(delegate)</li>
<li>服务器按预期返回 401 和 qop="auth"字符串</li>
<li><p>应用使用 Authorization: Digestheader 再次请求。 </p>

<p>根据<a href="http://www.ietf.org/rfc/rfc2617.txt" rel="noreferrer noopener nofollow">RFC2617</a> :</p>

<blockquote>
<p>nonce-count</p>

<p>This MUST be specified if a qop directive is sent (see above), and
MUST NOT be specified if the server did not send a qop directive in
the WWW-Authenticate header field. The nc-value is the hexadecimal
count of the number of requests (including the current request)
that the client has sent with the nonce value in this request. For
example, in the first request sent in response to a given nonce
value, the client sends &#34;nc=00000001&#34;. The purpose of this
directive is to allow the server to detect request replays by
maintaining its own copy of this count - if the same nc-value is
seen twice, then the request is a replay. See the description
below of the construction of the request-digest value.</p>
</blockquote>

<p>但是,即使对于 iOS 10 中的第一个请求,nonce 计数也从“nc=00000002”开始,这会导致服务器拒绝它。</p></li>
<li><p>期望服务器响应 200 OK</p></li>
</ol>

<p><strong>iOS 9 及之前版本:</strong></p>

<pre><code>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=&#34;admin&#34;, realm=&#34;ND8422P&#34;,
nonce=&#34;cc17a78cdd96d54e012eadefe7d13d82&#34;, uri=&#34;/Tunnel/Message.aspx&#34;,
response=&#34;51587db4bcf6eeece68c4ec21108f170&#34;,
cnonce=&#34;47b8df8a980f280038834b7817250e90&#34;, nc=00000001, qop=&#34;auth&#34;
&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;&lt;GetServerInfo&gt;&lt;/GetServerInfo&gt;

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
</code></pre>

<p><strong>iOS 10:</strong></p>

<pre><code>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=&#34;admin&#34;, realm=&#34;ND8422P&#34;,
nonce=&#34;4b8bf8549da0c3010f031472e95f387d&#34;, uri=&#34;/Tunnel/Message.aspx&#34;,
response=&#34;91cf44bc0aadf2f743164d03b5c708c7&#34;,
cnonce=&#34;b5f9e6c69e19c1b396298d68f2aefe7e&#34;, nc=00000002, qop=&#34;auth&#34;
&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;&lt;GetServerInfo&gt;&lt;/GetServerInfo&gt;

HTTP/1.0 401 Unauthorized
WWW-Authenticate: Digest qop=&#34;auth&#34;, realm=&#34;ND8422P&#34;, nonce=&#34;8e8b0538bb08876ac4d8203f1d14e9ac&#34;
CSeq: 0
</code></pre>

<p>有人遇到同样的问题吗?</p>

<p>我能找到的唯一相关帖子是:
<a href="https://forums.developer.apple.com/thread/50617" rel="noreferrer noopener nofollow">Apple Developer Forums : Problem of the digest authentication</a> ,但没有更多信息。</p>

<p>如何在不要求服务器端忽略错误的 nonce-count 的情况下在客户端应用程序端修复它或获得解决方法?</p>

<p>谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Apple 开发者技术支持确认这是 iOS 10 的错误。
希望尽快修复。</p>

<blockquote>
<p>Thank you for contacting Apple Developer Technical Support (DTS).
We believe this issue is a bug. Please file a bug report using the Bug Reporter tool <a href="https://developer.apple.com/bug-reporting/" rel="noreferrer noopener nofollow">https://developer.apple.com/bug-reporting/</a>.</p>
</blockquote>

<p>更新:
Apple 在 iOS 10.2 Beta 3 中修复了这个问题</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 由于 iOS 10 中的 nonce 计数错误,HTTP 摘要身份验证失败,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39587003/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39587003/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 由于 iOS 10 中的 nonce 计数错误,HTTP 摘要身份验证失败