Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.6] Command-line client. Do not trust SSL certificates by default, unless '--trust' option is set. #5030

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ int main(int argc, char **argv)

account->setUrl(hostUrl);
account->setSslErrorHandler(sslErrorHandler);
account->setTrustCertificates(options.trustSSL);

QEventLoop loop;
auto *job = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/capabilities"));
Expand Down
22 changes: 17 additions & 5 deletions src/cmd/simplesslerrorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,29 @@ namespace OCC {

bool SimpleSslErrorHandler::handleErrors(QList<QSslError> errors, const QSslConfiguration &conf, QList<QSslCertificate> *certs, OCC::AccountPtr account)
{
(void)account;
(void)conf;
Q_UNUSED(conf);

if (!certs) {
qDebug() << "Certs parameter required but is NULL!";
if (!account || !certs) {
qDebug() << "account and certs parameters are required!";
return false;
}

if (account->trustCertificates()) {
for (const auto &error : qAsConst(errors)) {
certs->append(error.certificate());
}
return true;
}

bool allTrusted = true;

for (const auto &error : qAsConst(errors)) {
if (!account->approvedCerts().contains(error.certificate())) {
allTrusted = false;
}
certs->append(error.certificate());
}
return true;

return allTrusted;
}
}
10 changes: 10 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,14 @@ bool Account::fileCanBeUnlocked(SyncJournalDb * const journal,
return false;
}

void Account::setTrustCertificates(bool trustCertificates)
{
_trustCertificates = trustCertificates;
}

bool Account::trustCertificates() const
{
return _trustCertificates;
}

} // namespace OCC
5 changes: 5 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject

bool fileCanBeUnlocked(SyncJournalDb * const journal, const QString &folderRelativePath) const;

void setTrustCertificates(bool trustCertificates);
[[nodiscard]] bool trustCertificates() const;

public slots:
/// Used when forgetting credentials
void clearQNAMCache();
Expand Down Expand Up @@ -343,6 +346,8 @@ protected Q_SLOTS:

static QString davPathBase();

bool _trustCertificates = false;

QWeakPointer<Account> _sharedThis;
QString _id;
QString _davUser;
Expand Down