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

1Password OpVault format support #2292

Merged
merged 3 commits into from
May 19, 2019
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
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,16 @@ if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
set(IS_32BIT TRUE)
endif()

set(CLANG_COMPILER_ID_REGEX "^(Apple)?[Cc]lang$")
if("${CMAKE_C_COMPILER}" MATCHES "clang$"
OR "${CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
OR "${CMAKE_C_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
set(CMAKE_COMPILER_IS_CLANG 1)
endif()

if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$"
OR "${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()

Expand Down Expand Up @@ -253,6 +254,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
endif()

if(WITH_COVERAGE AND CMAKE_COMPILER_IS_CLANGXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
# then:
# $ llvm-profdata merge -sparse default.profraw -o default.profdata
# $ llvm-cov show ./tests/${the_test_binary} \
# -format=html -instr-profile=default.profdata -output-dir=./coverages \
# `find src -iname '*.h' -or -iname '*.cpp'`
endif()

if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
endif()
Expand All @@ -276,7 +286,7 @@ if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.
add_gcc_compiler_cxxflags("-fsized-deallocation")
endif()

if(APPLE)
if(APPLE AND CMAKE_COMPILER_IS_CLANGXX)
add_gcc_compiler_cxxflags("-stdlib=libc++")
endif()

Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ set(keepassx_SOURCES
format/Kdbx4Reader.cpp
format/Kdbx4Writer.cpp
format/KdbxXmlWriter.cpp
format/OpData01.cpp
format/OpVaultReader.cpp
format/OpVaultReaderAttachments.cpp
format/OpVaultReaderBandEntry.cpp
format/OpVaultReaderSections.cpp
gui/AboutDialog.cpp
gui/Application.cpp
gui/CategoryListWidget.cpp
Expand All @@ -103,6 +108,7 @@ set(keepassx_SOURCES
gui/MainWindow.cpp
gui/MessageBox.cpp
gui/MessageWidget.cpp
gui/OpVaultOpenWidget.cpp
gui/PasswordEdit.cpp
gui/PasswordGeneratorWidget.cpp
gui/ApplicationSettingsWidget.cpp
Expand Down
3 changes: 1 addition & 2 deletions src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,8 @@ bool AutoType::windowMatches(const QString& windowTitle, const QString& windowPa
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
QRegExp regExp(windowPattern.mid(2, windowPattern.size() - 4), Qt::CaseInsensitive, QRegExp::RegExp2);
return (regExp.indexIn(windowTitle) != -1);
} else {
return WildcardMatcher(windowTitle).match(windowPattern);
}
return WildcardMatcher(windowTitle).match(windowPattern);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/autotype/AutoTypeFilterLineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "AutoTypeFilterLineEdit.h"
#include <QKeyEvent>

void AutoTypeFilterLineEdit::keyPressEvent(QKeyEvent *event)
void AutoTypeFilterLineEdit::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Up) {
emit keyUpPressed();
Expand All @@ -29,7 +29,7 @@ void AutoTypeFilterLineEdit::keyPressEvent(QKeyEvent *event)
}
}

void AutoTypeFilterLineEdit::keyReleaseEvent(QKeyEvent *event)
void AutoTypeFilterLineEdit::keyReleaseEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Escape) {
emit escapeReleased();
Expand Down
10 changes: 7 additions & 3 deletions src/autotype/AutoTypeFilterLineEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ class AutoTypeFilterLineEdit : public QLineEdit
Q_OBJECT

public:
AutoTypeFilterLineEdit(QWidget* widget) : QLineEdit(widget) {}
AutoTypeFilterLineEdit(QWidget* widget)
: QLineEdit(widget)
{
}

protected:
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
signals:
void keyUpPressed();
void keyDownPressed();
Expand Down
7 changes: 3 additions & 4 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QLabel>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QSortFilterProxyModel>
#include <QVBoxLayout>

#include "autotype/AutoTypeSelectView.h"
#include "core/AutoTypeMatch.h"
Expand Down Expand Up @@ -77,7 +77,7 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
connect(m_view, SIGNAL(rejected()), SLOT(reject()));
// clang-format on

QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
if (proxy) {
proxy->setFilterKeyColumn(-1);
proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
Expand Down Expand Up @@ -146,10 +146,9 @@ void AutoTypeSelectDialog::matchRemoved()
}
}


void AutoTypeSelectDialog::filterList(QString filterString)
{
QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
if (proxy) {
proxy->setFilterWildcard(filterString);
if (!m_view->currentIndex().isValid()) {
Expand Down
6 changes: 1 addition & 5 deletions src/autotype/mac/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
set(autotype_mac_SOURCES AutoTypeMac.cpp)

set(autotype_mac_mm_SOURCES
${CMAKE_SOURCE_DIR}/src/gui/macutils/AppKitImpl.mm
${CMAKE_SOURCE_DIR}/src/gui/macutils/MacUtils.cpp)

add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES} ${autotype_mac_mm_SOURCES})
add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES})
set_target_properties(keepassx-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon")
target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets)

