Skip to content

Commit

Permalink
Merge pull request #1098 from hifi/feature/sshagent
Browse files Browse the repository at this point in the history
SSH agent client support (KeeAgent compatible)
  • Loading branch information
phoerious authored Nov 19, 2017
2 parents 8625e2c + 4840c2c commit ac73e25
Show file tree
Hide file tree
Showing 39 changed files with 3,547 additions and 13 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON)
option(WITH_XC_AUTOTYPE "Include Auto-Type." ON)
option(WITH_XC_HTTP "Include KeePassHTTP and Custom Icon Downloads." OFF)
option(WITH_XC_YUBIKEY "Include YubiKey support." OFF)
option(WITH_XC_SSHAGENT "Include SSH agent support." OFF)

# Process ui files automatically from source files
set(CMAKE_AUTOUIC ON)
Expand Down
1 change: 1 addition & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Files: share/icons/application/*/actions/application-exit.png
share/icons/application/*/actions/view-history.png
share/icons/application/*/apps/internet-web-browser.png
share/icons/application/*/apps/preferences-desktop-icons.png
share/icons/application/*/apps/utilities-terminal.png
share/icons/application/*/categories/preferences-other.png
share/icons/application/*/status/dialog-error.png
share/icons/application/*/status/dialog-information.png
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added share/icons/svg/utilities-terminal.svgz
Binary file not shown.
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ set(keepassx_SOURCES_MAINEXE
add_feature_info(AutoType WITH_XC_AUTOTYPE "Automatic password typing")
add_feature_info(KeePassHTTP WITH_XC_HTTP "Browser integration compatible with ChromeIPass and PassIFox")
add_feature_info(YubiKey WITH_XC_YUBIKEY "YubiKey HMAC-SHA1 challenge-response")
add_feature_info(SSHAgent WITH_XC_SSHAGENT "SSH agent integration compatible with KeeAgent")

add_subdirectory(http)
if(WITH_XC_HTTP)
Expand All @@ -186,6 +187,11 @@ endif()
add_subdirectory(autotype)
add_subdirectory(cli)

add_subdirectory(sshagent)
if(WITH_XC_SSHAGENT)
set(sshagent_LIB sshagent)
endif()

set(autotype_SOURCES
core/Tools.cpp
autotype/AutoType.cpp
Expand Down Expand Up @@ -222,6 +228,7 @@ set_target_properties(keepassx_core PROPERTIES COMPILE_DEFINITIONS KEEPASSX_BUIL
target_link_libraries(keepassx_core
${keepasshttp_LIB}
${autotype_LIB}
${sshagent_LIB}
${YUBIKEY_LIBRARIES}
${ZXCVBN_LIBRARIES}
Qt5::Core
Expand Down
1 change: 1 addition & 0 deletions src/config-keepassx.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#cmakedefine WITH_XC_HTTP
#cmakedefine WITH_XC_AUTOTYPE
#cmakedefine WITH_XC_YUBIKEY
#cmakedefine WITH_XC_SSHAGENT

#cmakedefine KEEPASSXC_DIST
#cmakedefine KEEPASSXC_DIST_TYPE "@KEEPASSXC_DIST_TYPE@"
Expand Down
5 changes: 5 additions & 0 deletions src/crypto/SymmetricCipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ bool SymmetricCipher::reset()
return m_backend->reset();
}

int SymmetricCipher::keySize() const
{
return m_backend->keySize();
}

int SymmetricCipher::blockSize() const
{
return m_backend->blockSize();
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/SymmetricCipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SymmetricCipher
enum Mode
{
Cbc,
Ctr,
Ecb,
Stream
};
Expand Down Expand Up @@ -69,6 +70,7 @@ class SymmetricCipher
}

bool reset();
int keySize() const;
int blockSize() const;
QString errorString() const;

Expand Down
1 change: 1 addition & 0 deletions src/crypto/SymmetricCipherBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SymmetricCipherBackend
Q_REQUIRED_RESULT virtual bool processInPlace(QByteArray& data, quint64 rounds) = 0;

virtual bool reset() = 0;
virtual int keySize() const = 0;
virtual int blockSize() const = 0;

virtual QString errorString() const = 0;
Expand Down
41 changes: 30 additions & 11 deletions src/crypto/SymmetricCipherGcrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, Sy
, m_algo(gcryptAlgo(algo))
, m_mode(gcryptMode(mode))
, m_direction(direction)
, m_blockSize(-1)
{
}

Expand Down Expand Up @@ -62,6 +61,9 @@ int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
case SymmetricCipher::Cbc:
return GCRY_CIPHER_MODE_CBC;

case SymmetricCipher::Ctr:
return GCRY_CIPHER_MODE_CTR;

case SymmetricCipher::Stream:
return GCRY_CIPHER_MODE_STREAM;

Expand Down Expand Up @@ -92,14 +94,6 @@ bool SymmetricCipherGcrypt::init()
return false;
}

size_t blockSizeT;
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, nullptr, &blockSizeT);
if (error != 0) {
setErrorString(error);
return false;
}

m_blockSize = blockSizeT;
return true;
}

