Fix the clientos param (#87)

* fix the clientos param

* fix the clientos param
This commit is contained in:
Kevin Yue 2021-09-04 18:56:17 +08:00 committed by GitHub
parent 64e6487e7e
commit 6fa77cdbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 36 deletions

View File

@ -8,7 +8,7 @@
using namespace gpclient::helper; using namespace gpclient::helper;
GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, const GatewayAuthenticatorParams& params) GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, const GatewayAuthenticatorParams params)
: QObject() : QObject()
, gateway(gateway) , gateway(gateway)
, params(params) , params(params)
@ -29,23 +29,19 @@ void GatewayAuthenticator::authenticate()
{ {
PLOGI << "Start gateway authentication..."; PLOGI << "Start gateway authentication...";
LoginParams loginParams; LoginParams loginParams { params.clientos() };
loginParams.setUser(params.username()); loginParams.setUser(params.username());
loginParams.setPassword(params.password()); loginParams.setPassword(params.password());
loginParams.setUserAuthCookie(params.userAuthCookie()); loginParams.setUserAuthCookie(params.userAuthCookie());
if (!params.clientos().isEmpty()) {
loginParams.setClientos(params.clientos());
}
login(loginParams); login(loginParams);
} }
void GatewayAuthenticator::login(const LoginParams &params) void GatewayAuthenticator::login(const LoginParams &loginParams)
{ {
PLOGI << "Trying to login the gateway at " << loginUrl << " with " << params.toUtf8(); PLOGI << "Trying to login the gateway at " << loginUrl << " with " << loginParams.toUtf8();
QNetworkReply *reply = createRequest(loginUrl, params.toUtf8()); QNetworkReply *reply = createRequest(loginUrl, loginParams.toUtf8());
connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onLoginFinished); connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onLoginFinished);
} }
@ -132,10 +128,11 @@ void GatewayAuthenticator::onPerformNormalLogin(const QString &username, const Q
PLOGI << "Start to perform normal login..."; PLOGI << "Start to perform normal login...";
normalLoginWindow->setProcessing(true); normalLoginWindow->setProcessing(true);
LoginParams params; LoginParams loginParams { params.clientos() };
params.setUser(username); loginParams.setUser(username);
params.setPassword(password); loginParams.setPassword(password);
login(params);
login(loginParams);
} }
void GatewayAuthenticator::onLoginWindowRejected() void GatewayAuthenticator::onLoginWindowRejected()
@ -170,12 +167,12 @@ void GatewayAuthenticator::onSAMLLoginSuccess(const QMap<QString, QString> &saml
PLOGI << "SAML login succeeded, got the portal-userauthcookie " << samlResult.value("userAuthCookie"); PLOGI << "SAML login succeeded, got the portal-userauthcookie " << samlResult.value("userAuthCookie");
} }
LoginParams params; LoginParams loginParams { params.clientos() };
params.setUser(samlResult.value("username")); loginParams.setUser(samlResult.value("username"));
params.setPreloginCookie(samlResult.value("preloginCookie")); loginParams.setPreloginCookie(samlResult.value("preloginCookie"));
params.setUserAuthCookie(samlResult.value("userAuthCookie")); loginParams.setUserAuthCookie(samlResult.value("userAuthCookie"));
login(params); login(loginParams);
} }
void GatewayAuthenticator::onSAMLLoginFail(const QString msg) void GatewayAuthenticator::onSAMLLoginFail(const QString msg)

View File

@ -10,7 +10,7 @@ class GatewayAuthenticator : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GatewayAuthenticator(const QString& gateway, const GatewayAuthenticatorParams& params); explicit GatewayAuthenticator(const QString& gateway, const GatewayAuthenticatorParams params);
~GatewayAuthenticator(); ~GatewayAuthenticator();
void authenticate(); void authenticate();
@ -30,13 +30,13 @@ private slots:
private: private:
QString gateway; QString gateway;
const GatewayAuthenticatorParams& params; const GatewayAuthenticatorParams params;
QString preloginUrl; QString preloginUrl;
QString loginUrl; QString loginUrl;
NormalLoginWindow *normalLoginWindow{ nullptr }; NormalLoginWindow *normalLoginWindow{ nullptr };
void login(const LoginParams& params); void login(const LoginParams& loginParams);
void doAuth(); void doAuth();
void normalAuth(QString labelUsername, QString labelPassword, QString authMessage); void normalAuth(QString labelUsername, QString labelPassword, QString authMessage);
void samlAuth(QString samlMethod, QString samlRequest, QString preloginUrl = ""); void samlAuth(QString samlMethod, QString samlRequest, QString preloginUrl = "");

View File

