Browse Source

[Development] Use enhanced Security class by both UNIX and Windows viewers.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4042 3789f03b-4d11-0410-bbf8-ca57d06f2519
tags/v1.0.90
Adam Tkac 14 years ago
parent
commit
f324dc451b

+ 7
- 6
common/rfb/CConnection.cxx View File

static LogWriter vlog("CConnection"); static LogWriter vlog("CConnection");


CConnection::CConnection() CConnection::CConnection()
: is(0), os(0), reader_(0), writer_(0),
shared(false), security(0), nSecTypes(0), clientSecTypeOrder(false),
: csecurity(0), is(0), os(0), reader_(0), writer_(0),
shared(false), nSecTypes(0), clientSecTypeOrder(false),
state_(RFBSTATE_UNINITIALISED), useProtocol3_3(false) state_(RFBSTATE_UNINITIALISED), useProtocol3_3(false)
{ {
security = new Security();
} }


CConnection::~CConnection() CConnection::~CConnection()
{ {
if (security) security->destroy();
if (csecurity) csecurity->destroy();
deleteReaderAndWriter(); deleteReaderAndWriter();
} }


} }


state_ = RFBSTATE_SECURITY; state_ = RFBSTATE_SECURITY;
security = getCSecurity(secType);
csecurity = security->GetCSecurity(secType);
processSecurityMsg(); processSecurityMsg();
} }


