2022年07月17日

Nextcloudが突然不調(つづき)

 Nextcloud に突然ログインできなくなった件の続きです。いろいろ調べまくった。Nextcloud Desktop Client のビルドまでやった(これはこれでめっちゃ大変だった)。デバッガ配下で実行してみたけど、あまり有用な情報は得られず。Nextcloud のログインの流れについて調べていると、開発用ドキュメントに記載があることに気づいたので、curl で調べてみた。これなら、一段階ごとに何が起きているか理解しやすくなる。

(1) Login flow v2 のエントリーポイントにアクセスする。

$ curl -X POST https://xxxx.xxxxxx.xxx/index.php/login/v2
{"poll":
  {"token":"cxl...KVt", (途中省略)
   "endpoint":"https:\/\/xxxx.xxxxxx.xxx\/index.php\/login\/v2\/poll"},
 "login":"https:\/\/xxxx.xxxxxx.xxx\/index.php\/login\/v2\/flow\/ivg...NoV"}

(2) "login" URL にブラウザでアクセスする。いつもの認証画面が開く。

$ open -a "Firefox" https://xxxx.xxxxxx.xxx/index.php/login/v2/flow/ivg...NoV

(3) ポーリングを行う。token の値は (1) で返されたもの。(2) で認証が済んでいれば、1回目で成功する。(認証が済むまでは 404 が返されるはず)

$ curl -X POST https://xxxx.xxxxxx.xxx/index.php/login/v2/poll -d "token:cxl...KVt"
{"server": "https://xxxx.xxxxxx.xxx",
 "loginName":"nagata",
 "appPassword":"iQY...enl"}

(4) (3) で返されたログイン名とパスワードを使ってファイルリストを取得する。

$ curl -u nagata:iQY...enl https://xxxx.xxxxxx.xxx/remote.php/dav/files/nagata// -X PROPFIND
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
  <s:message>No public access to this resource., No 'Authorization: Basic' header found. Either the 
client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. 
Either the client didn't send one, or the server is mis-configured, No 'Authorization: Basic' 
header found. Either the client didn't send one, or the server is misconfigured</s:message>
</d:error>

 エラーが出た。"Authorization: Basic" ヘッダがない、と言っている。送ってないのか? curl -v で確かめてみる。

$ curl -v -u nagata:gxz...SOa https://xxxx.xxxxxx.xxx/remote.php/dav/files/tnagata
* ...(略)...
* Server auth using Basic with user 'nagata'
* Using Stream ID: 1 (easy handle 0x7fc940000400)
> GET /remote.php/dav/files/nagata HTTP/2
> Host: xxxx.xxxxxx.xxx
> Authorization: Basic ... ← 送ってるやん??
> User-Agent: curl/7.54.0
> Accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 401 
...(中略)...
* Authentication problem. Ignoring this.
< www-authenticate: Basic realm="Nextcloud", charset="UTF-8"
< set-cookie:(略)

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
  <s:message>No public access to this resource., No 'Authorization: Basic' header found. Either the 
client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. 
Either the client didn't send one, or the server is mis-configured, No 'Authorization: Basic' 
header found. Either the client didn't send one, or the server is misconfigured</s:message>
</d:error>

 どうもおかしい。途中で HTTP ヘッダが落とされてないか? リクエストヘッダを全部表示する PHP スクリプトを書いて試してみた。

[allheaders.php]
<pre>
<?php
foreach(getallheaders() as $name => $value) {
  echo "$name : $value\n";
}
?>
</pre>

 curl -u"Authorization: Basic" ヘッダを送ってみた。


$ curl -v -u nagata:pass http://xxxx.xxxxxx.xxx/allheaders.php
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
* Connected to xxxx.xxxxxx.xxx (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'nagata'
> GET /allheaders.php HTTP/1.1
> Host: xxxx.xxxxxx.xxx
> Authorization: Basic bmFnYXRhOnBhc3M= ← 送っている。
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sun, 17 Jul 2022 09:13:05 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Server: Apache
< X-Powered-By: PHP/7.4.30
< Vary: Range,Accept-Encoding
< Accept-Ranges: none
< 
<pre>
Host : xxxx.xxxxxx.xxx
X-Forwarded-Host : xxxx.xxxxxx.xxx
X-Forwarded-For : yyy.yyy.yyy.yyy
X-Forwarded-Proto : http
X-Backend : lit###.phy.lolipop.lan
User-Agent : curl/7.54.0
Accept : */*
</pre>

 curl は送ったと言ってるのに、PHP には見えてない。これはサーバ側の設定で落とされてるんじゃないか?

 今回はここまで。サーバ側の設定について、ロリポップに問い合わせてみる予定です。

Posted at 2022年07月17日 19:08:37
email.png