Expand Down
2 changes: 1 addition & 1 deletion src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ QJsonObject BrowserAction::handleSetLogin(const QJsonObject& json, const QString
QJsonObject message = buildMessage(newNonce);
message["count"] = QJsonValue::Null;
message["entries"] = QJsonValue::Null;
message["error"] = "";
message["error"] = QString("");
message["hash"] = hash;

return buildResponse(action, message, newNonce);
Expand Down
4 changes: 2 additions & 2 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,

// Fill the list
for (Entry* entry : pwEntries) {
result << prepareEntry(entry);
result.append(prepareEntry(entry));
}

return result;
Expand Down Expand Up @@ -825,7 +825,7 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
if (key.startsWith(QLatin1String("KPH: "))) {
QJsonObject sField;
sField[key] = entry->resolveMultiplePlaceholders(attr->value(key));
stringFields << sField;
stringFields.append(sField);
}
}
res["stringFields"] = stringFields;
Expand Down
6 changes: 3 additions & 3 deletions src/browser/BrowserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ void BrowserSettings::setVivaldiSupport(bool enabled)

bool BrowserSettings::braveSupport()
{
return m_hostInstaller.checkIfInstalled(HostInstaller::SupportedBrowsers::BRAVE);
return m_hostInstaller.checkIfInstalled(HostInstaller::SupportedBrowsers::BRAVE);
}

void BrowserSettings::setBraveSupport(bool enabled)
{
m_hostInstaller.installBrowser(
HostInstaller::SupportedBrowsers::BRAVE, enabled, supportBrowserProxy(), customProxyLocation());
m_hostInstaller.installBrowser(
HostInstaller::SupportedBrowsers::BRAVE, enabled, supportBrowserProxy(), customProxyLocation());
}

bool BrowserSettings::torBrowserSupport()
Expand Down
10 changes: 5 additions & 5 deletions src/browser/HostInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ QString HostInstaller::getTargetPath(SupportedBrowsers browser) const
case SupportedBrowsers::TOR_BROWSER:
return TARGET_DIR_TOR_BROWSER;
case SupportedBrowsers::BRAVE:
return TARGET_DIR_BRAVE;
return TARGET_DIR_BRAVE;
default:
return QString();
}
Expand All @@ -194,11 +194,11 @@ QString HostInstaller::getBrowserName(SupportedBrowsers browser) const
case SupportedBrowsers::FIREFOX:
return "firefox";
case SupportedBrowsers::VIVALDI:
return "vivaldi";
return "vivaldi";
case SupportedBrowsers::TOR_BROWSER:
return "tor-browser";
case SupportedBrowsers::BRAVE:
return "brave";
return "brave";
default:
return QString();
}
Expand Down Expand Up @@ -299,9 +299,9 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&

QJsonObject script;
script["name"] = HOST_NAME;
script["description"] = "KeePassXC integration with native messaging support";
script["description"] = QString("KeePassXC integration with native messaging support");
script["path"] = path;
script["type"] = "stdio";
script["type"] = QString("stdio");

