AuthCancelledException()
: Exception("Authentication cancelled") {}
};
- struct ConnFailedException : public Exception {
- ConnFailedException(const char* reason)
- : Exception("%s", reason) {}
- };
}
#endif
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) {
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);
// 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++)
state_ = RFBSTATE_SECURITY;
ssecurity = security.GetSSecurity(this, secType);
} catch (rdr::Exception& e) {
- throwConnFailedException("%s", e.str());
+ failConnection("%s", e.str());
}
}
close(authFailureMsg.c_str());
}
-void SConnection::throwConnFailedException(const char* format, ...)
+void SConnection::failConnection(const char* format, ...)
{
va_list ap;
char str[256];
}
state_ = RFBSTATE_INVALID;
- throw ConnFailedException(str);
+ throw Exception("%s", str);
}
void SConnection::setAccessRights(AccessRights ar)
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; }
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;
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;
}
{
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);
}
{
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);
}
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);
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();
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;
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;
}