summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-24 03:06:32 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-24 03:06:32 +0200
commit84a5ceeb7db03d75425d72e8a23a0bb0f267bc01 (patch)
tree7a7702429a7cdbc06144b2141eb80ee2aa462d39 /src/Common
parent415cd36477e152c12f91a10ad61bb719373cd9d1 (diff)
downloadmad-84a5ceeb7db03d75425d72e8a23a0bb0f267bc01.tar
mad-84a5ceeb7db03d75425d72e8a23a0bb0f267bc01.zip
Hash-Klasse hinzugefügt
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/AuthBackend.h2
-rw-r--r--src/Common/AuthManager.cpp4
-rw-r--r--src/Common/AuthManager.h4
-rw-r--r--src/Common/CMakeLists.txt3
-rw-r--r--src/Common/Hash.cpp65
-rw-r--r--src/Common/Hash.h91
-rw-r--r--src/Common/UserManager.cpp20
7 files changed, 173 insertions, 16 deletions
diff --git a/src/Common/AuthBackend.h b/src/Common/AuthBackend.h
index e933856..53c7769 100644
--- a/src/Common/AuthBackend.h
+++ b/src/Common/AuthBackend.h
@@ -40,7 +40,7 @@ class AuthBackend {
virtual const std::vector<std::string>& getMethods() const = 0;
virtual boost::shared_ptr<AuthContext> authenticate(const std::string& /*method*/, const std::string& /*user*/,
- const std::vector<boost::uint8_t>& /*challenge*/, std::vector<boost::uint8_t>& /*response*/,
+ const std::vector<boost::uint8_t>& /*data*/, std::vector<boost::uint8_t>& /*response*/,
boost::shared_ptr<AuthContext> /*context*/) throw(Core::Exception) = 0;
public:
diff --git a/src/Common/AuthManager.cpp b/src/Common/AuthManager.cpp
index b27c29f..ffb8453 100644
--- a/src/Common/AuthManager.cpp
+++ b/src/Common/AuthManager.cpp
@@ -45,13 +45,13 @@ std::vector<std::string> AuthManager::getMethods() {
return backend->getMethods();
}
-boost::shared_ptr<AuthContext> AuthManager::authenticate(const std::string &method, const std::string &user, const std::vector<boost::uint8_t> &challenge,
+boost::shared_ptr<AuthContext> AuthManager::authenticate(const std::string &method, const std::string &user, const std::vector<boost::uint8_t> &data,
std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context) throw(Core::Exception) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
response.clear();
- return backend->authenticate(method, user, challenge, response, context);
+ return backend->authenticate(method, user, data, response, context);
}
}
diff --git a/src/Common/AuthManager.h b/src/Common/AuthManager.h
index c773214..1516526 100644
--- a/src/Common/AuthManager.h
+++ b/src/Common/AuthManager.h
@@ -54,7 +54,7 @@ class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable {
}
virtual boost::shared_ptr<AuthContext> authenticate(const std::string& /*method*/, const std::string& /*user*/,
- const std::vector<boost::uint8_t>& /*challenge*/, std::vector<boost::uint8_t>& /*response*/,
+ const std::vector<boost::uint8_t>& /*data*/, std::vector<boost::uint8_t>& /*response*/,
boost::shared_ptr<AuthContext> /*context*/) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
@@ -74,7 +74,7 @@ class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable {
std::vector<std::string> getMethods();
- boost::shared_ptr<AuthContext> authenticate(const std::string &method, const std::string &user, const std::vector<boost::uint8_t> &challenge,
+ boost::shared_ptr<AuthContext> authenticate(const std::string &method, const std::string &user, const std::vector<boost::uint8_t> &data,
std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context = boost::shared_ptr<AuthContext>()) throw(Core::Exception);
};
diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt
index 13e1599..129c7de 100644
--- a/src/Common/CMakeLists.txt
+++ b/src/Common/CMakeLists.txt
@@ -25,6 +25,7 @@ mad_library(Common
ClientConnection.cpp ClientConnection.h
Connection.cpp Connection.h
GroupInfo.h
+ Hash.cpp Hash.h
HostInfo.h
Module.h
ModuleManager.cpp ModuleManager.h
@@ -41,4 +42,4 @@ mad_library(Common
UserManager.cpp UserManager.h
XmlPacket.cpp XmlPacket.h
)
-target_link_libraries(Common Net Core modules ${LIBXML2_LIBRARIES} ${DL_LIBRARY})
+target_link_libraries(Common Net Core modules ${LIBXML2_LIBRARIES} ${MHASH_LIBRARY} ${DL_LIBRARY})
diff --git a/src/Common/Hash.cpp b/src/Common/Hash.cpp
new file mode 100644
index 0000000..8194ffb
--- /dev/null
+++ b/src/Common/Hash.cpp
@@ -0,0 +1,65 @@
+/*
+ * Hash.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Hash.h"
+
+#include <boost/scoped_array.hpp>
+
+#include <mhash.h>
+
+namespace Mad {
+namespace Common {
+
+const Hash::Hashes Hash::hashes;
+
+Hash::Hashes::Hashes() {
+ addHash("SHA256", MHASH_SHA256);
+ addHash("Tiger192", MHASH_TIGER192);
+ addHash("HAVAL192", MHASH_HAVAL192);
+ addHash("SHA1", MHASH_SHA1);
+ addHash("Tiger160", MHASH_TIGER160);
+ addHash("HAVAL160", MHASH_HAVAL160);
+ addHash("RIPEMD-160", MHASH_RIPEMD160);
+ addHash("MD5", MHASH_MD5);
+ addHash("Tiger128", MHASH_TIGER128);
+ addHash("HAVAL128", MHASH_HAVAL128);
+}
+
+std::vector<boost::uint8_t> Hash::hash(const std::vector<boost::uint8_t> &in, unsigned int method) throw (Core::Exception) {
+ MHASH mh;
+
+ mh = mhash_init(static_cast<hashid>(method));
+ if(mh == MHASH_FAILED)
+ throw(Core::Exception(Core::Exception::NOT_AVAILABLE));
+
+ boost::scoped_array<boost::uint8_t> inArray(new boost::uint8_t[in.size()]);
+ std::copy(in.begin(), in.end(), inArray.get());
+
+ mhash(mh, inArray.get(), in.size());
+
+ std::size_t hashLength = mhash_get_block_size(static_cast<hashid>(method));
+
+ boost::scoped_array<boost::uint8_t> outArray(new boost::uint8_t[hashLength]);
+ mhash_deinit(mh, outArray.get());
+
+ return std::vector<boost::uint8_t>(outArray.get(), outArray.get()+hashLength);
+}
+
+}
+}
diff --git a/src/Common/Hash.h b/src/Common/Hash.h
new file mode 100644
index 0000000..69b3318
--- /dev/null
+++ b/src/Common/Hash.h
@@ -0,0 +1,91 @@
+/*
+ * Hash.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_HASH_H_
+#define MAD_COMMON_HASH_H_
+
+#include "export.h"
+
+#include <Core/Exception.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <boost/cstdint.hpp>
+
+namespace Mad {
+namespace Common {
+
+class MAD_COMMON_EXPORT Hash {
+ private:
+ Hash();
+
+ class MAD_COMMON_EXPORT Hashes {
+ private:
+ std::map<std::string, unsigned int> map;
+ std::vector<std::string> list;
+
+ void addHash(const std::string &name, unsigned id) {
+ map.insert(std::make_pair(name, id));
+ list.push_back(name);
+ }
+
+ public:
+ const std::vector<std::string>& getList() const {
+ return list;
+ }
+
+ const std::map<std::string, unsigned int>& getMap() const {
+ return map;
+ }
+
+ Hashes();
+ };
+
+ static const Hashes hashes;
+
+ public:
+ static const std::vector<std::string>& getHashList() {
+ return hashes.getList();
+ }
+
+ static std::vector<boost::uint8_t> hash(const std::vector<boost::uint8_t> &in, unsigned int method) throw (Core::Exception);
+
+ static std::vector<boost::uint8_t> hash(const std::vector<boost::uint8_t> &in, const std::string &method) throw (Core::Exception) {
+ std::map<std::string, unsigned int>::const_iterator methodIt = hashes.getMap().find(method);
+ if(methodIt == hashes.getMap().end())
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+
+ return hash(in, methodIt->second);
+ }
+
+ static std::vector<boost::uint8_t> hash(const std::string &in, unsigned int method) throw (Core::Exception) {
+ return hash(std::vector<boost::uint8_t>(in.begin(), in.end()), method);
+ }
+
+ static std::vector<boost::uint8_t> hash(const std::string &in, const std::string &method) throw (Core::Exception) {
+ return hash(std::vector<boost::uint8_t>(in.begin(), in.end()), method);
+ }
+};
+
+}
+}
+
+#endif /* MAD_COMMON_HASH_H_ */
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp
index d4467ee..d184044 100644
--- a/src/Common/UserManager.cpp
+++ b/src/Common/UserManager.cpp
@@ -234,7 +234,7 @@ void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) {
(*configBackend)->addUser(userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -258,7 +258,7 @@ void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw(
(*configBackend)->updateUser(*oldUserInfo, userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -280,7 +280,7 @@ void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) {
(*configBackend)->deleteUser(*userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -317,7 +317,7 @@ void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) {
(*configBackend)->addGroup(groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -341,7 +341,7 @@ void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) thr
(*configBackend)->updateGroup(*oldGroupInfo, groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -363,7 +363,7 @@ void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) {
(*configBackend)->deleteGroup(*groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -388,7 +388,7 @@ void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Cor
(*configBackend)->addUserToGroup(*userInfo, *groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -413,7 +413,7 @@ void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) thro
(*configBackend)->deleteUserFromGroup(*userInfo, *groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}
}
@@ -439,7 +439,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th
exception = e;
if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) {
@@ -449,7 +449,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th
}
catch(Core::Exception e) {
if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what());
}
}