Expand All @@ -119,7 +113,13 @@ bool SymmetricCipherGcrypt::setKey(const QByteArray& key)
bool SymmetricCipherGcrypt::setIv(const QByteArray& iv)
{
m_iv = iv;
gcry_error_t error = gcry_cipher_setiv(m_ctx, m_iv.constData(), m_iv.size());
gcry_error_t error;

if (m_mode == GCRY_CIPHER_MODE_CTR) {
error = gcry_cipher_setctr(m_ctx, m_iv.constData(), m_iv.size());
} else {
error = gcry_cipher_setiv(m_ctx, m_iv.constData(), m_iv.size());
}

if (error != 0) {
setErrorString(error);
Expand Down Expand Up @@ -228,9 +228,28 @@ bool SymmetricCipherGcrypt::reset()
return true;
}

int SymmetricCipherGcrypt::keySize() const
{
gcry_error_t error;
size_t keySizeT;

error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_KEYLEN, nullptr, &keySizeT);
if (error != 0)
return -1;

return keySizeT;
}

int SymmetricCipherGcrypt::blockSize() const
{
return m_blockSize;
gcry_error_t error;
size_t blockSizeT;

error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, nullptr, &blockSizeT);
if (error != 0)
return -1;

return blockSizeT;
}

QString SymmetricCipherGcrypt::errorString() const
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/SymmetricCipherGcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SymmetricCipherGcrypt : public SymmetricCipherBackend
Q_REQUIRED_RESULT bool processInPlace(QByteArray& data, quint64 rounds);

bool reset();
int keySize() const;
int blockSize() const;

QString errorString() const;
Expand All @@ -54,7 +55,6 @@ class SymmetricCipherGcrypt : public SymmetricCipherBackend
const SymmetricCipher::Direction m_direction;
QByteArray m_key;
QByteArray m_iv;
int m_blockSize;
QString m_errorString;
};

Expand Down
3 changes: 3 additions & 0 deletions src/gui/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ AboutDialog::AboutDialog(QWidget* parent)
#ifdef WITH_XC_YUBIKEY
extensions += "\n- YubiKey";
#endif
#ifdef WITH_XC_SSHAGENT
extensions += "\n- SSH Agent";
#endif

if (extensions.isEmpty())
extensions = " None";
Expand Down
13 changes: 13 additions & 0 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
#include "gui/group/EditGroupWidget.h"
#include "gui/group/GroupView.h"

#include "config-keepassx.h"

#ifdef WITH_XC_SSHAGENT
#include "sshagent/SSHAgent.h"
#endif

DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
: QStackedWidget(parent)
, m_db(db)
Expand Down Expand Up @@ -210,6 +216,13 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
m_searchCaseSensitive = false;
m_searchLimitGroup = config()->get("SearchLimitGroup", false).toBool();

#ifdef WITH_XC_SSHAGENT
if (config()->get("SSHAgent", false).toBool()) {
connect(this, SIGNAL(currentModeChanged(DatabaseWidget::Mode)), SSHAgent::instance(), SLOT(databaseModeChanged(DatabaseWidget::Mode)));
connect(this, SIGNAL(closeRequest()), SSHAgent::instance(), SLOT(databaseModeChanged()));
}
#endif

setCurrentWidget(m_mainWidget);
}

Expand Down
9 changes: 9 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
#include "http/OptionDialog.h"
#endif

#ifdef WITH_XC_SSHAGENT
#include "sshagent/AgentSettingsPage.h"
#include "sshagent/SSHAgent.h"
#endif

#include "gui/SettingsWidget.h"
#include "gui/PasswordGeneratorWidget.h"

Expand Down Expand Up @@ -121,6 +126,10 @@ MainWindow::MainWindow()
#ifdef WITH_XC_HTTP
m_ui->settingsWidget->addSettingsPage(new HttpPlugin(m_ui->tabWidget));
#endif
#ifdef WITH_XC_SSHAGENT
SSHAgent::init(this);
m_ui->settingsWidget->addSettingsPage(new AgentSettingsPage(m_ui->tabWidget));
#endif

setWindowIcon(filePath()->applicationIcon());
m_ui->globalMessageWidget->setHidden(true);
Expand Down
Loading

0 comments on commit ac73e25

Please sign in to comment.