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 Aug 7, 2024
1 parent 4f6a352 commit b81551f
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 147 deletions.
8 changes: 8 additions & 0 deletions common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ void CConnection::handleClipboardProvide(uint32_t flags,
handleClipboardData(serverClipboard.c_str());
}

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

bool CConnection::showMsgBox(MsgBoxFlags, const char *, const char *)
{
return true;
}

void CConnection::authSuccess()
{
}
Expand Down
28 changes: 25 additions & 3 deletions common/rfb/CConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,22 @@ namespace rfb {
class CMsgWriter;
class CSecurity;
class IdentityVerifier;

class CConnection : public CMsgHandler {

enum class MsgBoxFlags{
M_OK = 0,
M_OKCANCEL = 1,
M_YESNO = 4,
M_ICONERROR = 0x10,
M_ICONQUESTION = 0x20,
M_ICONWARNING = 0x30,
M_ICONINFORMATION = 0x40,
M_DEFBUTTON1 = 0,
M_DEFBUTTON2 = 0x100
};

class CConnection
: public CMsgHandler
{
public:

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


// Methods to be overridden in a derived class


// getUserPasswd gets the username and password. This might involve a
// dialog, getpass(), etc. The user buffer pointer can be null, in which
// case no user name will be retrieved.
virtual void getUserPasswd(bool secure, std::string* user,
std::string* password);

virtual bool showMsgBox(MsgBoxFlags flags, const char *title, const char *text);

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

Expand Down
10 changes: 0 additions & 10 deletions common/rfb/CSecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#ifndef __RFB_CSECURITY_H__
#define __RFB_CSECURITY_H__

#include <rfb/UserPasswdGetter.h>
#include <rfb/UserMsgBox.h>

namespace rfb {
class CConnection;
class CSecurity {
Expand All @@ -51,13 +48,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
3 changes: 1 addition & 2 deletions common/rfb/CSecurityPlain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <rfb/CConnection.h>
#include <rfb/CSecurityPlain.h>
#include <rfb/UserPasswdGetter.h>

#include <rdr/OutStream.h>

Expand All @@ -36,7 +35,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
7 changes: 3 additions & 4 deletions common/rfb/CSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <rfb/CConnection.h>
#include <rfb/LogWriter.h>
#include <rfb/Exception.h>
#include <rfb/UserMsgBox.h>
#include <rfb/util.h>
#include <rdr/AESInStream.h>
#include <rdr/AESOutStream.h>
Expand Down Expand Up @@ -215,7 +214,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(MsgBoxFlags::M_YESNO, title, text.c_str()))
throw AuthFailureException("server key mismatch");
}

Expand Down Expand Up @@ -438,9 +437,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
2 changes: 0 additions & 2 deletions common/rfb/CSecurityRSAAES.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
#include <nettle/rsa.h>
#include <rfb/CSecurity.h>
#include <rfb/Security.h>
#include <rfb/UserMsgBox.h>
#include <rdr/InStream.h>
#include <rdr/OutStream.h>
#include <rdr/RandomStream.h>

namespace rfb {
class UserMsgBox;
class CSecurityRSAAES : public CSecurity {
public:
CSecurityRSAAES(CConnection* cc, uint32_t secType,
Expand Down
23 changes: 11 additions & 12 deletions common/rfb/CSecurityTLS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <rfb/CConnection.h>
#include <rfb/LogWriter.h>
#include <rfb/Exception.h>
#include <rfb/UserMsgBox.h>
#include <rfb/util.h>
#include <rdr/TLSInStream.h>
#include <rdr/TLSOutStream.h>
Expand Down Expand Up @@ -441,7 +440,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(MsgBoxFlags::M_YESNO,
"Unknown certificate issuer",
text.c_str()))
throw AuthFailureException("Unknown certificate issuer");
Expand All @@ -461,8 +460,8 @@ void CSecurityTLS::checkSession()
"\n"
"Do you want to make an exception for this "
"server?", info.data);

if (!msg->showMsgBox(UserMsgBox::M_YESNO,
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Certificate is not yet valid",
text.c_str()))
throw AuthFailureException("Certificate is not yet valid");
Expand All @@ -481,7 +480,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(MsgBoxFlags::M_YESNO,
"Expired certificate",
text.c_str()))
throw AuthFailureException("Expired certificate");
Expand All @@ -500,7 +499,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(MsgBoxFlags::M_YESNO,
"Insecure certificate algorithm",
text.c_str()))
throw AuthFailureException("Insecure certificate algorithm");
Expand All @@ -525,7 +524,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(MsgBoxFlags::M_YESNO,
"Certificate hostname mismatch",
text.c_str()))
throw AuthFailureException("Certificate hostname mismatch");
Expand All @@ -551,7 +550,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(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -574,7 +573,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(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -595,7 +594,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(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -616,7 +615,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(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand All @@ -643,7 +642,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(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
throw AuthFailureException("Unexpected server certificate");
Expand Down
1 change: 0 additions & 1 deletion common/rfb/CSecurityTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <rfb/CSecurity.h>
#include <rfb/Security.h>
#include <rfb/UserMsgBox.h>
#include <rdr/InStream.h>
#include <rdr/OutStream.h>
#include <gnutls/gnutls.h>
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
41 changes: 0 additions & 41 deletions common/rfb/UserMsgBox.h

This file was deleted.

36 changes: 0 additions & 36 deletions common/rfb/UserPasswdGetter.h

This file was deleted.

2 changes: 1 addition & 1 deletion tests/perf/encperf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CConn : public rfb::CConnection {
rdr::FileInStream *in;
DummyOutStream *out;
rfb::SimpleUpdateTracker updates;
class SConn *sc;
class SConn *sc;
};

class Manager : public rfb::EncodeManager {
Expand Down
Loading

0 comments on commit b81551f

Please sign in to comment.