andig / carddav2fb

Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box
63 stars 19 forks source link

REPORT: CARDDAV:filter required on Synlogy #167

Closed Cetartiodactyla closed 4 years ago

Cetartiodactyla commented 4 years ago

Bekomme beim Download der vCards einen Bad Request zurück. Der CardDAV Server läuft auf einer Synology Disk Station. Über den Browser kein Problem mit der definierten URL.

❯ ./carddav2fb run
Downloading recent FRITZ!Box phonebook
Save internal data from recent FRITZ!Box phonebook!
PHP Warning:  ftp_close(): SSL_read on shutdown: Connection reset by peer (54) in /Users/florian/bin/carddav2fb/src/functions.php on line 613

Warning: ftp_close(): SSL_read on shutdown: Connection reset by peer (54) in /Users/florian/bin/carddav2fb/src/functions.php on line 613
Phone numbers with special attributes saved
Downloading vCard(s) from account gkontakte
    0 [>---------------------------]*   Trying 192.168.1.10:8443...
* TCP_NODELAY set
* Connected to server.firma.de (192.168.1.10) port 8443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: /usr/local/etc/openssl@1.1/certs
* SSL connection using TLSv1.2 / AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=server.firma.de
*  start date: Oct 20 05:11:08 2019 GMT
*  expire date: Jan 18 05:11:08 2020 GMT
*  subjectAltName: host "server.firma.de" matched cert's "server.firma.de"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> REPORT /addressbooks/users/kontakte/addressbook/ HTTP/1.1
Host: server.firma.de:8443
Depth: 1
User-Agent: GuzzleHttp/6.4.1 curl/7.66.0 PHP/7.3.11
Authorization: Basic Z2tvbvRha3RlEQZXdW05WGNUR3lENA==
Content-Length: 239

* upload completely sent off: 239 out of 239 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Date: Tue, 05 Nov 2019 14:41:13 GMT
< DAV: 1, access-control, addressbook, extended-mkcol, calendarserver-principal-property-search, calendarserver-principal-search, calendarserver-home-sync
< Server: Twisted/13.0.0 TwistedWeb/9.0.0
< Content-Length: 115
< Strict-Transport-Security: max-age=604800
< Content-Type: text/html;charset=utf-8
< Connection: close
<
* Closing connection 0

In RequestException.php line 113:

  Client error: `REPORT https://server.firma.de:8443/addressbooks/users/kontakte/addressbook/` resulted in a `400 Bad Request` response: 
  <html><head><title>Bad Request</title></head><body><h1>Bad Request</h1><p>CARDDAV:filter required</p></body></html>                             

run [-i|--image] [-l|--local [LOCAL]] [-c|--config CONFIG]
andig commented 4 years ago

Du scheinst da mehrere Probleme zu haben:

PHP Warning: ftp_close(): SSL_read on shutdown: Connection reset by peer (54) in /Users/florian/bin/carddav2fb/src/functions.php on line 613

Komisch- SSL Fehler?

Der CardDAV Server läuft ...

