Skip to content

Commit

Permalink
[feature][needs-docs] Master Password integration with OS password ma…
Browse files Browse the repository at this point in the history
…nager

This PR adds (optional) synchronization of the master password
with the OS password manager (AKA wallet/keychain).

A set of new menu items has been added in the options ->
authentication -> utilities to manage the new behavior.

Notifications are handled by the message bar unless the
password r/w operation is triggered from a modal dialog,
in this case the notifications will be routed through
the recently exposed QgisApp::showSystemNotification
that uses the OS tray notifications.

This new feature requires libqt5keychain, and was tested
with v. 0.5+
  • Loading branch information
elpaso committed Apr 11, 2017
1 parent 669fa87 commit 090d530
Show file tree
Hide file tree
Showing 31 changed files with 714 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -278,6 +278,8 @@ ENDIF (WITH_QTMOBILITY)
# search for QScintilla2 (C++ lib)
FIND_PACKAGE(QScintilla REQUIRED)

# Password helper
FIND_PACKAGE(QtKeychain REQUIRED)
# Master password hash and authentication encryption
FIND_PACKAGE(QCA REQUIRED)
# Check for runtime dependency of qca-ossl plugin
Expand Down
2 changes: 1 addition & 1 deletion ci/travis/linux/before_install.sh
Expand Up @@ -22,7 +22,7 @@
pushd ${HOME}

# fetching data from github should be just as fast as S3
curl -s -S -L https://github.com/opengisch/osgeo4travis/archive/qt5bin.tar.gz | tar --strip-components=1 -xz -C /home/travis &
curl -s -S -L https://github.com/opengisch/osgeo4travis/archive/qt55bin.tar.gz | tar --strip-components=1 -xz -C /home/travis &
SETUP_OSGEO4W_PID=$!

mkdir /home/travis/osgeo4travis
Expand Down
51 changes: 51 additions & 0 deletions cmake/FindQtKeychain.cmake
@@ -0,0 +1,51 @@
# Find QtKeychain
# ~~~~~~~~~~~~~~~
# Copyright (c) 2016, Boundless Spatial
# Author: Larry Shaffer <lshaffer (at) boundlessgeo (dot) com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
# CMake module to search for QtKeychain library from:
# https://github.com/frankosterfeld/qtkeychain
#
# If it's found it sets QTKEYCHAIN_FOUND to TRUE
# and following variables are set:
# QTKEYCHAIN_INCLUDE_DIR
# QTKEYCHAIN_LIBRARY

FIND_PATH(QTKEYCHAIN_INCLUDE_DIR keychain.h
PATHS
${LIB_DIR}/include
"$ENV{LIB_DIR}/include"
$ENV{INCLUDE}
/usr/local/include
/usr/include
PATH_SUFFIXES qt5keychain qtkeychain
)

FIND_LIBRARY(QTKEYCHAIN_LIBRARY NAMES qt5keychain qtkeychain
PATHS
${LIB_DIR}
"$ENV{LIB_DIR}"
$ENV{LIB}
/usr/local/lib
/usr/lib
)


IF (QTKEYCHAIN_INCLUDE_DIR AND QTKEYCHAIN_LIBRARY)
SET(QTKEYCHAIN_FOUND TRUE)
ELSE()
SET(QTKEYCHAIN_FOUND FALSE)
ENDIF (QTKEYCHAIN_INCLUDE_DIR AND QTKEYCHAIN_LIBRARY)

