]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Add server capabilities for checksums #4638
authorChristian Kamm <mail@ckamm.de>
Tue, 12 Apr 2016 08:12:35 +0000 (10:12 +0200)
committerChristian Kamm <mail@ckamm.de>
Fri, 15 Apr 2016 08:58:14 +0000 (10:58 +0200)
* Add checksums/supportedTypes and checksums/preferredUploadType
  capabilities. The default is that no checksum types are supported.

* Remove the transmissionChecksum config option. Servers must now
  use the capabilities to indicate that they are fine with the
  client sending checksums.

Note: This intentionally breaks brandings that overrode
Theme::transmissionChecksum. The override must be removed and the
server's capabilities must be adjusted to include the new values.

src/libsync/capabilities.cpp
src/libsync/capabilities.h
src/libsync/checksums.cpp
src/libsync/checksums.h
src/libsync/configfile.cpp
src/libsync/configfile.h
src/libsync/owncloudpropagator.cpp
src/libsync/propagatedownload.cpp
src/libsync/propagateupload.cpp
src/libsync/theme.cpp
src/libsync/theme.h

index d6d2eafd58e02ca8dd0a075577f5102fdb9cf4f0..0dfff767efd529698a0a9cc2724b99661113cad7 100644 (file)
@@ -81,28 +81,18 @@ bool Capabilities::isValid() const
     return !_capabilities.isEmpty();
 }
 
-QList<QByteArray> Capabilities::supportedChecksumTypesAdvertised() const
-{
-    return QList<QByteArray>();
-}
-
 QList<QByteArray> Capabilities::supportedChecksumTypes() const
 {
-    auto list = supportedChecksumTypesAdvertised();
-    QByteArray cfgType = ConfigFile().transmissionChecksum().toLatin1();
-    if (!cfgType.isEmpty()) {
-        list.prepend(cfgType);
+    QList<QByteArray> list;
+    foreach (const auto & t, _capabilities["checksums"].toMap()["supportedTypes"].toList()) {
+        list.push_back(t.toByteArray());
     }
     return list;
 }
 
-QByteArray Capabilities::preferredChecksumType() const
+QByteArray Capabilities::preferredUploadChecksumType() const
 {
-    auto list = supportedChecksumTypes();
-    if (list.isEmpty()) {
-        return QByteArray();
-    }
-    return list.first();
+    return _capabilities["checksums"].toMap()["preferredUploadType"].toByteArray();
 }
 
 }
index c3297f22438d6dc7b47b99e2b658b8b113c16dd5..70290bf976b5c37159d64d0f428569c652e3afd1 100644 (file)
@@ -46,14 +46,28 @@ public:
     /// returns true if the capabilities are loaded already.
     bool isValid() const;
 
-    /// Returns the checksum types the server explicitly advertises
-    QList<QByteArray> supportedChecksumTypesAdvertised() const;
-
-    /// Like supportedChecksumTypesRaw(), but includes the type from the config
+    /**
+     * Returns the checksum types the server understands.
+     *
+     * When the client uses one of these checksumming algorithms in
+     * the OC-Checksum header of a file upload, the server will use
+     * it to validate that data was transmitted correctly.
+     *
+     * Path: checksums/supportedTypes
+     * Default: []
+     * Possible entries: "Adler32", "MD5", "SHA1"
+     */
     QList<QByteArray> supportedChecksumTypes() const;
 
-    /// Returns the checksum type that should be used for new uploads.
-    QByteArray preferredChecksumType() const;
+    /**
+     * The checksum algorithm that the server recommends for file uploads.
+     * This is just a preference, any algorithm listed in supportedTypes may be used.
+     *
+     * Path: checksums/preferredUploadType
+     * Default: empty, meaning "no preference"
+     * Possible values: empty or any of the supportedTypes
+     */
+    QByteArray preferredUploadChecksumType() const;
 
 private:
     QVariantMap _capabilities;