Was für ein Server ist das? Scheint als würde er einen Filter erwarten (https://github.com/trevor/calendarserver/blob/master/twistedcaldav/carddavxml.py#L264), den wir nicht setzen. Mit andere Servern geht es.

Cetartiodactyla commented 4 years ago

Kann mich per FTP-SSL über Cyberduck ohne Probleme einloggen. Hatte bisher allerdings in der config eine http URL eingegeben. Habe die nun auf https gesetzt und den Zertifikatscheck deaktiviert. In den Ordner FRITZ/mediabox wird auch etwas geschrieben. Den Fehler bekomme ich aber trotzdem.

Zum CardDAV Server kann ich nichts näheres sagen, außer, dass es sich um das Synology Paket handelt. https://www.synology.com/de-de/knowledgebase/DSM/help/CardDAVServer/carddav_server_desc

Welche Filter könnten das denn sein?

andig commented 4 years ago

Welche Filter könnten das denn sein?

Vmtl. gem. https://tools.ietf.org/html/rfc6352#page-40. Andere CardDAV Server brauchen das nicht- da bist Du also auf Dich gestellt was da notwendig ist.

SpamReceiver commented 4 years ago

I would like to point to another occurrence of the same symptom: https://github.com/andig/carddav2fb/pull/172#issuecomment-552186172

PHP Warning: ftp_close(): SSL_read on shutdown: Connection reset by peer (104) in .../carddav2fb/src/functions.php on line 289 PHP Warning: ftp_close(): SSL_read on shutdown: Connection reset by peer (54) in .../carddav2fb/src/functions.php on line 613

This output is written to stderr, so my cron job fails every day which is a bit annoying. I would be happy to have a fix for it. Thank you very much.

andig commented 4 years ago

I would like to point to another occurrence of the same symptom:

Feel free to test https://github.com/andig/carddav2fb/pull/175 and/or donate for keeping the project alive ;)

develth commented 4 years ago

Hab hier ein ähnliches Problem mit SOGo:

Downloading vCard(s) from account thomas@account.de
    0 [>---------------------------]
In RequestException.php line 113:
Client error: `REPORT https://myserver.de/SOGo/dav/thomas@account.de/Contacts/personal/` resulted in a `400 Request Failed` response:
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body><h3>An error occurred duri (truncated...)

This could be the full message:

<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <h3>An error occurred during object publishing</h3>
    <p>XML entity expected for WebDAV REPORT.</p>
</body>

</html>
develth commented 4 years ago

It worked when i set Content-Type to application/xml

andig commented 4 years ago

@develth would you mind opening a PR?

develth commented 4 years ago

@andig will open when i fixed it

andig commented 4 years ago

It should be possible to add the header directly to the config file without coding:

'server' => [
    [
        'url' => 'https://...',
        'user' => '',
        'password' => '',
        'http' => [           // http client options are directly passed to Guzzle http client
            // 'verify' => false, // uncomment to disable certificate check
            // 'auth' => 'digest', // uncomment for digest auth
            'headers' => [
                'Content-Type' => 'application/xml',
            ],
        ]
    ],
develth commented 4 years ago

I already fixed it in src/CardDav/Backend.php

$response = $this->getCachedClient()->request('REPORT', $this->url, [
                'headers' => [
                    'Content-Type' => 'text/xml'
                ],
                'body' => <<<EOD
<?xml version="1.0" encoding="utf-8"?>
<C:addressbook-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
    <D:prop>
        <D:getetag/>
        <C:address-data content-type="text/vcard"/>
    </D:prop>
</C:addressbook-query>
EOD
            ]);

I don´t think that we need that in config, because there is a fixed xml body. Will create PR in next step. Was Bugfixing another stuff, i create a separate ticket for that.

andig commented 4 years ago

Could you check if that works with auth options that might be defined in the config?

Viele Grüße, Andreas

Am 09.01.2020 um 09:02 schrieb Thomas notifications@github.com:

 I already fixed it in src/CardDav/Backend.php

$response = $this->getCachedClient()->request('REPORT', $this->url, [ 'headers' => [ 'Content-Type' => 'text/xml' ], 'body' => <<<EOD <?xml version="1.0" encoding="utf-8"?>

EOD ]); I don´t think that we need that in config, because there is a fixed xml body. Will create PR in next step. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
develth commented 4 years ago

If i change auth to digest it fails - so options from config will be set - it works!

matzesa commented 4 years ago

zum Problem CARDDAV:filter required auf Synology: Ich habe die Backend.php angepasst um <C:filter/>, dann gab es keinen Fehler von der Synology-Box mehr. Leider war das XML das zurückkam nicht valide, da scheint ein Fehler bei Synology vorzuliegen. Mit Suchen&Ersetzen habe ich das XML angepasst. Nicht schön, funktioniert aber für mich vorerst.

        if (strpos($body, "<'>")) {
            $body = str_replace("<ietf:params:xml:ns:carddav'>", "<address-data>", $body);
            $body = str_replace("<'>", "<multistatus>", $body);
        }
andig commented 4 years ago

@matzesa please join the discussion here https://github.com/andig/carddav2fb/issues/188

molfi commented 4 years ago

Face the same problem with carddav2fb with Synology CardDAV Server. As the problem apparently is seen on Synology side and wont be fixed in carddav2fb code base (which is totally fine for me) let me please just make matzesa´s hint more clear for non developers (like me ;-)). This is the excerpt of the Backend.php how it works on my end after finding the right place in the code - hope its how matzesa intended it to be.

image

Wish you good day ... and thanks for this nice cool tool.

andig commented 4 years ago

As the problem apparently is seen on Synology side and wont be fixed in carddav2fb code base (which is totally fine for me) let me please just make matzesa´s hint more clear for non developers (like me ;-)).

It should be fixed upstream. Did anybody try to open an issue there?

molfi commented 4 years ago

Hi

The term „Upstream“ is not known to me, sorry. Do you mean opening a „ticket“ with synology support?

If yes, then what is the argumentation? Should i raise their awareness that their CardDAV Server implementation is assuming the XML filter element being mandatory which seems to be too strict according to IETF RFC?