QJsonArray arr;
if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER) {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/NativeMessagingBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void NativeMessagingBase::readNativeMessages()
{
#ifdef Q_OS_WIN
quint32 length = 0;
while (m_running.load() && !std::cin.eof()) {
while (m_running.load() != 0 && !std::cin.eof()) {
length = 0;
std::cin.read(reinterpret_cast<char*>(&length), 4);
readStdIn(length);
Expand Down
4 changes: 2 additions & 2 deletions src/browser/NativeMessagingBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef NATIVEMESSAGINGBASE_H
#define NATIVEMESSAGINGBASE_H

#include <QAtomicInteger>
#include <QAtomicInt>
#include <QFuture>
#include <QJsonDocument>
#include <QJsonObject>
Expand Down Expand Up @@ -60,7 +60,7 @@ protected slots:
QString getLocalServerPath() const;

protected:
QAtomicInteger<quint8> m_running;
QAtomicInt m_running;
QSharedPointer<QSocketNotifier> m_notifier;
QFuture<void> m_future;
};
Expand Down
14 changes: 7 additions & 7 deletions src/browser/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ NativeMessagingHost::NativeMessagingHost(DatabaseTabWidget* parent, const bool e
{
m_localServer.reset(new QLocalServer(this));
m_localServer->setSocketOptions(QLocalServer::UserAccessOption);
m_running.store(false);
m_running.store(0);

if (browserSettings()->isEnabled() && !m_running) {
if (browserSettings()->isEnabled() && m_running.load() == 0) {
run();
}

Expand All @@ -59,7 +59,7 @@ int NativeMessagingHost::init()
void NativeMessagingHost::run()
{
QMutexLocker locker(&m_mutex);
if (!m_running.load() && init() == -1) {
if (m_running.load() == 0 && init() == -1) {
return;
}

Expand All @@ -69,7 +69,7 @@ void NativeMessagingHost::run()
browserSettings()->useCustomProxy() ? browserSettings()->customProxyLocation() : "");
}

m_running.store(true);
m_running.store(1);
#ifdef Q_OS_WIN
m_future =
QtConcurrent::run(this, static_cast<void (NativeMessagingHost::*)()>(&NativeMessagingHost::readNativeMessages));
Expand Down Expand Up @@ -100,7 +100,7 @@ void NativeMessagingHost::stop()
databaseLocked();
QMutexLocker locker(&m_mutex);
m_socketList.clear();
m_running.testAndSetOrdered(true, false);
m_running.testAndSetOrdered(1, 0);
m_future.waitForFinished();
m_localServer->close();
}
Expand Down Expand Up @@ -210,13 +210,13 @@ void NativeMessagingHost::disconnectSocket()
void NativeMessagingHost::databaseLocked()
{
QJsonObject response;
response["action"] = "database-locked";
response["action"] = QString("database-locked");
sendReplyToAllClients(response);
}

void NativeMessagingHost::databaseUnlocked()
{
QJsonObject response;
response["action"] = "database-unlocked";
response["action"] = QString("database-unlocked");
sendReplyToAllClients(response);
}
3 changes: 1 addition & 2 deletions src/cli/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ const QCommandLineOption Command::KeyFileOption = QCommandLineOption(QStringList
QObject::tr("path"));

const QCommandLineOption Command::NoPasswordOption =
QCommandLineOption(QStringList() << "no-password",
QObject::tr("Deactivate password key for the database."));
QCommandLineOption(QStringList() << "no-password", QObject::tr("Deactivate password key for the database."));

QMap<QString, Command*> commands;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int Extract::execute(const QStringList& arguments)
errorTextStream << parser.helpText().replace("[options]", "extract [options]");
return EXIT_FAILURE;
}

auto compositeKey = QSharedPointer<CompositeKey>::create();

auto db = Utils::unlockDatabase(args.at(0),
Expand Down
3 changes: 1 addition & 2 deletions src/cli/keepassxc-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ int main(int argc, char** argv)

parser.addPositionalArgument("command", QObject::tr("Name of the command to execute."));

QCommandLineOption debugInfoOption(QStringList() << "debug-info",
QObject::tr("Displays debugging information."));
QCommandLineOption debugInfoOption(QStringList() << "debug-info", QObject::tr("Displays debugging information."));
parser.addOption(debugInfoOption);
parser.addHelpOption();
parser.addVersionOption();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void operator delete[](void* ptr) noexcept
* Custom insecure delete operator that does not zero out memory before
* freeing a buffer. Can be used for better performance.
*/
void operator delete(void* ptr, bool) noexcept
void operator delete(void* ptr, bool)noexcept
{
std::free(ptr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace Bootstrap
nullptr, // do not change owner or group
pACL, // DACL specified
nullptr // do not change SACL
);
);

Cleanup:

Expand Down
6 changes: 3 additions & 3 deletions src/core/Merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context)
// Merge Custom Data if source is newer
const auto targetCustomDataModificationTime = sourceMetadata->customData()->getLastModified();
const auto sourceCustomDataModificationTime = targetMetadata->customData()->getLastModified();
if (!targetMetadata->customData()->contains(CustomData::LastModified) ||
(targetCustomDataModificationTime.isValid() && sourceCustomDataModificationTime.isValid() &&
targetCustomDataModificationTime > sourceCustomDataModificationTime)) {
if (!targetMetadata->customData()->contains(CustomData::LastModified)
|| (targetCustomDataModificationTime.isValid() && sourceCustomDataModificationTime.isValid()
&& targetCustomDataModificationTime > sourceCustomDataModificationTime)) {
const auto sourceCustomDataKeys = sourceMetadata->customData()->keys();
const auto targetCustomDataKeys = targetMetadata->customData()->keys();

Expand Down
3 changes: 1 addition & 2 deletions src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "core/Config.h"
#include "core/Translator.h"

#include "git-info.h"
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QIODevice>
Expand All @@ -33,7 +34,6 @@
#include <QSysInfo>
#include <QUuid>
#include <cctype>
#include "git-info.h"

#ifdef Q_OS_WIN
#include <windows.h> // for Sleep()
Expand Down Expand Up @@ -75,7 +75,6 @@ namespace Tools
#endif
debugInfo.append("\n");


#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
debugInfo.append(QObject::tr("Operating system: %1\nCPU architecture: %2\nKernel: %3 %4")
.arg(QSysInfo::prettyProductName(),
Expand Down
Loading