Skip to content

Commit

Permalink
sha1password supported again
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Oct 25, 2023
1 parent b0f19e6 commit 2aa2a8b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions libshviotqt/src/rpc/clientconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#endif

#include <fstream>
#include <regex>

namespace cp = shv::chainpack;
using namespace std;
Expand Down Expand Up @@ -446,10 +447,17 @@ chainpack::RpcValue ClientConnection::createLoginParams(const chainpack::RpcValu
if(loginType() == chainpack::IRpcConnection::LoginType::Sha1) {
std::string server_nonce = server_hello.asMap().value("nonce").toString();
std::string pwd = password();
if(pwd.size() == 40)
shvWarning() << "Using shadowed password directly by client is unsecure and it will be disabled in future SHV versions";
else
pwd = utils::sha1Hex(pwd); /// SHA1 password must be 40 chars long, it is considered to be plain if shorter
do {
if(pwd.size() == 40) {
// sha1passwd
std::regex re(R"([0-9a-f]{40})");
if(std::regex_match(pwd, re)) {
/// SHA1 password
break;
}
}
pwd = utils::sha1Hex(pwd);
} while(false);
std::string pn = server_nonce + pwd;
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1);
#if QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 3
Expand Down

0 comments on commit 2aa2a8b

Please sign in to comment.