diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
commit | b40ba0cf91603b695f1f2380cbd39966a458f22f (patch) | |
tree | 1fec48ddc59eb1392fac38495b230e4b2cbf7528 /src/Client/Authenticators | |
parent | e1d8490f0654a3da0b900407d80d91d8d0da68c8 (diff) | |
download | mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.tar mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.zip |
Use Unicode-aware String class instead of std::string
Diffstat (limited to 'src/Client/Authenticators')
4 files changed, 36 insertions, 31 deletions
diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp index 4aadb63..7ccaa63 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp @@ -40,7 +40,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::sendRequest() void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket(boost::shared_ptr<const Common::XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } @@ -58,7 +58,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket( ret.set("user", username); - std::vector<boost::uint8_t> hashedPassword = Common::Hash::hash(std::vector<boost::uint8_t>(password.begin(), password.end()), hash); + std::vector<boost::uint8_t> hashedPassword = Common::Hash::hash(password, hash); const std::vector<boost::uint8_t> &challenge = packet->get<const std::vector<boost::uint8_t>&>("data"); hashedPassword.insert(hashedPassword.end(), challenge.begin(), challenge.end()); @@ -79,8 +79,8 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket( } } -void ChallengeResponseAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception) { - std::string hash; +void ChallengeResponseAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception) { + Core::String hash; { boost::shared_ptr<Common::Requests::AuthMethodRequest> request(new Common::Requests::AuthMethodRequest(application)); @@ -96,14 +96,14 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati const Common::XmlData::List *methods = result.first->getList("methods"); for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { - if(method->get<const std::string&>("name") != "Challenge-Response") + if(method->get<const Core::String&>("name") != "Challenge-Response") continue; const Common::XmlData::List *subMethods = method->getList("subMethods"); for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { - if(Common::Hash::isHashSupported(subMethod->get<const std::string&>("name"))) { - hash = subMethod->get<const std::string&>("name"); + if(Common::Hash::isHashSupported(subMethod->get<const Core::String&>("name"))) { + hash = subMethod->get<const Core::String&>("name"); break; } } @@ -111,11 +111,11 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati break; } - if(hash.empty()) + if(hash.isEmpty()) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.extract().c_str()); boost::shared_ptr<ChallengeResponseAuthRequest> request(new ChallengeResponseAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.h b/src/Client/Authenticators/ChallengeResponseAuthenticator.h index 3906ba9..5787b1b 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.h +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.h @@ -32,10 +32,10 @@ class MAD_CLIENT_EXPORT ChallengeResponseAuthenticator { private: class MAD_CLIENT_EXPORT ChallengeResponseAuthRequest : public Common::Request { private: - std::string username; - std::string password; + Core::String username; + Core::String password; - std::string hash; + Core::String hash; bool hasResponded; @@ -44,14 +44,14 @@ class MAD_CLIENT_EXPORT ChallengeResponseAuthenticator { virtual void handlePacket(boost::shared_ptr<const Common::XmlData> packet); public: - ChallengeResponseAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) + ChallengeResponseAuthRequest(Common::Application *application, const Core::String &username0, const Core::String &password0, const Core::String &hash0) : Common::Request(application), username(username0), password(password0), hash(hash0), hasResponded(false) {} }; ChallengeResponseAuthenticator(); public: - static void authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception); + static void authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception); }; } diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index bf2a284..2ac9d68 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -35,17 +35,22 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { packet.set("user", username); - if(hash == "Clear") - packet.set("data", std::vector<boost::uint8_t>(password.begin(), password.end())); - else - packet.set("data", Common::Hash::hash(std::vector<boost::uint8_t>(password.begin(), password.end()), hash)); + + + if(hash == "Clear") { + std::string passwordStr = password.extractUTF8(); + packet.set("data", std::vector<boost::uint8_t>(passwordStr.begin(), passwordStr.end())); + } + else { + packet.set("data", Common::Hash::hash(password, hash)); + } sendPacket(packet); } void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr<const Common::XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } @@ -57,8 +62,8 @@ void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr< signalFinished(packet); } -void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception) { - std::string hash; +void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception) { + Core::String hash; { boost::shared_ptr<Common::Requests::AuthMethodRequest> request(new Common::Requests::AuthMethodRequest(application)); @@ -74,14 +79,14 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo const Common::XmlData::List *methods = result.first->getList("methods"); for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { - if(method->get<const std::string&>("name") != "Password") + if(method->get<const Core::String&>("name") != "Password") continue; const Common::XmlData::List *subMethods = method->getList("subMethods"); for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { - if(Common::Hash::isHashSupported(subMethod->get<const std::string&>("name"))) { - hash = subMethod->get<const std::string&>("name"); + if(Common::Hash::isHashSupported(subMethod->get<const Core::String&>("name"))) { + hash = subMethod->get<const Core::String&>("name"); break; } } @@ -89,11 +94,11 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo break; } - if(hash.empty()) + if(hash.isEmpty()) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.extract().c_str()); boost::shared_ptr<PasswordAuthRequest> request(new PasswordAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/PasswordAuthenticator.h b/src/Client/Authenticators/PasswordAuthenticator.h index 70ab3f2..e0ae8ef 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.h +++ b/src/Client/Authenticators/PasswordAuthenticator.h @@ -32,24 +32,24 @@ class MAD_CLIENT_EXPORT PasswordAuthenticator { private: class MAD_CLIENT_EXPORT PasswordAuthRequest : public Common::Request { private: - std::string username; - std::string password; + Core::String username; + Core::String password; - std::string hash; + Core::String hash; protected: virtual void sendRequest(); virtual void handlePacket(boost::shared_ptr<const Common::XmlData> packet); public: - PasswordAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) + PasswordAuthRequest(Common::Application *application, const Core::String &username0, const Core::String &password0, const Core::String &hash0) : Common::Request(application), username(username0), password(password0), hash(hash0) {} }; PasswordAuthenticator(); public: - static void authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception); + static void authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception); }; } |