void CConnection::processSecurityMsg() void CConnection::processSecurityMsg()
{ {
vlog.debug("processing security message"); vlog.debug("processing security message");
if (security->processMsg(this)) {
if (csecurity->processMsg(this)) {
state_ = RFBSTATE_SECURITY_RESULT; state_ = RFBSTATE_SECURITY_RESULT;
processSecurityResultMsg(); processSecurityResultMsg();
} }
{ {
vlog.debug("processing security result message"); vlog.debug("processing security result message");
int result; int result;
if (cp.beforeVersion(3,8) && security->getType() == secTypeNone) {
if (cp.beforeVersion(3,8) && csecurity->getType() == secTypeNone) {
result = secResultOK; result = secResultOK;
} else { } else {
if (!is->checkNoWait(1)) return; if (!is->checkNoWait(1)) return;

+ 4
- 10
common/rfb/CConnection.h View File

#include <rdr/InStream.h> #include <rdr/InStream.h>
#include <rdr/OutStream.h> #include <rdr/OutStream.h>
#include <rfb/CMsgHandler.h> #include <rfb/CMsgHandler.h>
#include <rfb/CSecurity.h>
#include <rfb/util.h> #include <rfb/util.h>
#include <rfb/Security.h>


namespace rfb { namespace rfb {




// Methods to be overridden in a derived class // Methods to be overridden in a derived class


// getCSecurity() gets the CSecurity object for the given type. The type
// is guaranteed to be one of the secTypes passed in to addSecType(). The
// CSecurity object's destroy() method will be called by the CConnection
// from its destructor.
virtual CSecurity* getCSecurity(int secType)=0;

// getCurrentCSecurity() gets the CSecurity instance used for this connection.
const CSecurity* getCurrentCSecurity() const {return security;}

// getIdVerifier() returns the identity verifier associated with the connection. // getIdVerifier() returns the identity verifier associated with the connection.
// Ownership of the IdentityVerifier is retained by the CConnection instance. // Ownership of the IdentityVerifier is retained by the CConnection instance.
virtual IdentityVerifier* getIdentityVerifier() {return 0;} virtual IdentityVerifier* getIdentityVerifier() {return 0;}


stateEnum state() { return state_; } stateEnum state() { return state_; }


CSecurity *csecurity; /* Windows viewer needs it exported. */
protected: protected:
void setState(stateEnum s) { state_ = s; } void setState(stateEnum s) { state_ = s; }
Security *security;


private: private:
void processVersionMsg(); void processVersionMsg();
CMsgWriter* writer_; CMsgWriter* writer_;
bool deleteStreamsWhenDone; bool deleteStreamsWhenDone;
bool shared; bool shared;
CSecurity* security;
enum { maxSecTypes = 8 }; enum { maxSecTypes = 8 };
int nSecTypes; int nSecTypes;
rdr::U8 secTypes[maxSecTypes]; rdr::U8 secTypes[maxSecTypes];

+ 1
- 1
common/rfb/Security.cxx View File

StringParameter Security::secTypes StringParameter Security::secTypes
("SecurityTypes", ("SecurityTypes",
"Specify which security scheme to use (None, VncAuth)", "Specify which security scheme to use (None, VncAuth)",
"VncAuth");
"VncAuth", ConfServer);


Security::Security(void) : upg(NULL) Security::Security(void) : upg(NULL)
{ {

+ 4
- 15
unix/vncviewer/CConn.cxx View File

setShared(shared); setShared(shared);
addSecType(secTypeNone); addSecType(secTypeNone);
addSecType(secTypeVncAuth); addSecType(secTypeVncAuth);
security->upg = this; /* Security instance is created in CConnection costructor. */

CharArray encStr(preferredEncoding.getData()); CharArray encStr(preferredEncoding.getData());
int encNum = encodingNum(encStr.buf); int encNum = encodingNum(encStr.buf);
if (encNum != -1) { if (encNum != -1) {
return; return;
} }


const char* secType = secTypeName(getCurrentCSecurity()->getType());
const char* secType = secTypeName(csecurity->getType());
const char* titlePrefix = _("VNC authentication"); const char* titlePrefix = _("VNC authentication");
unsigned int titleLen = strlen(titlePrefix) + strlen(secType) + 4; unsigned int titleLen = strlen(titlePrefix) + strlen(secType) + 4;
CharArray title(titleLen); CharArray title(titleLen);


// CConnection callback methods // CConnection callback methods


// getCSecurity() gets the appropriate CSecurity object for the security
// types which we support.
CSecurity* CConn::getCSecurity(int secType) {
switch (secType) {
case secTypeNone:
return new CSecurityNone();
case secTypeVncAuth:
return new CSecurityVncAuth(this);
default:
throw rfb::Exception("Unsupported secType?");
}
}

// serverInit() is called when the serverInit message has been received. At // serverInit() is called when the serverInit message has been received. At
// this point we create the desktop window and display it. We also tell the // this point we create the desktop window and display it. We also tell the
// server the pixel format and encodings to use and request the first update. // server the pixel format and encodings to use and request the first update.
char spfStr[100]; char spfStr[100];
cp.pf().print(pfStr, 100); cp.pf().print(pfStr, 100);
serverPF.print(spfStr, 100); serverPF.print(spfStr, 100);
int secType = getCurrentCSecurity()->getType();
int secType = csecurity->getType();
char infoText[1024]; char infoText[1024];
snprintf(infoText, sizeof(infoText), snprintf(infoText, sizeof(infoText),
_("Desktop name: %.80s\n" _("Desktop name: %.80s\n"

+ 0
- 1
unix/vncviewer/CConn.h View File

virtual void handleEvent(TXWindow* w, XEvent* ev); virtual void handleEvent(TXWindow* w, XEvent* ev);
// CConnection callback methods // CConnection callback methods
rfb::CSecurity* getCSecurity(int secType);
void serverInit(); void serverInit();
void setDesktopSize(int w, int h); void setDesktopSize(int w, int h);
void setExtendedDesktopSize(int reason, int result, int w, int h, void setExtendedDesktopSize(int reason, int result, int w, int h,

+ 2
- 15
win/vncviewer/CConn.cxx View File

// - Set which auth schemes we support, in order of preference // - Set which auth schemes we support, in order of preference
addSecType(secTypeVncAuth); addSecType(secTypeVncAuth);
addSecType(secTypeNone); addSecType(secTypeNone);
security->upg = this; /* Security instance is created in CConnection costructor. */


// Start the RFB protocol // Start the RFB protocol
sock = s; sock = s;
} }
} }



CSecurity* CConn::getCSecurity(int secType)
{
switch (secType) {
case secTypeNone:
return new CSecurityNone();
case secTypeVncAuth:
return new CSecurityVncAuth(this);
default:
throw Exception("Unsupported secType?");
}
}


void void
CConn::setColourMapEntries(int first, int count, U16* rgbs) { CConn::setColourMapEntries(int first, int count, U16* rgbs) {
vlog.debug("setColourMapEntries: first=%d, count=%d", first, count); vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
if ((user && !*user) || (password && !*password)) { if ((user && !*user) || (password && !*password)) {
// Missing username or password - prompt the user // Missing username or password - prompt the user
UserPasswdDialog userPasswdDialog; UserPasswdDialog userPasswdDialog;
userPasswdDialog.setCSecurity(getCurrentCSecurity());
userPasswdDialog.setCSecurity(csecurity);
userPasswdDialog.getUserPasswd(user, password); userPasswdDialog.getUserPasswd(user, password);
} }
if (user) options.setUserName(*user); if (user) options.setUserName(*user);

+ 1
- 1
win/vncviewer/InfoDialog.cxx View File

sprintf(buf, "%d.%d", conn->cp.majorVersion, conn->cp.minorVersion); sprintf(buf, "%d.%d", conn->cp.majorVersion, conn->cp.minorVersion);
setItemString(IDC_INFO_VERSION, TStr(buf)); setItemString(IDC_INFO_VERSION, TStr(buf));


const CSecurity* cSec = conn->getCurrentCSecurity();
const CSecurity* cSec = conn->csecurity;
setItemString(IDC_INFO_SECURITY, TStr(secTypeName(cSec->getType()))); setItemString(IDC_INFO_SECURITY, TStr(secTypeName(cSec->getType())));
setItemString(IDC_INFO_ENCRYPTION, TStr(cSec->description())); setItemString(IDC_INFO_ENCRYPTION, TStr(cSec->description()));
} }

Loading…
Cancel
Save