Skip to content

Commit

Permalink
Merge pull request #4663 from 'ckamm/disabletransmissionchecksum'
Browse files Browse the repository at this point in the history
Disable validation of transmission checksums by default
  • Loading branch information
ogoffart committed Apr 21, 2016
2 parents 1935c78 + fa69d08 commit 522f7af
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 83 deletions.
20 changes: 5 additions & 15 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
26 changes: 20 additions & 6 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,28 @@ class OWNCLOUDSYNC_EXPORT Capabilities {
/// 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;
Expand Down
6 changes: 0 additions & 6 deletions src/libsync/checksums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ bool uploadChecksumEnabled()
return enabled;
}

bool downloadChecksumEnabled()
{
static bool enabled = qgetenv("OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD").isEmpty();
return enabled;
}

QByteArray contentChecksumType()
{
static QByteArray type = qgetenv("OWNCLOUD_CONTENT_CHECKSUM_TYPE");
Expand Down
3 changes: 0 additions & 3 deletions src/libsync/checksums.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ bool parseChecksumHeader(const QByteArray& header, QByteArray* type, QByteArray*
/// Checks OWNCLOUD_DISABLE_CHECKSUM_UPLOAD
bool uploadChecksumEnabled();

/// Checks OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD
bool downloadChecksumEnabled();

/// Checks OWNCLOUD_CONTENT_CHECKSUM_TYPE (default: SHA1)
QByteArray contentChecksumType();

Expand Down
15 changes: 0 additions & 15 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ 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 proxyHostC[] = "Proxy/host";
static const char proxyTypeC[] = "Proxy/type";
Expand Down Expand Up @@ -129,20 +128,6 @@ quint64 ConfigFile::chunkSize() const
return settings.value(QLatin1String(chunkSizeC), 10*1000*1000).toLongLong(); // default to 10 MB
}

QString ConfigFile::transmissionChecksum() 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();
}

return checksum;
}

void ConfigFile::setOptionalDesktopNotifications(bool show)
{
QSettings settings(configFile(), QSettings::IniFormat);
Expand Down
6 changes: 0 additions & 6 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
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;

void saveGeometry(QWidget *w);
void restoreGeometry(QWidget *w);

Expand Down
15 changes: 0 additions & 15 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,6 @@ void PropagateDownloadFileQNAM::slotGetFinished()
connect(validator, SIGNAL(validationFailed(QString)),
SLOT(slotChecksumFail(QString)));
auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
if (!downloadChecksumEnabled()) {
checksumHeader.clear();
}
validator->start(_tmpFile.fileName(), checksumHeader);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
5 changes: 0 additions & 5 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,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
Expand Down
8 changes: 0 additions & 8 deletions src/libsync/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
* 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.
Expand Down

0 comments on commit 522f7af

Please sign in to comment.