IF (QTKEYCHAIN_FOUND)
IF (NOT QTKEYCHAIN_FIND_QUIETLY)
MESSAGE(STATUS "Found QtKeychain: ${QTKEYCHAIN_LIBRARY}")
ENDIF (NOT QTKEYCHAIN_FIND_QUIETLY)
ELSE (QTKEYCHAIN_FOUND)
IF (QTKEYCHAIN_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find QtKeychain")
ENDIF (QTKEYCHAIN_FIND_REQUIRED)
ENDIF (QTKEYCHAIN_FOUND)
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Expand Up @@ -89,6 +89,7 @@ INCLUDE_DIRECTORIES(SYSTEM
${QEXTSERIALPORT_INCLUDE_DIR}
${QSCINTILLA_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES(
Expand Down
24 changes: 23 additions & 1 deletion python/core/auth/qgsauthmanager.sip
Expand Up @@ -442,14 +442,36 @@ class QgsAuthManager : QObject
QMutex *mutex();

signals:

/**
* Signals emitted on password helper failure,
* mainly used in the tests to exit main application loop
*/
void passwordHelperFailure();

/**
* Signals emitted on password helper success,
* mainly used in the tests to exit main application loop
*/
void passwordHelperSuccess();

/**
* Custom logging signal to relay to console output and QgsMessageLog
* @see QgsMessageLog
* @param message Message to send
* @param tag Associated tag (title)
* @param level Message log level
*/
void messageOut( const QString& message, const QString& tag, QgsAuthManager::MessageLevel level = INFO ) const;
void messageOut( const QString& message, const QString& tag = QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level = INFO ) const;

/**
* Custom logging signal to inform the user about master password <-> password manager interactions
* @see QgsMessageLog
* @param message Message to send
* @param tag Associated tag (title)
* @param level Message log level
*/
void passwordHelperMessageOut( const QString &message, const QString &tag = QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level = INFO ) const;

/**
* Emitted when a password has been verify (or not)
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -578,6 +578,7 @@ INCLUDE_DIRECTORIES(SYSTEM
${GDAL_INCLUDE_DIR}
${QWTPOLAR_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)

IF(ENABLE_MODELTEST)
Expand Down
17 changes: 12 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -12254,6 +12254,8 @@ void QgisApp::masterPasswordSetup()
{
connect( QgsAuthManager::instance(), &QgsAuthManager::messageOut,
this, &QgisApp::authMessageOut );
connect( QgsAuthManager::instance(), &QgsAuthManager::passwordHelperMessageOut,
this, &QgisApp::authMessageOut );
connect( QgsAuthManager::instance(), &QgsAuthManager::authDatabaseEraseRequested,
this, &QgisApp::eraseAuthenticationDatabase );
}
Expand Down Expand Up @@ -12289,12 +12291,17 @@ void QgisApp::eraseAuthenticationDatabase()

void QgisApp::authMessageOut( const QString &message, const QString &authtag, QgsAuthManager::MessageLevel level )
{
// only if main window is active window
// Use system notifications if the main window is not the active one,
// push message to the message bar if the main window is active
if ( qApp->activeWindow() != this )
return;

int levelint = static_cast< int >( level );
messageBar()->pushMessage( authtag, message, static_cast< QgsMessageBar::MessageLevel >( levelint ), 7 );
{
showSystemNotification( tr( "QGIS Authentication" ), message );
}
else
{
int levelint = static_cast< int >( level );
messageBar()->pushMessage( authtag, message, static_cast< QgsMessageBar::MessageLevel >( levelint ), 7 );
}
}

void QgisApp::completeInitialization()
Expand Down
1 change: 1 addition & 0 deletions src/auth/basic/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES (
)
INCLUDE_DIRECTORIES (SYSTEM
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES (
../../gui
Expand Down
1 change: 1 addition & 0 deletions src/auth/identcert/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES (
)
INCLUDE_DIRECTORIES (SYSTEM
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES (
../../gui
Expand Down
1 change: 1 addition & 0 deletions src/auth/pkipaths/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES (
)
INCLUDE_DIRECTORIES (SYSTEM
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES (
../../gui
Expand Down
1 change: 1 addition & 0 deletions src/auth/pkipkcs12/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES (
)
INCLUDE_DIRECTORIES (SYSTEM
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES (
../../gui
Expand Down
3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Expand Up @@ -980,6 +980,7 @@ INCLUDE_DIRECTORIES(SYSTEM
${SQLITE3_INCLUDE_DIR}
${SPATIALITE_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)

#for PAL classes
Expand Down Expand Up @@ -1071,7 +1072,7 @@ TARGET_LINK_LIBRARIES(qgis_core
${OPTIONAL_QTWEBKIT}
${QT_QTSQL_LIBRARY}
${QCA_LIBRARY}

${QTKEYCHAIN_LIBRARY}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
Expand Down

0 comments on commit 090d530

Please sign in to comment.