@ -2,7 +2,7 @@
#include <QUrlQuery> #include <QUrlQuery>
LoginParams::LoginParams() LoginParams::LoginParams(const QString clientos)
{ {
params.addQueryItem("prot", QUrl::toPercentEncoding("https:")); params.addQueryItem("prot", QUrl::toPercentEncoding("https:"));
params.addQueryItem("server", ""); params.addQueryItem("server", "");
@ -15,6 +15,12 @@ LoginParams::LoginParams()
params.addQueryItem("direct", "yes"); params.addQueryItem("direct", "yes");
params.addQueryItem("clientVer", "4100"); params.addQueryItem("clientVer", "4100");
params.addQueryItem("os-version", QUrl::toPercentEncoding(QSysInfo::prettyProductName())); params.addQueryItem("os-version", QUrl::toPercentEncoding(QSysInfo::prettyProductName()));
// add the clientos parameter if not empty
if (!clientos.isEmpty()) {
params.addQueryItem("clientos", clientos);
}
params.addQueryItem("portal-userauthcookie", ""); params.addQueryItem("portal-userauthcookie", "");
params.addQueryItem("portal-prelogonuserauthcookie", ""); params.addQueryItem("portal-prelogonuserauthcookie", "");
params.addQueryItem("prelogin-cookie", ""); params.addQueryItem("prelogin-cookie", "");
@ -55,11 +61,6 @@ void LoginParams::setPreloginCookie(const QString cookie)
updateQueryItem("prelogin-cookie", cookie); updateQueryItem("prelogin-cookie", cookie);
} }
void LoginParams::setClientos(const QString clientos)
{
updateQueryItem("clientos", clientos);
}
QByteArray LoginParams::toUtf8() const QByteArray LoginParams::toUtf8() const
{ {
return params.toString().toUtf8(); return params.toString().toUtf8();

View File

@ -6,7 +6,7 @@
class LoginParams class LoginParams
{ {
public: public:
LoginParams(); LoginParams(const QString clientos);
~LoginParams(); ~LoginParams();
void setUser(const QString user); void setUser(const QString user);
@ -15,7 +15,6 @@ public:
void setUserAuthCookie(const QString cookie); void setUserAuthCookie(const QString cookie);
void setPrelogonAuthCookie(const QString cookie); void setPrelogonAuthCookie(const QString cookie);
void setPreloginCookie(const QString cookie); void setPreloginCookie(const QString cookie);
void setClientos(const QString clientos);
QByteArray toUtf8() const; QByteArray toUtf8() const;

View File

@ -14,6 +14,7 @@ using namespace gpclient::helper;
PortalAuthenticator::PortalAuthenticator(const QString& portal, const QString& clientos) : QObject() PortalAuthenticator::PortalAuthenticator(const QString& portal, const QString& clientos) : QObject()
, portal(portal) , portal(portal)
, clientos(clientos)
, preloginUrl("https://" + portal + "/global-protect/prelogin.esp?tmp=tmp&kerberos-support=yes&ipv6-support=yes&clientVer=4100") , preloginUrl("https://" + portal + "/global-protect/prelogin.esp?tmp=tmp&kerberos-support=yes&ipv6-support=yes&clientVer=4100")
, configUrl("https://" + portal + "/global-protect/getconfig.esp") , configUrl("https://" + portal + "/global-protect/getconfig.esp")
{ {
@ -146,12 +147,12 @@ void PortalAuthenticator::onSAMLLoginFail(const QString msg)
void PortalAuthenticator::fetchConfig(QString username, QString password, QString preloginCookie, QString userAuthCookie) void PortalAuthenticator::fetchConfig(QString username, QString password, QString preloginCookie, QString userAuthCookie)
{ {
LoginParams params; LoginParams loginParams { clientos };
params.setServer(portal); loginParams.setServer(portal);
params.setUser(username); loginParams.setUser(username);
params.setPassword(password); loginParams.setPassword(password);
params.setPreloginCookie(preloginCookie); loginParams.setPreloginCookie(preloginCookie);
params.setUserAuthCookie(userAuthCookie); loginParams.setUserAuthCookie(userAuthCookie);
// Save the username and password for future use. // Save the username and password for future use.
this->username = username; this->username = username;
@ -159,7 +160,7 @@ void PortalAuthenticator::fetchConfig(QString username, QString password, QStrin
PLOGI << "Fetching the portal config from " << configUrl << " for user: " << username; PLOGI << "Fetching the portal config from " << configUrl << " for user: " << username;
QNetworkReply *reply = createRequest(configUrl, params.toUtf8()); QNetworkReply *reply = createRequest(configUrl, loginParams.toUtf8());
connect(reply, &QNetworkReply::finished, this, &PortalAuthenticator::onFetchConfigFinished); connect(reply, &QNetworkReply::finished, this, &PortalAuthenticator::onFetchConfigFinished);
} }

View File

@ -34,6 +34,7 @@ private slots:
private: private:
QString portal; QString portal;
QString clientos;
QString preloginUrl; QString preloginUrl;
QString configUrl; QString configUrl;
QString username; QString username;