From bcaaea74a94502d6beabf9ea974dfbcdcf458883 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Aug 2024 15:31:05 +0200 Subject: [PATCH] Avoid connection failed exception The usage of this is unclear as it is never caught. Use the general exception class, to stay consistent with all other protocol handling. --- common/rfb/CSecurityDH.cxx | 4 ++-- common/rfb/CSecurityMSLogonII.cxx | 4 ++-- common/rfb/CSecurityRSAAES.cxx | 4 ++-- common/rfb/SSecurityRSAAES.cxx | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index 25797792..f3b085c7 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -112,7 +112,7 @@ void CSecurityDH::writeCredentials() std::vector bBytes(keyLength); if (!rs.hasData(keyLength)) - throw ConnFailedException("failed to generate DH private key"); + throw Exception("failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -132,7 +132,7 @@ void CSecurityDH::writeCredentials() uint8_t buf[128]; if (!rs.hasData(128)) - throw ConnFailedException("failed to generate random padding"); + throw Exception("failed to generate random padding"); rs.readBytes(buf, 128); if (username.size() >= 64) throw Exception("username is too long"); diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx index 24bd4cbd..dc817518 100644 --- a/common/rfb/CSecurityMSLogonII.cxx +++ b/common/rfb/CSecurityMSLogonII.cxx @@ -101,7 +101,7 @@ void CSecurityMSLogonII::writeCredentials() std::vector bBytes(8); if (!rs.hasData(8)) - throw ConnFailedException("failed to generate DH private key"); + throw Exception("failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -123,7 +123,7 @@ void CSecurityMSLogonII::writeCredentials() } if (!rs.hasData(256 + 64)) - throw ConnFailedException("failed to generate random padding"); + throw Exception("failed to generate random padding"); rs.readBytes(user, 256); rs.readBytes(pass, 64); if (username.size() >= 256) diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 9b418c64..a78739ac 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -135,7 +135,7 @@ 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 generate random"); + throw Exception("failed to generate random"); rs->readBytes(dst, length); } @@ -223,7 +223,7 @@ void CSecurityRSAAES::writeRandom() { rdr::OutStream* os = cc->getOutStream(); if (!rs.hasData(keySize / 8)) - throw ConnFailedException("failed to generate random"); + throw Exception("failed to generate random"); rs.readBytes(clientRandom, keySize / 8); mpz_t x; mpz_init(x); diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 530dca16..37860a10 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -155,18 +155,18 @@ void SSecurityRSAAES::loadPrivateKey() { FILE* file = fopen(keyFile, "rb"); if (!file) - throw ConnFailedException("failed to open key file"); + throw Exception("failed to open key file"); fseek(file, 0, SEEK_END); size_t size = ftell(file); if (size == 0 || size > MaxKeyFileSize) { fclose(file); - throw ConnFailedException("size of key file is zero or too big"); + throw Exception("size of key file is zero or too big"); } fseek(file, 0, SEEK_SET); std::vector data(size); if (fread(data.data(), 1, data.size(), file) != size) { fclose(file); - throw ConnFailedException("failed to read key"); + throw Exception("failed to read key"); } fclose(file); @@ -183,7 +183,7 @@ void SSecurityRSAAES::loadPrivateKey() loadPKCS8Key(der.data(), der.size()); return; } - throw ConnFailedException("failed to import key"); + throw Exception("failed to import key"); } void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) @@ -194,7 +194,7 @@ void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) if (!rsa_keypair_from_der(&pub, &serverKey, 0, size, data)) { rsa_private_key_clear(&serverKey); rsa_public_key_clear(&pub); - throw ConnFailedException("failed to import key"); + throw Exception("failed to import key"); } serverKeyLength = serverKey.size * 8; serverKeyN = new uint8_t[serverKey.size]; @@ -234,7 +234,7 @@ void SSecurityRSAAES::loadPKCS8Key(const uint8_t* data, size_t size) loadPKCS1Key(i.data, i.length); return; failed: - throw ConnFailedException("failed to import key"); + throw Exception("failed to import key"); } bool SSecurityRSAAES::processMsg() -- 2.39.5