index 99101fd244b1e9d8bbc35ea76a509b47fadfdccd..3a17825ad8a6582bbf622b5f43b47629d9d05d1c 100644 (file)
@@ -17,6 +17,7 @@
 #include "syncfileitem.h"
 #include "propagatorjobs.h"
 #include "account.h"
+#include "configfile.h"
 
 #include <qtconcurrentrun.h>
 
@@ -108,10 +109,10 @@ bool uploadChecksumEnabled()
     return enabled;
 }
 
-bool downloadChecksumEnabled()
+bool downloadChecksumValidationEnabled()
 {
-    static bool enabled = qgetenv("OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD").isEmpty();
-    return enabled;
+    static bool disabledByConfig = ConfigFile().disableDownloadChecksumValidation();
+    return !disabledByConfig;
 }
 
 QByteArray contentChecksumType()
index 519c74b71701507e3a37e6dbd13eeb78758360e4..670e3c0b418037fe621a0c18da80525cd7e9f6d5 100644 (file)
@@ -34,8 +34,8 @@ bool parseChecksumHeader(const QByteArray& header, QByteArray* type, QByteArray*
 /// Checks OWNCLOUD_DISABLE_CHECKSUM_UPLOAD
 bool uploadChecksumEnabled();
 
-/// Checks OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD
-bool downloadChecksumEnabled();
+/// Checks disableDownloadChecksumValidation from the config file
+bool downloadChecksumValidationEnabled();
 
 /// Checks OWNCLOUD_CONTENT_CHECKSUM_TYPE (default: SHA1)
 QByteArray contentChecksumType();
index a0c5b144282c209b13ae328eaea5ffb212ca82fc..931349a98c1d57c8922fe7ea20207d92e10d513a 100644 (file)
@@ -52,7 +52,7 @@ static const char updateCheckIntervalC[] = "updateCheckInterval";
 static const char geometryC[] = "geometry";
 static const char timeoutC[] = "timeout";
 static const char chunkSizeC[] = "chunkSize";
-static const char transmissionChecksumC[] = "transmissionChecksum";
+static const char disableDownloadChecksumValidationC[] = "disableDownloadChecksumValidation";
 
 static const char proxyHostC[] = "Proxy/host";
 static const char proxyTypeC[] = "Proxy/type";
@@ -129,18 +129,15 @@ quint64 ConfigFile::chunkSize() const
     return settings.value(QLatin1String(chunkSizeC), 10*1000*1000).toLongLong(); // default to 10 MB
 }
 
