From c964aa2708ed2839ded3c35eed7338f3e81f568f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 24 Aug 2009 04:47:54 +0200 Subject: =?UTF-8?q?Authentifikation:=20=C3=9Cbertrage=20Passw=C3=B6rter=20?= =?UTF-8?q?gehasht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/AuthBackendFile/AuthBackendFile.cpp | 20 ++++++++++++++------ src/modules/AuthBackendFile/AuthBackendFile.h | 20 +++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'src/modules') diff --git a/src/modules/AuthBackendFile/AuthBackendFile.cpp b/src/modules/AuthBackendFile/AuthBackendFile.cpp index ac7a1db..b05b2db 100644 --- a/src/modules/AuthBackendFile/AuthBackendFile.cpp +++ b/src/modules/AuthBackendFile/AuthBackendFile.cpp @@ -74,11 +74,11 @@ bool AuthBackendFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /*h return true; } -boost::shared_ptr AuthBackendFile::authenticate(const std::string &method, const std::string &user, - const std::vector &data, std::vector& /*response*/, +boost::shared_ptr AuthBackendFile::authenticate(const std::string &method, const std::string &subMethod, + const std::string &user, const std::vector &data, std::vector& /*response*/, boost::shared_ptr context) throw(Core::Exception) { if(method != "Password") - throw(Core::Exception(Core::Exception::INVALID_INPUT)); + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); if(context.get() != 0 && dynamic_cast(context.get()) == 0) throw(Core::Exception(Core::Exception::INVALID_INPUT)); @@ -86,12 +86,20 @@ boost::shared_ptr AuthBackendFile::authenticate(const std:: if(context.get() == 0) context.reset(new AuthContextFile); - std::string password(data.begin(), data.end()); - std::map::iterator userIt = userMap.find(user); - if(userIt == userMap.end() || password != userIt->second) + if(userIt == userMap.end()) throw(Core::Exception(Core::Exception::AUTHENTICATION)); + if(subMethod == "Clear") { + if(userIt->second != std::string(data.begin(), data.end())) + throw(Core::Exception(Core::Exception::AUTHENTICATION)); + } + else { + if(!std::equal(data.begin(), data.end(), Common::Hash::hash(userIt->second, subMethod).begin())) + throw(Core::Exception(Core::Exception::AUTHENTICATION)); + } + + return context; } diff --git a/src/modules/AuthBackendFile/AuthBackendFile.h b/src/modules/AuthBackendFile/AuthBackendFile.h index 90f572c..5f13b51 100644 --- a/src/modules/AuthBackendFile/AuthBackendFile.h +++ b/src/modules/AuthBackendFile/AuthBackendFile.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -44,10 +45,11 @@ class MAD_MODULE_EXPORT AuthBackendFile : public Common::AuthBackend, private Co void readFile(const std::string &name); - std::vector methods; - Common::Application *application; + std::vector methods; + std::vector subMethods; + std::map userMap; protected: @@ -57,13 +59,21 @@ class MAD_MODULE_EXPORT AuthBackendFile : public Common::AuthBackend, private Co return methods; } - virtual boost::shared_ptr authenticate(const std::string &method, const std::string &user, - const std::vector &data, std::vector &response, + virtual const std::vector& getSubMethods(const std::string &method) const throw(Core::Exception) { + if(method != "Password") + throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); + + return subMethods; + } + + virtual boost::shared_ptr authenticate(const std::string &method, const std::string &subMethod, + const std::string &user, const std::vector &data, std::vector &response, boost::shared_ptr context) throw(Core::Exception); public: - AuthBackendFile(Common::Application *application0) : application(application0) { + AuthBackendFile(Common::Application *application0) : application(application0), subMethods(Common::Hash::getHashList()) { methods.push_back("Password"); + subMethods.push_back("Clear"); application->getConfigManager()->registerConfigurable(this); } -- cgit v1.2.3