Skip to content

Commit

Permalink
CConnection: Modify UserPasswdGetter and UserMsgBox interface to CCon…
Browse files Browse the repository at this point in the history
…nection

Problems with the original code: A process can only establish one connection.
After modification, multiple connections can be supported.
  • Loading branch information
KangLin committed Jul 30, 2024
1 parent 4f6a352 commit 2bc68d0
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 44 deletions.
10 changes: 8 additions & 2 deletions common/rfb/CConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ namespace rfb {
class CSecurity;
class IdentityVerifier;

class CConnection : public CMsgHandler {
class CConnection
: public CMsgHandler
, public UserPasswdGetter
#if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
,public UserMsgBox
#endif
{
public:

CConnection();
Expand Down Expand Up @@ -126,7 +132,7 @@ namespace rfb {


// Methods to be overridden in a derived class

// authSuccess() is called when authentication has succeeded.
virtual void authSuccess();

Expand Down
7 changes: 0 additions & 7 deletions common/rfb/CSecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ namespace rfb {
virtual int getType() const = 0;
virtual bool isSecure() const { return false; }

/*
* Use variable directly instead of dumb get/set methods.
* It MUST be set by viewer.
*/
static UserPasswdGetter *upg;
static UserMsgBox *msg;

protected:
CConnection* cc;
};
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityDH.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void CSecurityDH::writeCredentials()
std::string password;
rdr::RandomStream rs;

(CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
cc->getUserPasswd(isSecure(), &username, &password);

std::vector<uint8_t> bBytes(keyLength);
if (!rs.hasData(keyLength))
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityMSLogonII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CSecurityMSLogonII::writeCredentials()
std::string password;
rdr::RandomStream rs;

(CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
cc->getUserPasswd(isSecure(), &username, &password);

std::vector<uint8_t> bBytes(8);
if (!rs.hasData(8))
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityPlain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool CSecurityPlain::processMsg()
std::string username;
std::string password;

(CSecurity::upg)->getUserPasswd(cc->isSecure(), &username, &password);
cc->getUserPasswd(cc->isSecure(), &username, &password);

// Return the response to the server
os->writeU32(username.size());
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/CSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void CSecurityRSAAES::verifyServer()
"Fingerprint: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n"
"Please verify that the information is correct and press \"Yes\". "
"Otherwise press \"No\"", f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]);
if (!msg->showMsgBox(UserMsgBox::M_YESNO, title, text.c_str()))
if (!cc->showMsgBox(UserMsgBox::M_YESNO, title, text.c_str()))
throw AuthFailureException("server key mismatch");
}

Expand Down Expand Up @@ -438,9 +438,9 @@ void CSecurityRSAAES::writeCredentials()
std::string password;

if (subtype == secTypeRA2UserPass)
(CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
cc->getUserPasswd(isSecure(), &username, &password);
else
(CSecurity::upg)->getUserPasswd(isSecure(), nullptr, &password);
cc->getUserPasswd(isSecure(), nullptr, &password);

if (subtype == secTypeRA2UserPass) {
if (username.size() > 255)
Expand Down
20 changes: 10 additions & 10 deletions common/rfb/CSecurityTLS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unknown certificate issuer",
text.c_str()))
throw AuthFailureException("Unknown certificate issuer");
Expand All @@ -462,7 +462,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Certificate is not yet valid",
text.c_str()))
throw AuthFailureException("Certificate is not yet valid");
Expand All @@ -481,7 +481,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Expired certificate",
text.c_str()))
throw AuthFailureException("Expired certificate");
Expand All @@ -500,7 +500,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Insecure certificate algorithm",
text.c_str()))
throw AuthFailureException("Insecure certificate algorithm");
Expand All @@ -525,7 +525,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", client->getServerName(), info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Certificate hostname mismatch",
text.c_str()))
throw AuthFailureException("Certificate hostname mismatch");
Expand All @@ -551,7 +551,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -574,7 +574,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -595,7 +595,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -616,7 +616,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -643,7 +643,7 @@ void CSecurityTLS::checkSession()
"Do you want to make an exception for this "
"server?", client->getServerName(), info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(UserMsgBox::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityVncAuth.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool CSecurityVncAuth::processMsg()
uint8_t challenge[vncAuthChallengeSize];
is->readBytes(challenge, vncAuthChallengeSize);
std::string passwd;
(CSecurity::upg)->getUserPasswd(cc->isSecure(), nullptr, &passwd);
cc->getUserPasswd(cc->isSecure(), nullptr, &passwd);

// Calculate the correct response
uint8_t key[8];
Expand Down
10 changes: 0 additions & 10 deletions common/rfb/SecurityClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
using namespace rdr;
using namespace rfb;

UserPasswdGetter *CSecurity::upg = nullptr;
#if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
UserMsgBox *CSecurity::msg = nullptr;
#endif

StringParameter SecurityClient::secTypes
("SecurityTypes",
"Specify which security scheme to use (None, VncAuth, Plain"
Expand All @@ -67,11 +62,6 @@ ConfViewer);

CSecurity* SecurityClient::GetCSecurity(CConnection* cc, uint32_t secType)
{
assert (CSecurity::upg != nullptr); /* (upg == nullptr) means bug in the viewer */
#if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
assert (CSecurity::msg != nullptr);
#endif

if (!IsSupported(secType))
goto bail;

Expand Down
14 changes: 14 additions & 0 deletions tests/perf/decperf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class CConn : public rfb::CConnection {
void setColourMapEntries(int, int, uint16_t*) override;
void bell() override;
void serverCutText(const char*) override;

// UserMsgBox interface
virtual bool showMsgBox(int flags, const char *title, const char *text) override;
// UserPasswdGetter interface
virtual void getUserPasswd(bool secure, std::string *user, std::string *password) override;

public:
double cpuTime;
Expand All @@ -85,6 +90,15 @@ class CConn : public rfb::CConnection {
DummyOutStream *out;
};

bool CConn::showMsgBox(int, const char *, const char *)
{
return true;
}

void CConn::getUserPasswd(bool, std::string *, std::string *)
{
}

DummyOutStream::DummyOutStream()
{
offset = 0;
Expand Down
15 changes: 14 additions & 1 deletion tests/perf/encperf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ class CConn : public rfb::CConnection {
void setColourMapEntries(int, int, uint16_t*) override;
void bell() override;
void serverCutText(const char*) override;


virtual bool showMsgBox(int flags, const char *title, const char *text) override;
virtual void getUserPasswd(bool secure, std::string *user, std::string *password) override;

public:
double decodeTime;
double encodeTime;
Expand All @@ -118,8 +121,18 @@ class CConn : public rfb::CConnection {
DummyOutStream *out;
rfb::SimpleUpdateTracker updates;
class SConn *sc;

};

bool CConn::showMsgBox(int, const char *, const char *)
{
return true;
}

void CConn::getUserPasswd(bool, std::string *, std::string *)
{
}

class Manager : public rfb::EncodeManager {
public:
Manager(class rfb::SConnection *conn);
Expand Down
10 changes: 10 additions & 0 deletions vncviewer/CConn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,13 @@ void CConn::handleUpdateTimeout(void *data)

Fl::repeat_timeout(1.0, handleUpdateTimeout, data);
}

bool CConn::showMsgBox(int flags, const char *title, const char *text)
{
return dlg.showMsgBox(flags, title, text);
}

void CConn::getUserPasswd(bool secure, std::string *user, std::string *password)
{
dlg.getUserPasswd(secure, user, password);
}
11 changes: 10 additions & 1 deletion vncviewer/CConn.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <rfb/CConnection.h>
#include <rdr/FdInStream.h>
#include "UserDialog.h"

namespace network { class Socket; }

Expand All @@ -43,7 +44,13 @@ class CConn : public rfb::CConnection

// Callback when socket is ready (or broken)
static void socketEvent(FL_SOCKET fd, void *data);


// UserMsgBox interface
virtual bool showMsgBox(int flags, const char *title, const char *text) override;

// UserPasswdGetter interface
virtual void getUserPasswd(bool secure, std::string *user, std::string *password) override;

// CConnection callback methods
void initDone() override;

Expand Down Expand Up @@ -105,6 +112,8 @@ class CConn : public rfb::CConnection
struct timeval updateStartTime;
size_t updateStartPos;
unsigned long long bpsEstimate;

UserDialog dlg;
};

#endif
6 changes: 0 additions & 6 deletions vncviewer/vncviewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ static int mktunnel()
int main(int argc, char** argv)
{
const char *localedir;
UserDialog dlg;

argv0 = argv[0];

Expand Down Expand Up @@ -742,11 +741,6 @@ int main(int argc, char** argv)
vlog.error(_("Could not create VNC state directory: %s"), strerror(errno));
}

CSecurity::upg = &dlg;
#if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
CSecurity::msg = &dlg;
#endif

Socket *sock = nullptr;

#ifndef WIN32
Expand Down

0 comments on commit 2bc68d0

Please sign in to comment.