-QString ConfigFile::transmissionChecksum() const
+bool ConfigFile::disableDownloadChecksumValidation() const
 {
     QSettings settings(configFile(), QSettings::IniFormat);
 
-    QString checksum = settings.value(QLatin1String(transmissionChecksumC), QString()).toString();
-
-    if( checksum.isEmpty() ) {
-        // if the config file setting is empty, maybe the Branding requires it.
-        checksum = Theme::instance()->transmissionChecksum();
+    QVariant value = settings.value(QLatin1String(disableDownloadChecksumValidationC));
+    if (!value.isValid()) {
+        return false;
     }
-
-    return checksum;
+    return value.toBool();
 }
 
 void ConfigFile::setOptionalDesktopNotifications(bool show)
index d45a9693ff3cf7251cedc763981e3a5100260cf5..361a82b13c708da0b133349dff401fb9294e2e8a 100644 (file)
@@ -114,11 +114,13 @@ public:
     int timeout() const;
     quint64 chunkSize() const;
 
-    // send a checksum as a header along with the transmission or not.
-    // possible values:
-    // empty: no checksum calculated or expected.
-    // or "Adler32", "MD5", "SHA1"
-    QString transmissionChecksum() const;
+    /** Whether to disable download checksum validation.
+     *
+     * By default (false) received checksums will be validated. This flag
+     * can disable checksum validation and is intended for debugging purposes
+     * only.
+     */
+    bool disableDownloadChecksumValidation() const;
 
     void saveGeometry(QWidget *w);
     void restoreGeometry(QWidget *w);
index 04e592f9d50c646f3504234d7f0fdf1b52abbdf4..dce440391f32a8dfda436755111f0db9f7d4e1af 100644 (file)
@@ -299,21 +299,6 @@ void OwncloudPropagator::start(const SyncFileItemVector& items)
 {
     Q_ASSERT(std::is_sorted(items.begin(), items.end()));
 
-    /* Check and log the transmission checksum type */
-    ConfigFile cfg;
-    const QString checksumType = cfg.transmissionChecksum();
-
-    /* if the checksum type is empty, it is not sent. No error */
-    if( !checksumType.isEmpty() ) {
-        if( checksumType == checkSumAdlerC ||
-                checksumType == checkSumMD5C    ||
-                checksumType == checkSumSHA1C ) {
-            qDebug() << "Client sends transmission checksum type" << checksumType;
-        } else {
-            qWarning() << "Unknown transmission checksum type from config" << checksumType;
-        }
-    }
-
     /* This builds all the jobs needed for the propagation.
      * Each directory is a PropagateDirectory job, which contains the files in it.
      * In order to do that we loop over the items. (which are sorted by destination)
index eb804203bb810b22a399b008256442cdec669350..41170b6afcb4e52d9d8fefe6f057028870afac57 100644 (file)
@@ -555,7 +555,7 @@ void PropagateDownloadFileQNAM::slotGetFinished()
     connect(validator, SIGNAL(validationFailed(QString)),
             SLOT(slotChecksumFail(QString)));
     auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
-    if (!downloadChecksumEnabled()) {
+    if (!downloadChecksumValidationEnabled()) {
         checksumHeader.clear();
     }
     validator->start(_tmpFile.fileName(), checksumHeader);
index b11c47707ad28af6798a761980c1c78a6eeb7cec..f46bf28b3b24d962d94b96be9b6ee0dc6ffd7d21 100644 (file)
@@ -261,7 +261,7 @@ void PropagateUploadFileQNAM::slotComputeTransmissionChecksum(const QByteArray&
     // Compute the transmission checksum.
     auto computeChecksum = new ComputeChecksum(this);
     if (uploadChecksumEnabled()) {
-        computeChecksum->setChecksumType(_propagator->account()->capabilities().preferredChecksumType());
+        computeChecksum->setChecksumType(_propagator->account()->capabilities().preferredUploadChecksumType());
     } else {
         computeChecksum->setChecksumType(QByteArray());
     }
index e2f673b6269a8de34bbddd8a784812cabfe84c08..3b6eea9effdbc77b0e589ec04f91b30f416a67b7 100644 (file)
@@ -248,11 +248,6 @@ QString Theme::updateCheckUrl() const
     return QLatin1String("https://updates.owncloud.com/client/");
 }
 
-QString Theme::transmissionChecksum() const
-{
-    return QString::null; // No transmission by default.
-}
-
 qint64 Theme::newBigFolderSizeLimit() const
 {
     // Default to 500MB
index c9df0145304bf3939c1a50ad437b76856de8a458..b57afb62ea47495317fd293f9d919d1848e3932e 100644 (file)
@@ -204,14 +204,6 @@ public:
      * to nothing selected
      */
     virtual bool wizardSelectiveSyncDefaultNothing() const;
-    /**
-     * @brief Add an additional checksum header to PUT requests and compare them
-     * if they come with GET requests.
-     * This value sets the checksum type (SHA1, MD5 or Adler32) or is left empty
-     * if no checksumming is wanted. In that case it can still be overwritten in
-     * the client config file.
-     */
-    virtual QString transmissionChecksum() const;
 
     /**
      * Default option for the newBigFolderSizeLimit.