Commit 645055a6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

qca is required now

parent b0d6479e
......@@ -97,11 +97,6 @@ find_package(Qca-qt5 2.3.0 CONFIG REQUIRED)
option(KDEPIM_RUN_AKONADI_TEST "Enable autotest based on Akonadi." TRUE)
# QT5 package
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED TextToSpeech Network Widgets Test XmlPatterns DBus WebEngineWidgets NetworkAuth)
if (NOT Qca-qt5_FOUND)
message(STATUS "QCA not found, public key authentication will not be supported")
else()
add_definitions(-DHAVE_QCA)
endif()
# KF5 package
......
......@@ -39,10 +39,8 @@ using namespace Mock;
#include <QWebEngineUrlSchemeHandler>
#include <QWebEngineView>
#include <KLocalizedString>
#ifdef HAVE_QCA
#include "ewspkeyauthjob.h"
#endif
#endif
#include <QtWebEngineWidgetsVersion>
#include "ewsclient_debug.h"
......@@ -51,11 +49,9 @@ static const auto o365AccessTokenUrl = QUrl(QStringLiteral("https://login.micros
static const auto o365FakeUserAgent = QStringLiteral("Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36");
static const auto o365Resource = QStringLiteral("https%3A%2F%2Foutlook.office365.com%2F");
#ifdef HAVE_QCA
static const auto pkeyAuthSuffix = QStringLiteral(" PKeyAuth/1.0");
static const auto pkeyRedirectUri = QStringLiteral("urn:http-auth:PKeyAuth");
static const QString pkeyPasswordMapKey = QStringLiteral("pkey-password");
#endif
static const QString accessTokenMapKey = QStringLiteral("access-token");
static const QString refreshTokenMapKey = QStringLiteral("refresh-token");
......@@ -132,9 +128,7 @@ public:
void granted();
void error(const QString &error, const QString &errorDescription, const QUrl &uri);
QVariantMap queryToVarmap(const QUrl &url);
#ifdef HAVE_QCA
void pkeyAuthResult(KJob *job);
#endif
QWebEngineView mWebView;
QWebEngineProfile mWebProfile;
......@@ -148,9 +142,7 @@ public:
const QString mRedirectUri;
bool mAuthenticated;
QPointer<QDialog> mWebDialog;
#ifdef HAVE_QCA
QString mPKeyPassword;
#endif
EwsOAuth *q_ptr = nullptr;
Q_DECLARE_PUBLIC(EwsOAuth)
......@@ -225,9 +217,7 @@ void EwsOAuthRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info
qCDebugNC(EWSCLI_LOG) << QStringLiteral("Intercepted browser navigation to ") << url;
if ((url.toString(QUrl::RemoveQuery) == mRedirectUri)
#ifdef HAVE_QCA
|| (url.toString(QUrl::RemoveQuery) == pkeyRedirectUri)
#endif
) {
qCDebug(EWSCLI_LOG) << QStringLiteral("Found redirect URI - blocking request");
......@@ -320,14 +310,12 @@ void EwsOAuthPrivate::authorizeWithBrowser(const QUrl &url)
* Fortunately enough this can be worked around by faking the user agent to something "supported".
*/
auto userAgent = o365FakeUserAgent;
#ifdef HAVE_QCA
if (!q->mPKeyCertFile.isNull() && !q->mPKeyKeyFile.isNull()) {
qCInfoNC(EWSCLI_LOG) << QStringLiteral("Found PKeyAuth certificates");
userAgent += pkeyAuthSuffix;
} else {
qCInfoNC(EWSCLI_LOG) << QStringLiteral("PKeyAuth certificates not found");
}
#endif
mWebProfile.setHttpUserAgent(userAgent);
mWebDialog = new QDialog(q->mAuthParentWidget);
......@@ -365,7 +353,6 @@ void EwsOAuthPrivate::redirectUriIntercepted(const QUrl &url)
mWebView.stop();
mWebDialog->hide();
#ifdef HAVE_QCA
Q_Q(EwsOAuth);
if (url.toString(QUrl::RemoveQuery) == pkeyRedirectUri) {
qCDebugNC(EWSCLI_LOG) << QStringLiteral("Found PKeyAuth URI");
......@@ -378,11 +365,9 @@ void EwsOAuthPrivate::redirectUriIntercepted(const QUrl &url)
return;
}
#endif
Q_EMIT mOAuth2.authorizationCallbackReceived(queryToVarmap(url));
}
#ifdef HAVE_QCA
void EwsOAuthPrivate::pkeyAuthResult(KJob *j)
{
EwsPKeyAuthJob *job = qobject_cast<EwsPKeyAuthJob *>(j);
......@@ -397,8 +382,6 @@ void EwsOAuthPrivate::pkeyAuthResult(KJob *j)
Q_EMIT mOAuth2.authorizationCallbackReceived(varmap);
}
#endif
void EwsOAuthPrivate::granted()
{
Q_Q(EwsOAuth);
......@@ -497,11 +480,9 @@ void EwsOAuth::walletMapRequestFinished(const QMap<QString, QString> &map)
{
Q_D(EwsOAuth);
#ifdef HAVE_QCA
if (map.contains(pkeyPasswordMapKey)) {
d->mPKeyPassword = map[pkeyPasswordMapKey];
}
#endif
if (map.contains(refreshTokenMapKey)) {
d->mOAuth2.setRefreshToken(map[refreshTokenMapKey]);
}
......
......@@ -127,7 +127,6 @@ EwsConfigDialog::EwsConfigDialog(EwsResource *parentResource, EwsClient &client,
mUi->authOAuth2RadioButton->setChecked(true);
mUi->pkeyAuthGroupBox->setEnabled(true);
}
#ifdef HAVE_QCA
mUi->pkeyAuthCert->setText(mSettings->pKeyCert());
mUi->pkeyAuthKey->setText(mSettings->pKeyKey());
connect(mSettings.data(), &EwsSettings::mapRequestFinished, this, [&](const QMap<QString, QString> &map) {
......@@ -136,7 +135,6 @@ EwsConfigDialog::EwsConfigDialog(EwsResource *parentResource, EwsClient &client,
}
});
mSettings->requestMap();
#endif
int selectedIndex = -1;
int i = 0;
......@@ -229,7 +227,6 @@ void EwsConfigDialog::save()
if (mUi->authOAuth2RadioButton->isChecked()) {
mSettings->setAuthMode(QStringLiteral("oauth2"));
}
#ifdef HAVE_QCA
if (mUi->pkeyAuthGroupBox->isEnabled()
&& !mUi->pkeyAuthCert->text().isEmpty() && !mUi->pkeyAuthKey->text().isEmpty()) {
mSettings->setPKeyCert(mUi->pkeyAuthCert->text());
......@@ -237,7 +234,6 @@ void EwsConfigDialog::save()
const QMap<QString, QString> map = {{pkeyPasswordMapKey, mUi->pkeyAuthPassword->password()}};
mSettings->setMap(map);
}
#endif
if (!mAuthMap.isEmpty()) {
mSettings->setMap(mAuthMap);
......@@ -461,13 +457,11 @@ EwsAbstractAuth *EwsConfigDialog::prepareAuth()
}
auth->setAuthParentWidget(this);
#ifdef HAVE_QCA
if (mUi->pkeyAuthGroupBox->isEnabled()
&& !mUi->pkeyAuthCert->text().isEmpty() && !mUi->pkeyAuthKey->text().isEmpty()) {
auth->setPKeyAuthCertificateFiles(mUi->pkeyAuthCert->text(), mUi->pkeyAuthKey->text());
mAuthMap[pkeyPasswordMapKey] = mUi->pkeyAuthPassword->password();
}
#endif
connect(auth, &EwsAbstractAuth::requestWalletPassword, this, [&](bool) {
auth->walletPasswordRequestFinished(mUi->passwordEdit->password());
......
......@@ -336,11 +336,9 @@ EwsAbstractAuth *EwsSettings::loadAuth(QObject *parent)
auth = new EwsPasswordAuth(user, parent);
}
#ifdef HAVE_QCA
if (!pKeyCert().isNull() && !pKeyKey().isNull()) {
auth->setPKeyAuthCertificateFiles(pKeyCert(), pKeyKey());
}
#endif
connect(auth, &EwsAbstractAuth::requestWalletPassword, this, &EwsSettings::requestPassword);
connect(auth, &EwsAbstractAuth::requestWalletMap, this, &EwsSettings::requestMap);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment