pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.04k stars 2.11k forks source link

Util::IniFileConfiguration of an ecrypted stream (Crypto::CryptoInputStream) using wrong password, hangs #4577

Open omerbrandis opened 3 weeks ago

omerbrandis commented 3 weeks ago

Hello

I'm using poco version 1.12.3.

problem description : i've followed this link the encryption/decryption functions. i'm using Util::IniFileConfiguration to read an ecrypted file using Crypto::CryptoInputStream. and as long as I'm providing the correct password and salt to the Crypto::CipherKey ctor, all is well.

but I am unable to handle the case of wrong password/salt, the application hangs when trying the read from the undecryptable stream :

here's the code std::string password = ""; std::string salt = "";

try { // create crypto engine Poco::Crypto::CipherFactory & factory = Poco::Crypto::CipherFactory::defaultFactory(); Poco::Crypto::CipherKey CK("aes-256-cbc", password, salt); std::cout << "after create cipher key" << std::endl; Poco::Crypto::Cipher * pCipher = factory.createCipher(CK);

// create a decryption stream Poco::FileInputStream sink("RunParameters.encrypted"); Poco::Crypto::CryptoInputStream DecryptorStream(sink, pCipher->createDecryptor()); std::cout << "after create decryptor stream" << std::endl;

// read from the stream Poco::AutoPtr pServerConfig(new Poco::Util::IniFileConfiguration(DecryptorStream)); std::cout << "after creating IniFileConfiguration object using the decryption stream" << std::endl; } catch (const Poco::Exception & Except) { ES.Message = "was not able to reach encrypted configuration file, exception = " + Except.displayText(); ES.Code = 8; return(ES); }

when I execute, it simply hangs. exception is not thrown. last row in the terminal is "after create decryptor stream"

please advise, :-)