From 630a57edbc4eeed53b4a1fbf86707783e534f290 Mon Sep 17 00:00:00 2001 From: Prasenjit Kumar Shaw Date: Mon, 3 Jun 2019 00:04:35 +0530 Subject: [PATCH] Add Sync tab in Preferences, Load FxA login & Add HKDF algorithm. Add Sync tab in Prefernces. Load Firefox Account Login page in Sync tab in Prefernces. Add HKDF algorithm that will be used for key stretching during Sync process. --- CMakeLists.txt | 1 + src/lib/CMakeLists.txt | 4 + src/lib/data/icons.qrc | 1 + src/lib/data/icons/preferences/sync.svg | 57 +++++++++++++ src/lib/preferences/preferences.cpp | 8 +- src/lib/preferences/preferences.h | 2 + src/lib/preferences/preferences.ui | 28 ++++-- src/lib/preferences/syncoptions.cpp | 44 ++++++++++ src/lib/preferences/syncoptions.h | 47 ++++++++++ src/lib/preferences/syncoptions.ui | 109 ++++++++++++++++++++++++ src/lib/sync/hkdf.cpp | 52 +++++++++++ src/lib/sync/hkdf.h | 36 ++++++++ 12 files changed, 383 insertions(+), 6 deletions(-) create mode 100755 src/lib/data/icons/preferences/sync.svg create mode 100644 src/lib/preferences/syncoptions.cpp create mode 100644 src/lib/preferences/syncoptions.h create mode 100755 src/lib/preferences/syncoptions.ui create mode 100644 src/lib/sync/hkdf.cpp create mode 100644 src/lib/sync/hkdf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fb3562e3..affa3feda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/lib/preferences ${CMAKE_SOURCE_DIR}/src/lib/session ${CMAKE_SOURCE_DIR}/src/lib/sidebar + ${CMAKE_SOURCE_DIR}/src/lib/sync ${CMAKE_SOURCE_DIR}/src/lib/tabwidget ${CMAKE_SOURCE_DIR}/src/lib/tools ${CMAKE_SOURCE_DIR}/src/lib/webengine diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 74775e351..6b63540e3 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -32,6 +32,7 @@ include_directories( preferences session sidebar + sync tabwidget tools webengine @@ -204,6 +205,7 @@ set(SRCS ${SRCS} preferences/pluginlistdelegate.cpp preferences/pluginsmanager.cpp preferences/preferences.cpp + preferences/syncoptions.cpp preferences/thememanager.cpp preferences/useragentdialog.cpp session/recoveryjsobject.cpp @@ -213,6 +215,7 @@ set(SRCS ${SRCS} sidebar/bookmarkssidebar.cpp sidebar/historysidebar.cpp sidebar/sidebar.cpp + sync/hkdf.cpp tabwidget/combotabbar.cpp tabwidget/tabbar.cpp tabwidget/tabicon.cpp @@ -313,6 +316,7 @@ qt5_wrap_ui(SRCS preferences/jsoptions.ui preferences/pluginslist.ui preferences/preferences.ui + preferences/syncoptions.ui preferences/thememanager.ui preferences/useragentdialog.ui session/sessionmanagerdialog.ui diff --git a/src/lib/data/icons.qrc b/src/lib/data/icons.qrc index f1345ad61..b692e42d8 100644 --- a/src/lib/data/icons.qrc +++ b/src/lib/data/icons.qrc @@ -56,6 +56,7 @@ icons/preferences/privacy.svg icons/preferences/shortcuts.svg icons/preferences/spellcheck.svg + icons/preferences/sync.svg icons/preferences/tabs.svg icons/menu/download.svg diff --git a/src/lib/data/icons/preferences/sync.svg b/src/lib/data/icons/preferences/sync.svg new file mode 100755 index 000000000..066e87638 --- /dev/null +++ b/src/lib/data/icons/preferences/sync.svg @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 24841b741..c8d43dce4 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -48,6 +48,7 @@ #include "webscrollbarmanager.h" #include "protocolhandlerdialog.h" #include "../config.h" +#include "syncoptions.h" #include #include @@ -137,7 +138,8 @@ Preferences::Preferences(BrowserWindow* window) setCategoryIcon(9, QIcon(":/icons/preferences/notifications.svg")); setCategoryIcon(10, QIcon(":/icons/preferences/extensions.svg")); setCategoryIcon(11, QIcon(":/icons/preferences/spellcheck.svg")); - setCategoryIcon(12, QIcon(":/icons/preferences/other.svg")); + setCategoryIcon(12, QIcon(":/icons/preferences/sync.svg")); + setCategoryIcon(13, QIcon(":/icons/preferences/other.svg")); Settings settings; //GENERAL URLs @@ -204,6 +206,10 @@ Preferences::Preferences(BrowserWindow* window) ui->newTabUseCurrent->setEnabled(false); } + // SYNC + m_syncOptions = new SyncOptions(this); + ui->syncFrame->addWidget(m_syncOptions); + // PROFILES QString startingProfile = ProfileManager::startingProfile(); ui->activeProfile->setText("" + ProfileManager::currentProfile() + ""); diff --git a/src/lib/preferences/preferences.h b/src/lib/preferences/preferences.h index 052551c1e..fd4325955 100644 --- a/src/lib/preferences/preferences.h +++ b/src/lib/preferences/preferences.h @@ -37,6 +37,7 @@ class BrowserWindow; class PluginsManager; class DesktopNotification; class ThemeManager; +class SyncOptions; class FALKON_EXPORT Preferences : public QDialog { @@ -97,6 +98,7 @@ private: AutoFillManager* m_autoFillManager; PluginsManager* m_pluginsList; ThemeManager* m_themesManager; + SyncOptions* m_syncOptions; QPointer m_notification; QUrl m_homepage; diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index bb041486b..89d4e2320 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -115,6 +115,11 @@ Spell Check + + + Sync + + Other @@ -145,8 +150,8 @@ 0 0 - 582 - 476 + 602 + 456 @@ -168,7 +173,7 @@ Qt::NoFocus - 0 + 12 @@ -2400,8 +2405,8 @@ 0 0 - 560 - 80 + 96 + 30 @@ -2437,6 +2442,19 @@ + + + + + 0 + 0 + 601 + 451 + + + + + diff --git a/src/lib/preferences/syncoptions.cpp b/src/lib/preferences/syncoptions.cpp new file mode 100644 index 000000000..c375ad453 --- /dev/null +++ b/src/lib/preferences/syncoptions.cpp @@ -0,0 +1,44 @@ + +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ + +#include "syncoptions.h" +#include "ui_syncoptions.h" + +#include +#include +#include "syncoptions.h" + +SyncOptions::SyncOptions(QWidget* parent) + : QWidget(parent) + , ui(new Ui::SyncOptions) +{ + ui->setupUi(this); + + QWebEnginePage *FxA_loginPage = new QWebEnginePage(); + FxA_loginPage->load(FxALoginUrl); + ui->fxaLoginView->setPage(FxA_loginPage); + ui->fxaLoginView->show(); +} + + + +SyncOptions::~SyncOptions() +{ + delete ui; +} diff --git a/src/lib/preferences/syncoptions.h b/src/lib/preferences/syncoptions.h new file mode 100644 index 000000000..d3680ad8f --- /dev/null +++ b/src/lib/preferences/syncoptions.h @@ -0,0 +1,47 @@ + +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ + + +#ifndef SYNCOPTIONS_H +#define SYNCOPTIONS_H + +#include +#include + +#include "qzcommon.h" + +namespace Ui +{ + class SyncOptions; +} + +class FALKON_EXPORT SyncOptions : public QWidget +{ + Q_OBJECT + +public: + explicit SyncOptions(QWidget* parent = 0); + ~SyncOptions(); + +private: + const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3"); + Ui::SyncOptions *ui; +}; + +#endif // SYNCOPTIONS_H diff --git a/src/lib/preferences/syncoptions.ui b/src/lib/preferences/syncoptions.ui new file mode 100755 index 000000000..826e0d0f4 --- /dev/null +++ b/src/lib/preferences/syncoptions.ui @@ -0,0 +1,109 @@ + + + SyncOptions + + + + 0 + 0 + 535 + 749 + + + + Form + + + + + 0 + 0 + 531 + 511 + + + + + + + + 0 + 0 + + + + + about:blank + + + + + + + + + + 0 + 530 + 531 + 211 + + + + + + + + + 0 + 0 + 531 + 51 + + + + + + + Sync Interval : + + + + + + + 5 minutes + + + + + + + 15 minutes + + + + + + + 30 minutes + + + + + + + + + + + + + QWebEngineView + QWidget +
QtWebEngineWidgets/QWebEngineView
+
+
+ + +
diff --git a/src/lib/sync/hkdf.cpp b/src/lib/sync/hkdf.cpp new file mode 100644 index 000000000..78a5760f2 --- /dev/null +++ b/src/lib/sync/hkdf.cpp @@ -0,0 +1,52 @@ + +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ + +#include "hkdf.h" + +#include +#include +#include + +HKDF::HKDF(const QByteArray key, const QByteArray salt) +{ + pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF,NULL); + + init(key, salt); +} + +HKDF::~HKDF() { + ; +} + +void HKDF::init(const QByteArray key, const QByteArray salt) +{ + size_t keylen = key.size(); + size_t saltlen = salt.size(); + + EVP_PKEY_derive_init(pctx); + EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()); + EVP_PKEY_CTX_set1_hkdf_salt(pctx, (uchar *)salt.data(), saltlen); + EVP_PKEY_CTX_set1_hkdf_key(pctx, (uchar *)key.data(), keylen); +} + +QByteArray HKDF::getKey(size_t outlen) { + QByteArray out; + EVP_PKEY_derive(pctx, (uchar *)out.data(), &outlen); + return out; +} diff --git a/src/lib/sync/hkdf.h b/src/lib/sync/hkdf.h new file mode 100644 index 000000000..53a10f754 --- /dev/null +++ b/src/lib/sync/hkdf.h @@ -0,0 +1,36 @@ + +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2019 Prasenjit Kumar Shaw +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#pragma once + +#include +#include + +class HKDF +{ +public: + explicit HKDF(const QByteArray key, const QByteArray salt); + ~HKDF(); + + QByteArray getKey(size_t outlen); + +private: + void init(const QByteArray key, const QByteArray salt); + + EVP_PKEY_CTX *pctx; +};