mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
Save credentials in system wallet
This commit is contained in:
parent
2801d96bbe
commit
6c4ba02703
@ -64,6 +64,17 @@ add_3rdparty(
|
|||||||
-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
|
-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_3rdparty(
|
||||||
|
qtkeychain
|
||||||
|
GIT_REPOSITORY https://github.com/frankosterfeld/qtkeychain.git
|
||||||
|
GIT_TAG master
|
||||||
|
CMAKE_ARGS
|
||||||
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||||
|
-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
|
||||||
|
-DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH}
|
||||||
|
-DCMAKE_PREFIX_PATH=$ENV{CMAKE_PREFIX_PATH}
|
||||||
|
)
|
||||||
|
|
||||||
ExternalProject_Get_Property(SingleApplication-${PROJECT_NAME} SOURCE_DIR BINARY_DIR)
|
ExternalProject_Get_Property(SingleApplication-${PROJECT_NAME} SOURCE_DIR BINARY_DIR)
|
||||||
set(SingleApplication_INCLUDE_DIR ${SOURCE_DIR})
|
set(SingleApplication_INCLUDE_DIR ${SOURCE_DIR})
|
||||||
set(SingleApplication_LIBRARY ${BINARY_DIR}/libSingleApplication.a)
|
set(SingleApplication_LIBRARY ${BINARY_DIR}/libSingleApplication.a)
|
||||||
@ -71,7 +82,12 @@ set(SingleApplication_LIBRARY ${BINARY_DIR}/libSingleApplication.a)
|
|||||||
ExternalProject_Get_Property(plog-${PROJECT_NAME} SOURCE_DIR)
|
ExternalProject_Get_Property(plog-${PROJECT_NAME} SOURCE_DIR)
|
||||||
set(plog_INCLUDE_DIR "${SOURCE_DIR}/include")
|
set(plog_INCLUDE_DIR "${SOURCE_DIR}/include")
|
||||||
|
|
||||||
add_dependencies(gpclient SingleApplication-${PROJECT_NAME} plog-${PROJECT_NAME})
|
ExternalProject_Get_Property(qtkeychain-${PROJECT_NAME} SOURCE_DIR BINARY_DIR)
|
||||||
|
set(qtkeychain_INCLUDE_DIR "${SOURCE_DIR}")
|
||||||
|
set(qtkeychain_BINARY_DIR "${BINARY_DIR}")
|
||||||
|
set(qtkeychain_LIBRARY ${BINARY_DIR}/libqt5keychain.so)
|
||||||
|
|
||||||
|
add_dependencies(gpclient SingleApplication-${PROJECT_NAME} plog-${PROJECT_NAME} qtkeychain-${PROJECT_NAME})
|
||||||
|
|
||||||
target_include_directories(gpclient PRIVATE
|
target_include_directories(gpclient PRIVATE
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
@ -79,10 +95,13 @@ target_include_directories(gpclient PRIVATE
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
${SingleApplication_INCLUDE_DIR}
|
${SingleApplication_INCLUDE_DIR}
|
||||||
${plog_INCLUDE_DIR}
|
${plog_INCLUDE_DIR}
|
||||||
|
${qtkeychain_INCLUDE_DIR}
|
||||||
|
${qtkeychain_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(gpclient
|
target_link_libraries(gpclient
|
||||||
${SingleApplication_LIBRARY}
|
${SingleApplication_LIBRARY}
|
||||||
|
${qtkeychain_LIBRARY}
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
Qt5::Network
|
Qt5::Network
|
||||||
Qt5::WebSockets
|
Qt5::WebSockets
|
||||||
|
@ -9,9 +9,12 @@
|
|||||||
#include <plog/Log.h>
|
#include <plog/Log.h>
|
||||||
#include <QWebEngineProfile>
|
#include <QWebEngineProfile>
|
||||||
#include <QWebEngineCookieStore>
|
#include <QWebEngineCookieStore>
|
||||||
|
#include <keychain.h>
|
||||||
|
|
||||||
#include "gphelper.h"
|
#include "gphelper.h"
|
||||||
|
|
||||||
|
using namespace QKeychain;
|
||||||
|
|
||||||
QNetworkAccessManager* gpclient::helper::networkManager = new QNetworkAccessManager;
|
QNetworkAccessManager* gpclient::helper::networkManager = new QNetworkAccessManager;
|
||||||
|
|
||||||
QNetworkReply* gpclient::helper::createRequest(QString url, QByteArray params)
|
QNetworkReply* gpclient::helper::createRequest(QString url, QByteArray params)
|
||||||
@ -132,3 +135,38 @@ void gpclient::helper::settings::clear()
|
|||||||
|
|
||||||
QWebEngineProfile::defaultProfile()->cookieStore()->deleteAllCookies();
|
QWebEngineProfile::defaultProfile()->cookieStore()->deleteAllCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool gpclient::helper::settings::secureSave(const QString &key, const QString &value) {
|
||||||
|
WritePasswordJob job( QLatin1String("gpclient") );
|
||||||
|
job.setAutoDelete( false );
|
||||||
|
job.setKey( key );
|
||||||
|
job.setTextData( value );
|
||||||
|
QEventLoop loop;
|
||||||
|
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
|
||||||
|
job.start();
|
||||||
|
loop.exec();
|
||||||
|
if ( job.error() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gpclient::helper::settings::secureGet(const QString &key, QString &value) {
|
||||||
|
ReadPasswordJob job( QLatin1String("gpclient") );
|
||||||
|
job.setAutoDelete( false );
|
||||||
|
job.setKey( key );
|
||||||
|
QEventLoop loop;
|
||||||
|
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
|
||||||
|
job.start();
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
const QString pw = job.textData();
|
||||||
|
if ( job.error() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = pw;
|
||||||
|
return true;
|
||||||
|
}
|
@ -36,6 +36,9 @@ namespace gpclient {
|
|||||||
QVariant get(const QString &key, const QVariant &defaultValue = QVariant());
|
QVariant get(const QString &key, const QVariant &defaultValue = QVariant());
|
||||||
void save(const QString &key, const QVariant &value);
|
void save(const QString &key, const QVariant &value);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
bool secureSave(const QString &key, const QString &value);
|
||||||
|
bool secureGet(const QString &key, QString &value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "standardloginwindow.h"
|
#include "standardloginwindow.h"
|
||||||
#include "ui_standardloginwindow.h"
|
#include "ui_standardloginwindow.h"
|
||||||
|
#include "gphelper.h"
|
||||||
|
|
||||||
|
using namespace gpclient::helper;
|
||||||
|
|
||||||
StandardLoginWindow::StandardLoginWindow(const QString &portalAddress, const QString &labelUsername,
|
StandardLoginWindow::StandardLoginWindow(const QString &portalAddress, const QString &labelUsername,
|
||||||
const QString &labelPassword, const QString &authMessage) :
|
const QString &labelPassword, const QString &authMessage) :
|
||||||
@ -13,11 +16,24 @@ StandardLoginWindow::StandardLoginWindow(const QString &portalAddress, const QSt
|
|||||||
ui->password->setPlaceholderText(labelPassword);
|
ui->password->setPlaceholderText(labelPassword);
|
||||||
ui->authMessage->setText(authMessage);
|
ui->authMessage->setText(authMessage);
|
||||||
|
|
||||||
|
autocomplete();
|
||||||
|
|
||||||
setWindowTitle("GlobalProtect Login");
|
setWindowTitle("GlobalProtect Login");
|
||||||
setFixedSize(width(), height());
|
setFixedSize(width(), height());
|
||||||
setModal(true);
|
setModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StandardLoginWindow::autocomplete() {
|
||||||
|
QString username, password;
|
||||||
|
settings::secureGet("username", username);
|
||||||
|
settings::secureGet("password", password);
|
||||||
|
|
||||||
|
if (!username.isEmpty() && !password.isEmpty()) {
|
||||||
|
ui->username->setText(username);
|
||||||
|
ui->password->setText(password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StandardLoginWindow::setProcessing(bool isProcessing) {
|
void StandardLoginWindow::setProcessing(bool isProcessing) {
|
||||||
ui->username->setReadOnly(isProcessing);
|
ui->username->setReadOnly(isProcessing);
|
||||||
ui->password->setReadOnly(isProcessing);
|
ui->password->setReadOnly(isProcessing);
|
||||||
@ -32,6 +48,9 @@ void StandardLoginWindow::on_loginButton_clicked() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings::secureSave("username", username);
|
||||||
|
settings::secureSave("password", password);
|
||||||
|
|
||||||
emit performLogin(username, password);
|
emit performLogin(username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ private:
|
|||||||
Ui::StandardLoginWindow *ui;
|
Ui::StandardLoginWindow *ui;
|
||||||
|
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
void autocomplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STANDARDLOGINWINDOW_H
|
#endif // STANDARDLOGINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user