Skip to content

Commit

Permalink
Remove ConnFailedException
Browse files Browse the repository at this point in the history
There were more unclear usage of this exception class, and since nothing
catches it it is very unclear what the purpose is. Go ahead and just
remove it.

Follow-up to bcaaea7.
  • Loading branch information
CendioOssman committed Sep 2, 2024
1 parent 2e33477 commit da1adb5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
4 changes: 0 additions & 4 deletions common/rfb/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@ namespace rfb {
AuthCancelledException()
: Exception("Authentication cancelled") {}
};
struct ConnFailedException : public Exception {
ConnFailedException(const char* reason)
: Exception("%s", reason) {}
};
}
#endif
18 changes: 9 additions & 9 deletions common/rfb/SConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ bool SConnection::processVersionMsg()

if (client.majorVersion != 3) {
// unknown protocol version
throwConnFailedException("Client needs protocol version %d.%d, server has %d.%d",
client.majorVersion, client.minorVersion,
defaultMajorVersion, defaultMinorVersion);
failConnection("Client needs protocol version %d.%d, server has %d.%d",
client.majorVersion, client.minorVersion,
defaultMajorVersion, defaultMinorVersion);
}

if (client.minorVersion != 3 && client.minorVersion != 7 && client.minorVersion != 8) {
Expand Down Expand Up @@ -165,8 +165,8 @@ bool SConnection::processVersionMsg()
if (*i == secTypeNone || *i == secTypeVncAuth) break;
}
if (i == secTypes.end()) {
throwConnFailedException("No supported security type for %d.%d client",
client.majorVersion, client.minorVersion);
failConnection("No supported security type for %d.%d client",
client.majorVersion, client.minorVersion);
}

os->writeU32(*i);
Expand All @@ -179,7 +179,7 @@ bool SConnection::processVersionMsg()
// list supported security types for >=3.7 clients

if (secTypes.empty())
throwConnFailedException("No supported security types");
failConnection("No supported security types");

os->writeU8(secTypes.size());
for (i=secTypes.begin(); i!=secTypes.end(); i++)
Expand Down Expand Up @@ -222,7 +222,7 @@ void SConnection::processSecurityType(int secType)
state_ = RFBSTATE_SECURITY;
ssecurity = security.GetSSecurity(this, secType);
} catch (rdr::Exception& e) {
throwConnFailedException("%s", e.str());
failConnection("%s", e.str());
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ void SConnection::handleAuthFailureTimeout(Timer* /*t*/)
close(authFailureMsg.c_str());
}

void SConnection::throwConnFailedException(const char* format, ...)
void SConnection::failConnection(const char* format, ...)
{
va_list ap;
char str[256];
Expand All @@ -325,7 +325,7 @@ void SConnection::throwConnFailedException(const char* format, ...)
}

state_ = RFBSTATE_INVALID;
throw ConnFailedException(str);
throw Exception("%s", str);
}

void SConnection::setAccessRights(AccessRights ar)
Expand Down
8 changes: 4 additions & 4 deletions common/rfb/SConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ namespace rfb {
int32_t getPreferredEncoding() { return preferredEncoding; }

protected:
// throwConnFailedException() prints a message to the log, sends a conn
// failed message to the client (if possible) and throws a
// ConnFailedException.
void throwConnFailedException(const char* format, ...)
// failConnection() prints a message to the log, sends a connection
// failed message to the client (if possible) and throws an
// Exception.
void failConnection(const char* format, ...)
__attribute__((__format__ (__printf__, 2, 3)));

void setState(stateEnum s) { state_ = s; }
Expand Down
18 changes: 9 additions & 9 deletions common/rfb/SSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ bool SSecurityRSAAES::readPublicKey()
is->setRestorePoint();
clientKeyLength = is->readU32();
if (clientKeyLength < MinKeyLength)
throw ConnFailedException("client key is too short");
throw Exception("client key is too short");
if (clientKeyLength > MaxKeyLength)
throw ConnFailedException("client key is too long");
throw Exception("client key is too long");
size_t size = (clientKeyLength + 7) / 8;
if (!is->hasDataOrRestore(size * 2))
return false;
Expand All @@ -310,23 +310,23 @@ bool SSecurityRSAAES::readPublicKey()
nettle_mpz_set_str_256_u(clientKey.n, size, clientKeyN);
nettle_mpz_set_str_256_u(clientKey.e, size, clientKeyE);
if (!rsa_public_key_prepare(&clientKey))
throw ConnFailedException("client key is invalid");
throw Exception("client key is invalid");
return true;
}

static void random_func(void* ctx, size_t length, uint8_t* dst)
{
rdr::RandomStream* rs = (rdr::RandomStream*)ctx;
if (!rs->hasData(length))
throw ConnFailedException("failed to encrypt random");
throw Exception("failed to encrypt random");
rs->readBytes(dst, length);
}

void SSecurityRSAAES::writeRandom()
{
rdr::OutStream* os = sc->getOutStream();
if (!rs.hasData(keySize / 8))
throw ConnFailedException("failed to generate random");
throw Exception("failed to generate random");
rs.readBytes(serverRandom, keySize / 8);
mpz_t x;
mpz_init(x);
Expand All @@ -340,7 +340,7 @@ void SSecurityRSAAES::writeRandom()
}
if (!res) {
mpz_clear(x);
throw ConnFailedException("failed to encrypt random");
throw Exception("failed to encrypt random");
}
uint8_t* buffer = new uint8_t[clientKey.size];
nettle_mpz_get_str_256(clientKey.size, buffer, x);
Expand All @@ -359,7 +359,7 @@ bool SSecurityRSAAES::readRandom()
is->setRestorePoint();
size_t size = is->readU16();
if (size != serverKey.size)
throw ConnFailedException("server key length doesn't match");
throw Exception("server key length doesn't match");
if (!is->hasDataOrRestore(size))
return false;
is->clearRestorePoint();
Expand All @@ -372,7 +372,7 @@ bool SSecurityRSAAES::readRandom()
if (!rsa_decrypt(&serverKey, &randomSize, clientRandom, x) ||
randomSize != (size_t)keySize / 8) {
mpz_clear(x);
throw ConnFailedException("failed to decrypt client random");
throw Exception("failed to decrypt client random");
}
mpz_clear(x);
return true;
Expand Down Expand Up @@ -501,7 +501,7 @@ bool SSecurityRSAAES::readHash()
sha256_digest(&ctx, hashSize, realHash);
}
if (memcmp(hash, realHash, hashSize) != 0)
throw ConnFailedException("hash doesn't match");
throw Exception("hash doesn't match");
return true;
}

Expand Down

0 comments on commit da1adb5

Please sign in to comment.